use of com.cloud.api.response.PodResponse in project CloudStack-archive by CloudStack-extras.
the class UpdatePodCmd method execute.
@Override
public void execute() {
Pod result = _configService.editPod(this);
if (result != null) {
PodResponse response = _responseGenerator.createPodResponse(result, false);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update pod");
}
}
use of com.cloud.api.response.PodResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createPodResponse.
@Override
public PodResponse createPodResponse(final Pod pod, final Boolean showCapacities) {
String[] ipRange = new String[2];
if (pod.getDescription() != null && pod.getDescription().length() > 0) {
ipRange = pod.getDescription().split("-");
} else {
ipRange[0] = pod.getDescription();
}
final PodResponse podResponse = new PodResponse();
podResponse.setId(pod.getUuid());
podResponse.setName(pod.getName());
final DataCenter zone = ApiDBUtils.findZoneById(pod.getDataCenterId());
if (zone != null) {
podResponse.setZoneId(zone.getUuid());
podResponse.setZoneName(zone.getName());
}
podResponse.setNetmask(NetUtils.getCidrNetmask(pod.getCidrSize()));
podResponse.setStartIp(ipRange[0]);
podResponse.setEndIp(ipRange.length > 1 && ipRange[1] != null ? ipRange[1] : "");
podResponse.setGateway(pod.getGateway());
podResponse.setAllocationState(pod.getAllocationState().toString());
if (showCapacities != null && showCapacities) {
final List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null, pod.getId(), null);
final Set<CapacityResponse> capacityResponses = new HashSet<>();
for (final SummedCapacity capacity : capacities) {
final CapacityResponse capacityResponse = new CapacityResponse();
capacityResponse.setCapacityType(capacity.getCapacityType());
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() + capacity.getReservedCapacity());
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
final List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(null, pod.getId(), null);
capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity());
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity());
} else {
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
}
if (capacityResponse.getCapacityTotal() != 0) {
capacityResponse.setPercentageAllocated(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
} else {
capacityResponse.setPercentageAllocated(s_percentFormat.format(0L));
}
capacityResponses.add(capacityResponse);
}
// Do it for stats as well.
capacityResponses.addAll(getStatsCapacityresponse(null, null, pod.getId(), pod.getDataCenterId()));
podResponse.setCapacitites(new ArrayList<>(capacityResponses));
}
podResponse.setObjectName("pod");
return podResponse;
}
Aggregations