Search in sources :

Example 6 with PodResponse

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");
    }
}
Also used : Pod(com.cloud.dc.Pod) ServerApiException(com.cloud.api.ServerApiException) PodResponse(com.cloud.api.response.PodResponse)

Example 7 with PodResponse

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;
}
Also used : DataCenter(com.cloud.dc.DataCenter) CapacityResponse(com.cloud.api.response.CapacityResponse) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity) PodResponse(com.cloud.api.response.PodResponse) HashSet(java.util.HashSet)

Aggregations

PodResponse (com.cloud.api.response.PodResponse)7 Pod (com.cloud.dc.Pod)6 ServerApiException (com.cloud.api.ServerApiException)4 ListResponse (com.cloud.api.response.ListResponse)2 ArrayList (java.util.ArrayList)2 CapacityResponse (com.cloud.api.response.CapacityResponse)1 SummedCapacity (com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity)1 DataCenter (com.cloud.dc.DataCenter)1 HashSet (java.util.HashSet)1 List (java.util.List)1