Search in sources :

Example 1 with NetworkOfferingResponse

use of org.apache.cloudstack.api.response.NetworkOfferingResponse in project cloudstack by apache.

the class ListNetworkOfferingsCmd method execute.

@Override
public void execute() {
    Pair<List<? extends NetworkOffering>, Integer> offerings = _configService.searchForNetworkOfferings(this);
    ListResponse<NetworkOfferingResponse> response = new ListResponse<NetworkOfferingResponse>();
    List<NetworkOfferingResponse> offeringResponses = new ArrayList<NetworkOfferingResponse>();
    for (NetworkOffering offering : offerings.first()) {
        NetworkOfferingResponse offeringResponse = _responseGenerator.createNetworkOfferingResponse(offering);
        offeringResponses.add(offeringResponse);
    }
    response.setResponses(offeringResponses, offerings.second());
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : NetworkOfferingResponse(org.apache.cloudstack.api.response.NetworkOfferingResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) NetworkOffering(com.cloud.offering.NetworkOffering) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with NetworkOfferingResponse

use of org.apache.cloudstack.api.response.NetworkOfferingResponse in project cloudstack by apache.

the class NetworkOfferingJoinDaoImpl method newNetworkOfferingResponse.

@Override
public NetworkOfferingResponse newNetworkOfferingResponse(NetworkOffering offering) {
    NetworkOfferingResponse networkOfferingResponse = new NetworkOfferingResponse();
    networkOfferingResponse.setId(offering.getUuid());
    networkOfferingResponse.setName(offering.getName());
    networkOfferingResponse.setDisplayText(offering.getDisplayText());
    networkOfferingResponse.setTags(offering.getTags());
    networkOfferingResponse.setTrafficType(offering.getTrafficType().toString());
    networkOfferingResponse.setIsDefault(offering.isDefault());
    networkOfferingResponse.setSpecifyVlan(offering.isSpecifyVlan());
    networkOfferingResponse.setConserveMode(offering.isConserveMode());
    networkOfferingResponse.setSpecifyIpRanges(offering.isSpecifyIpRanges());
    networkOfferingResponse.setAvailability(offering.getAvailability().toString());
    networkOfferingResponse.setIsPersistent(offering.isPersistent());
    networkOfferingResponse.setEgressDefaultPolicy(offering.isEgressDefaultPolicy());
    networkOfferingResponse.setConcurrentConnections(offering.getConcurrentConnections());
    networkOfferingResponse.setSupportsStrechedL2Subnet(offering.isSupportingStrechedL2());
    networkOfferingResponse.setSupportsPublicAccess(offering.isSupportingPublicAccess());
    networkOfferingResponse.setCreated(offering.getCreated());
    if (offering.getGuestType() != null) {
        networkOfferingResponse.setGuestIpType(offering.getGuestType().toString());
    }
    networkOfferingResponse.setState(offering.getState().name());
    if (offering instanceof NetworkOfferingJoinVO) {
        networkOfferingResponse.setDomainId(((NetworkOfferingJoinVO) offering).getDomainUuid());
        networkOfferingResponse.setDomain(((NetworkOfferingJoinVO) offering).getDomainPath());
        networkOfferingResponse.setZoneId(((NetworkOfferingJoinVO) offering).getZoneUuid());
        networkOfferingResponse.setZone(((NetworkOfferingJoinVO) offering).getZoneName());
    }
    networkOfferingResponse.setObjectName("networkoffering");
    return networkOfferingResponse;
}
Also used : NetworkOfferingResponse(org.apache.cloudstack.api.response.NetworkOfferingResponse) NetworkOfferingJoinVO(com.cloud.api.query.vo.NetworkOfferingJoinVO)

Example 3 with NetworkOfferingResponse

use of org.apache.cloudstack.api.response.NetworkOfferingResponse in project cloudstack by apache.

the class UpdateNetworkOfferingCmd method execute.

@Override
public void execute() {
    NetworkOffering result = _configService.updateNetworkOffering(this);
    if (result != null) {
        NetworkOfferingResponse response = _responseGenerator.createNetworkOfferingResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network offering");
    }
}
Also used : NetworkOfferingResponse(org.apache.cloudstack.api.response.NetworkOfferingResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkOffering(com.cloud.offering.NetworkOffering)

Example 4 with NetworkOfferingResponse

use of org.apache.cloudstack.api.response.NetworkOfferingResponse in project cloudstack by apache.

the class ApiResponseHelper method createNetworkOfferingResponse.

@Override
public NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering) {
    if (!(offering instanceof NetworkOfferingJoinVO)) {
        offering = ApiDBUtils.newNetworkOfferingView(offering);
    }
    NetworkOfferingResponse response = ApiDBUtils.newNetworkOfferingResponse(offering);
    response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
    Long so = null;
    if (offering.getServiceOfferingId() != null) {
        so = offering.getServiceOfferingId();
    } else {
        so = ApiDBUtils.findDefaultRouterServiceOffering();
    }
    if (so != null) {
        ServiceOffering soffering = ApiDBUtils.findServiceOfferingById(so);
        if (soffering != null) {
            response.setServiceOfferingId(soffering.getUuid());
        }
    }
    Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId());
    List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
    for (Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
        Service service = entry.getKey();
        Set<Provider> srvc_providers = entry.getValue();
        ServiceResponse svcRsp = new ServiceResponse();
        // skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        svcRsp.setName(service.getName());
        List<ProviderResponse> providers = new ArrayList<ProviderResponse>();
        for (Provider provider : srvc_providers) {
            if (provider != null) {
                ProviderResponse providerRsp = new ProviderResponse();
                providerRsp.setName(provider.getName());
                providers.add(providerRsp);
            }
        }
        svcRsp.setProviders(providers);
        if (Service.Lb == service) {
            List<CapabilityResponse> lbCapResponse = new ArrayList<CapabilityResponse>();
            CapabilityResponse lbIsoaltion = new CapabilityResponse();
            lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
            lbIsoaltion.setValue(offering.isDedicatedLB() ? "dedicated" : "shared");
            lbCapResponse.add(lbIsoaltion);
            CapabilityResponse eLb = new CapabilityResponse();
            eLb.setName(Capability.ElasticLb.getName());
            eLb.setValue(offering.isElasticLb() ? "true" : "false");
            lbCapResponse.add(eLb);
            CapabilityResponse inline = new CapabilityResponse();
            inline.setName(Capability.InlineMode.getName());
            inline.setValue(offering.isInline() ? "true" : "false");
            lbCapResponse.add(inline);
            svcRsp.setCapabilities(lbCapResponse);
        } else if (Service.SourceNat == service) {
            List<CapabilityResponse> capabilities = new ArrayList<CapabilityResponse>();
            CapabilityResponse sharedSourceNat = new CapabilityResponse();
            sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
            sharedSourceNat.setValue(offering.isSharedSourceNat() ? "perzone" : "peraccount");
            capabilities.add(sharedSourceNat);
            CapabilityResponse redundantRouter = new CapabilityResponse();
            redundantRouter.setName(Capability.RedundantRouter.getName());
            redundantRouter.setValue(offering.isRedundantRouter() ? "true" : "false");
            capabilities.add(redundantRouter);
            svcRsp.setCapabilities(capabilities);
        } else if (service == Service.StaticNat) {
            List<CapabilityResponse> staticNatCapResponse = new ArrayList<CapabilityResponse>();
            CapabilityResponse eIp = new CapabilityResponse();
            eIp.setName(Capability.ElasticIp.getName());
            eIp.setValue(offering.isElasticIp() ? "true" : "false");
            staticNatCapResponse.add(eIp);
            CapabilityResponse associatePublicIp = new CapabilityResponse();
            associatePublicIp.setName(Capability.AssociatePublicIP.getName());
            associatePublicIp.setValue(offering.isAssociatePublicIP() ? "true" : "false");
            staticNatCapResponse.add(associatePublicIp);
            svcRsp.setCapabilities(staticNatCapResponse);
        }
        serviceResponses.add(svcRsp);
    }
    response.setForVpc(_configMgr.isOfferingForVpc(offering));
    response.setServices(serviceResponses);
    // set network offering details
    Map<Detail, String> details = _ntwkModel.getNtwkOffDetails(offering.getId());
    if (details != null && !details.isEmpty()) {
        response.setDetails(details);
    }
    response.setHasAnnotation(annotationDao.hasAnnotations(offering.getUuid(), AnnotationService.EntityType.NETWORK_OFFERING.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    return response;
}
Also used : EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) ProviderResponse(org.apache.cloudstack.api.response.ProviderResponse) VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse) NetworkOfferingResponse(org.apache.cloudstack.api.response.NetworkOfferingResponse) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UsageService(org.apache.cloudstack.usage.UsageService) AnnotationService(org.apache.cloudstack.annotation.AnnotationService) CapabilityResponse(org.apache.cloudstack.api.response.CapabilityResponse) OvsProvider(com.cloud.network.OvsProvider) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider) ServiceResponse(org.apache.cloudstack.api.response.ServiceResponse) NetworkOfferingJoinVO(com.cloud.api.query.vo.NetworkOfferingJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) Detail(com.cloud.offering.NetworkOffering.Detail)

Example 5 with NetworkOfferingResponse

use of org.apache.cloudstack.api.response.NetworkOfferingResponse in project cloudstack by apache.

the class CreateNetworkOfferingCmd method execute.

@Override
public void execute() {
    NetworkOffering result = _configService.createNetworkOffering(this);
    if (result != null) {
        NetworkOfferingResponse response = _responseGenerator.createNetworkOfferingResponse(result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network offering");
    }
}
Also used : NetworkOfferingResponse(org.apache.cloudstack.api.response.NetworkOfferingResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkOffering(com.cloud.offering.NetworkOffering)

Aggregations

NetworkOfferingResponse (org.apache.cloudstack.api.response.NetworkOfferingResponse)5 NetworkOffering (com.cloud.offering.NetworkOffering)3 NetworkOfferingJoinVO (com.cloud.api.query.vo.NetworkOfferingJoinVO)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 Provider (com.cloud.network.Network.Provider)1 Service (com.cloud.network.Network.Service)1 OvsProvider (com.cloud.network.OvsProvider)1 PhysicalNetworkServiceProvider (com.cloud.network.PhysicalNetworkServiceProvider)1 VirtualRouterProvider (com.cloud.network.VirtualRouterProvider)1 Detail (com.cloud.offering.NetworkOffering.Detail)1 ServiceOffering (com.cloud.offering.ServiceOffering)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 AnnotationService (org.apache.cloudstack.annotation.AnnotationService)1 CapabilityResponse (org.apache.cloudstack.api.response.CapabilityResponse)1