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");
}
}
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");
}
}
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);
}
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");
}
}
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;
}
Aggregations