Search in sources :

Example 1 with VpcOffering

use of com.cloud.network.vpc.VpcOffering in project cloudstack by apache.

the class ContrailManagerImpl method locateVpcOffering.

private VpcOffering locateVpcOffering() {
    VpcOffering vpcOffer = _vpcOffDao.findByUniqueName(juniperVPCOfferingName);
    if (vpcOffer != null) {
        if (((VpcOfferingVO) vpcOffer).getState() == VpcOffering.State.Enabled) {
            return vpcOffer;
        }
        ((VpcOfferingVO) vpcOffer).setState(VpcOffering.State.Enabled);
        long id = vpcOffer.getId();
        _vpcOffDao.update(id, (VpcOfferingVO) vpcOffer);
        return vpcOffer;
    }
    Map<String, List<String>> serviceProviderMap = new HashMap<String, List<String>>();
    List<String> providerSet = new ArrayList<String>();
    providerSet.add(Provider.JuniperContrailVpcRouter.getName());
    final List<String> services = new ArrayList<String>();
    services.add(Service.Connectivity.getName());
    services.add(Service.Dhcp.getName());
    services.add(Service.NetworkACL.getName());
    services.add(Service.StaticNat.getName());
    services.add(Service.SourceNat.getName());
    services.add(Service.Gateway.getName());
    services.add(Service.Lb.getName());
    for (String svc : services) {
        if (svc.equals(Service.Lb.getName())) {
            List<String> lbProviderSet = new ArrayList<String>();
            lbProviderSet.add(Provider.InternalLbVm.getName());
            serviceProviderMap.put(svc, lbProviderSet);
            continue;
        }
        serviceProviderMap.put(svc, providerSet);
    }
    vpcOffer = _vpcProvSvc.createVpcOffering(juniperVPCOfferingName, juniperVPCOfferingDisplayText, services, serviceProviderMap, null, null, null, null, VpcOffering.State.Enabled);
    long id = vpcOffer.getId();
    _vpcOffDao.update(id, (VpcOfferingVO) vpcOffer);
    return _vpcOffDao.findById(id);
}
Also used : VpcOfferingVO(com.cloud.network.vpc.VpcOfferingVO) HashMap(java.util.HashMap) VpcOffering(com.cloud.network.vpc.VpcOffering) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Example 2 with VpcOffering

use of com.cloud.network.vpc.VpcOffering in project cloudstack by apache.

the class ApiResponseHelper method createVpcResponse.

@Override
public VpcResponse createVpcResponse(ResponseView view, Vpc vpc) {
    VpcResponse response = new VpcResponse();
    response.setId(vpc.getUuid());
    response.setName(vpc.getName());
    response.setDisplayText(vpc.getDisplayText());
    response.setCreated(vpc.getCreated());
    response.setState(vpc.getState().name());
    VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
    if (voff != null) {
        response.setVpcOfferingId(voff.getUuid());
        response.setVpcOfferingName(voff.getName());
    }
    response.setCidr(vpc.getCidr());
    response.setRestartRequired(vpc.isRestartRequired());
    response.setNetworkDomain(vpc.getNetworkDomain());
    response.setForDisplay(vpc.isDisplay());
    response.setUsesDistributedRouter(vpc.usesDistributedRouter());
    response.setRedundantRouter(vpc.isRedundant());
    response.setRegionLevelVpc(vpc.isRegionLevelVpc());
    Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId());
    List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
    for (Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
        Service service = entry.getKey();
        Set<Provider> serviceProviders = 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 : serviceProviders) {
            if (provider != null) {
                ProviderResponse providerRsp = new ProviderResponse();
                providerRsp.setName(provider.getName());
                providers.add(providerRsp);
            }
        }
        svcRsp.setProviders(providers);
        serviceResponses.add(svcRsp);
    }
    List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
    List<? extends Network> networks = ApiDBUtils.listVpcNetworks(vpc.getId());
    for (Network network : networks) {
        NetworkResponse ntwkRsp = createNetworkResponse(view, network);
        networkResponses.add(ntwkRsp);
    }
    DataCenter zone = ApiDBUtils.findZoneById(vpc.getZoneId());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setNetworks(networkResponses);
    response.setServices(serviceResponses);
    populateOwner(response, vpc);
    // set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Vpc, vpc.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    response.setHasAnnotation(annotationDao.hasAnnotations(vpc.getUuid(), AnnotationService.EntityType.VPC.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    response.setObjectName("vpc");
    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) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UsageService(org.apache.cloudstack.usage.UsageService) AnnotationService(org.apache.cloudstack.annotation.AnnotationService) 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) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) VpcResponse(org.apache.cloudstack.api.response.VpcResponse) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VpcOffering(com.cloud.network.vpc.VpcOffering) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse) PhysicalNetworkResponse(org.apache.cloudstack.api.response.PhysicalNetworkResponse) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with VpcOffering

use of com.cloud.network.vpc.VpcOffering in project cosmic by MissionCriticalCloud.

the class CreateVPCOfferingCmd method execute.

@Override
public void execute() {
    final VpcOffering vpc = _vpcProvSvc.getVpcOffering(getEntityId());
    if (vpc != null) {
        final VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(vpc);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPC offering");
    }
}
Also used : VpcOfferingResponse(com.cloud.api.response.VpcOfferingResponse) ServerApiException(com.cloud.api.ServerApiException) VpcOffering(com.cloud.network.vpc.VpcOffering)

Example 4 with VpcOffering

use of com.cloud.network.vpc.VpcOffering in project cosmic by MissionCriticalCloud.

the class UpdateVPCOfferingCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final VpcOffering result = _vpcProvSvc.updateVpcOffering(getId(), getVpcOfferingName(), getDisplayText(), getState());
    if (result != null) {
        final VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC offering");
    }
}
Also used : VpcOfferingResponse(com.cloud.api.response.VpcOfferingResponse) ServerApiException(com.cloud.api.ServerApiException) VpcOffering(com.cloud.network.vpc.VpcOffering)

Example 5 with VpcOffering

use of com.cloud.network.vpc.VpcOffering in project cosmic by MissionCriticalCloud.

the class ListVPCOfferingsCmd method execute.

@Override
public void execute() {
    final Pair<List<? extends VpcOffering>, Integer> offerings = _vpcProvSvc.listVpcOfferings(getId(), getVpcOffName(), getDisplayText(), getSupportedServices(), isDefault, this.getKeyword(), getState(), this.getStartIndex(), this.getPageSizeVal());
    final ListResponse<VpcOfferingResponse> response = new ListResponse<>();
    final List<VpcOfferingResponse> offeringResponses = new ArrayList<>();
    for (final VpcOffering offering : offerings.first()) {
        final VpcOfferingResponse offeringResponse = _responseGenerator.createVpcOfferingResponse(offering);
        offeringResponses.add(offeringResponse);
    }
    response.setResponses(offeringResponses, offerings.second());
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : VpcOfferingResponse(com.cloud.api.response.VpcOfferingResponse) ListResponse(com.cloud.api.response.ListResponse) VpcOffering(com.cloud.network.vpc.VpcOffering) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

VpcOffering (com.cloud.network.vpc.VpcOffering)11 ArrayList (java.util.ArrayList)5 ServerApiException (com.cloud.api.ServerApiException)3 VpcOfferingResponse (com.cloud.api.response.VpcOfferingResponse)3 List (java.util.List)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 VpcOfferingResponse (org.apache.cloudstack.api.response.VpcOfferingResponse)3 DataCenter (com.cloud.dc.DataCenter)2 Network (com.cloud.network.Network)2 Service (com.cloud.network.Network.Service)2 PhysicalNetwork (com.cloud.network.PhysicalNetwork)2 ResourceTag (com.cloud.server.ResourceTag)2 EnumSet (java.util.EnumSet)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 ListResponse (com.cloud.api.response.ListResponse)1 NetworkResponse (com.cloud.api.response.NetworkResponse)1 PhysicalNetworkResponse (com.cloud.api.response.PhysicalNetworkResponse)1 ResourceTagResponse (com.cloud.api.response.ResourceTagResponse)1