use of com.cloud.api.response.NetworkResponse in project CloudStack-archive by CloudStack-extras.
the class CreateNetworkCmd method execute.
@Override
public // an exception thrown by createNetwork() will be caught by the dispatcher.
void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
Network result = _networkService.createNetwork(this);
if (result != null) {
NetworkResponse response = _responseGenerator.createNetworkResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network");
}
}
use of com.cloud.api.response.NetworkResponse 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;
}
use of com.cloud.api.response.NetworkResponse in project cosmic by MissionCriticalCloud.
the class ListNetworksCmd method execute.
@Override
public void execute() {
final Pair<List<? extends Network>, Integer> networks = _networkService.searchForNetworks(this);
final ListResponse<NetworkResponse> response = new ListResponse<>();
final List<NetworkResponse> networkResponses = new ArrayList<>();
for (final Network network : networks.first()) {
final NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(ResponseView.Restricted, network);
networkResponses.add(networkResponse);
}
response.setResponses(networkResponses, networks.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of com.cloud.api.response.NetworkResponse in project cosmic by MissionCriticalCloud.
the class UpdateNetworkCmd method execute.
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException {
final User callerUser = _accountService.getActiveUser(CallContext.current().getCallingUserId());
final Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId());
final Network network = _networkService.getNetwork(id);
if (network == null) {
throw new InvalidParameterValueException("Couldn't find network by ID");
}
final Network result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount, callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr(), getGuestVmCidr(), getDisplayNetwork(), getCustomId(), getDns1(), getDns2(), getIpExclusionList());
if (result != null) {
final NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Restricted, result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network");
}
}
use of com.cloud.api.response.NetworkResponse in project cosmic by MissionCriticalCloud.
the class ListNiciraNvpDeviceNetworksCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
final List<? extends Network> networks = niciraNvpElementService.listNiciraNvpDeviceNetworks(this);
final ListResponse<NetworkResponse> response = new ListResponse<>();
final List<NetworkResponse> networkResponses = new ArrayList<>();
if (networks != null && !networks.isEmpty()) {
for (final Network network : networks) {
final NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(ResponseView.Full, network);
networkResponses.add(networkResponse);
}
}
response.setResponses(networkResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (final InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (final CloudRuntimeException runtimeExcp) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
Aggregations