Search in sources :

Example 1 with VpcResponse

use of com.cloud.api.response.VpcResponse in project cosmic by MissionCriticalCloud.

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 (final ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (final ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (final InsufficientCapacityException ex) {
        s_logger.info(ex.toString());
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    }
    if (vpc != null) {
        final 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(com.cloud.api.ServerApiException) VpcResponse(com.cloud.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 2 with VpcResponse

use of com.cloud.api.response.VpcResponse in project cosmic by MissionCriticalCloud.

the class UpdateVPCCmdByAdmin method execute.

@Override
public void execute() {
    final Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), getCustomId(), getDisplayVpc(), getVpcOfferingId(), getSourceNatList(), getSyslogServerList());
    if (result != null) {
        final 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(com.cloud.api.ServerApiException) VpcResponse(com.cloud.api.response.VpcResponse) Vpc(com.cloud.network.vpc.Vpc)

Example 3 with VpcResponse

use of com.cloud.api.response.VpcResponse in project cosmic by MissionCriticalCloud.

the class ListVPCsCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final 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());
    final ListResponse<VpcResponse> response = new ListResponse<>();
    final List<VpcResponse> vpcResponses = new ArrayList<>();
    for (final Vpc vpc : vpcs.first()) {
        final VpcResponse offeringResponse = _responseGenerator.createVpcResponse(ResponseView.Restricted, vpc);
        vpcResponses.add(offeringResponse);
    }
    response.setResponses(vpcResponses, vpcs.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) VpcResponse(com.cloud.api.response.VpcResponse) Vpc(com.cloud.network.vpc.Vpc) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with VpcResponse

use of com.cloud.api.response.VpcResponse in project cosmic by MissionCriticalCloud.

the class UpdateVPCCmd method execute.

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

Example 5 with VpcResponse

use of com.cloud.api.response.VpcResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createVpcResponse.

@Override
public VpcResponse createVpcResponse(final ResponseView view, final Vpc vpc) {
    final VpcResponse response = new VpcResponse();
    response.setId(vpc.getUuid());
    response.setName(vpc.getName());
    response.setDisplayText(vpc.getDisplayText());
    response.setState(vpc.getState().name());
    final VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
    if (voff != null) {
        response.setVpcOfferingId(voff.getUuid());
        response.setVpcOfferingName(voff.getName());
        response.setVpcOfferingDisplayText(voff.getDisplayText());
    }
    response.setCidr(vpc.getCidr());
    response.setRestartRequired(vpc.isRestartRequired());
    response.setNetworkDomain(vpc.getNetworkDomain());
    response.setForDisplay(vpc.isDisplay());
    response.setRedundantRouter(vpc.isRedundant());
    response.setSourceNatList(vpc.getSourceNatList());
    response.setSyslogServerList(vpc.getSyslogServerList());
    final Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId());
    final List<ServiceResponse> serviceResponses = getServiceResponses(serviceProviderMap);
    final List<NetworkResponse> networkResponses = new ArrayList<>();
    final List<? extends Network> networks = ApiDBUtils.listVpcNetworks(vpc.getId());
    for (final Network network : networks) {
        final NetworkResponse ntwkRsp = createNetworkResponse(view, network);
        networkResponses.add(ntwkRsp);
    }
    final 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
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Vpc, vpc.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final 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) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) ServiceResponse(com.cloud.api.response.ServiceResponse) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) VpcResponse(com.cloud.api.response.VpcResponse) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VpcOffering(com.cloud.network.vpc.VpcOffering) NetworkResponse(com.cloud.api.response.NetworkResponse) PhysicalNetworkResponse(com.cloud.api.response.PhysicalNetworkResponse) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse)

Aggregations

VpcResponse (com.cloud.api.response.VpcResponse)7 Vpc (com.cloud.network.vpc.Vpc)6 ServerApiException (com.cloud.api.ServerApiException)4 ArrayList (java.util.ArrayList)3 ListResponse (com.cloud.api.response.ListResponse)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 List (java.util.List)2 NetworkResponse (com.cloud.api.response.NetworkResponse)1 PhysicalNetworkResponse (com.cloud.api.response.PhysicalNetworkResponse)1 ResourceTagResponse (com.cloud.api.response.ResourceTagResponse)1 ServiceResponse (com.cloud.api.response.ServiceResponse)1 DataCenter (com.cloud.dc.DataCenter)1 Network (com.cloud.network.Network)1 Service (com.cloud.network.Network.Service)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 VpcOffering (com.cloud.network.vpc.VpcOffering)1 ResourceTag (com.cloud.server.ResourceTag)1 EnumSet (java.util.EnumSet)1