Search in sources :

Example 1 with VpcResponse

use of org.apache.cloudstack.api.response.VpcResponse 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.setState(vpc.getState().name());
    VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
    if (voff != null) {
        response.setVpcOfferingId(voff.getUuid());
    }
    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.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) 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 2 with VpcResponse

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

the class UpdateVPCCmdByAdmin method execute.

@Override
public void execute() {
    Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), getCustomId(), getDisplayVpc());
    if (result != null) {
        VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) VpcResponse(org.apache.cloudstack.api.response.VpcResponse) Vpc(com.cloud.network.vpc.Vpc)

Example 3 with VpcResponse

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

the class CreateVPCCmd method execute.

@Override
public void execute() {
    Vpc vpc = null;
    try {
        if (isStart()) {
            _vpcService.startVpc(getEntityId(), true);
        } else {
            s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
        }
        vpc = _entityMgr.findById(Vpc.class, getEntityId());
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    }
    if (vpc != null) {
        VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Restricted, vpc);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPC");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) VpcResponse(org.apache.cloudstack.api.response.VpcResponse) Vpc(com.cloud.network.vpc.Vpc) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 4 with VpcResponse

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

the class CreateVPCCmdByAdmin method execute.

@Override
public void execute() {
    Vpc vpc = null;
    try {
        if (isStart()) {
            _vpcService.startVpc(getEntityId(), true);
        } else {
            s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
        }
        vpc = _entityMgr.findById(Vpc.class, getEntityId());
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    }
    if (vpc != null) {
        VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Full, vpc);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPC");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) VpcResponse(org.apache.cloudstack.api.response.VpcResponse) Vpc(com.cloud.network.vpc.Vpc) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 5 with VpcResponse

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

the class ListVPCsCmdByAdmin method execute.

@Override
public void execute() {
    Pair<List<? extends Vpc>, Integer> vpcs = _vpcService.listVpcs(getId(), getVpcName(), getDisplayText(), getSupportedServices(), getCidr(), getVpcOffId(), getState(), getAccountName(), getDomainId(), getKeyword(), getStartIndex(), getPageSizeVal(), getZoneId(), isRecursive(), listAll(), getRestartRequired(), getTags(), getProjectId(), getDisplay());
    ListResponse<VpcResponse> response = new ListResponse<VpcResponse>();
    List<VpcResponse> vpcResponses = new ArrayList<VpcResponse>();
    for (Vpc vpc : vpcs.first()) {
        VpcResponse offeringResponse = _responseGenerator.createVpcResponse(ResponseView.Full, vpc);
        vpcResponses.add(offeringResponse);
    }
    response.setResponses(vpcResponses, vpcs.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) VpcResponse(org.apache.cloudstack.api.response.VpcResponse) Vpc(com.cloud.network.vpc.Vpc) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

VpcResponse (org.apache.cloudstack.api.response.VpcResponse)7 Vpc (com.cloud.network.vpc.Vpc)6 ServerApiException (org.apache.cloudstack.api.ServerApiException)4 ArrayList (java.util.ArrayList)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 List (java.util.List)2 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 DataCenter (com.cloud.dc.DataCenter)1 Network (com.cloud.network.Network)1 Provider (com.cloud.network.Network.Provider)1 Service (com.cloud.network.Network.Service)1 OvsProvider (com.cloud.network.OvsProvider)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 PhysicalNetworkServiceProvider (com.cloud.network.PhysicalNetworkServiceProvider)1 VirtualRouterProvider (com.cloud.network.VirtualRouterProvider)1 VpcOffering (com.cloud.network.vpc.VpcOffering)1 ResourceTag (com.cloud.server.ResourceTag)1 EnumSet (java.util.EnumSet)1