Search in sources :

Example 1 with PodResponse

use of org.apache.cloudstack.api.response.PodResponse in project cloudstack by apache.

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(ApiErrorCode.INTERNAL_ERROR, "Failed to update pod");
    }
}
Also used : Pod(com.cloud.dc.Pod) ServerApiException(org.apache.cloudstack.api.ServerApiException) PodResponse(org.apache.cloudstack.api.response.PodResponse)

Example 2 with PodResponse

use of org.apache.cloudstack.api.response.PodResponse in project cloudstack by apache.

the class CreateManagementNetworkIpRangeCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    Pod result = _configService.createPodIpRange(this);
    if (result != null) {
        PodResponse response = _responseGenerator.createPodResponse(result, false);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Pod IP Range.");
    }
}
Also used : Pod(com.cloud.dc.Pod) ServerApiException(org.apache.cloudstack.api.ServerApiException) PodResponse(org.apache.cloudstack.api.response.PodResponse)

Example 3 with PodResponse

use of org.apache.cloudstack.api.response.PodResponse in project cloudstack by apache.

the class CreatePodCmd method execute.

@Override
public void execute() {
    Pod result = _configService.createPod(getZoneId(), getPodName(), getStartIp(), getEndIp(), getGateway(), getNetmask(), getAllocationState());
    if (result != null) {
        PodResponse response = _responseGenerator.createPodResponse(result, false);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create pod");
    }
}
Also used : Pod(com.cloud.dc.Pod) ServerApiException(org.apache.cloudstack.api.ServerApiException) PodResponse(org.apache.cloudstack.api.response.PodResponse)

Example 4 with PodResponse

use of org.apache.cloudstack.api.response.PodResponse in project cloudstack by apache.

the class ListPodsByCmd method execute.

@Override
public void execute() {
    Pair<List<? extends Pod>, Integer> result = _mgr.searchForPods(this);
    ListResponse<PodResponse> response = new ListResponse<PodResponse>();
    List<PodResponse> podResponses = new ArrayList<PodResponse>();
    for (Pod pod : result.first()) {
        PodResponse podResponse = _responseGenerator.createPodResponse(pod, showCapacities);
        podResponse.setObjectName("pod");
        podResponses.add(podResponse);
    }
    response.setResponses(podResponses, result.second());
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : Pod(com.cloud.dc.Pod) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PodResponse(org.apache.cloudstack.api.response.PodResponse)

Example 5 with PodResponse

use of org.apache.cloudstack.api.response.PodResponse in project cloudstack by apache.

the class ApiResponseHelper method createPodResponse.

@Override
public PodResponse createPodResponse(Pod pod, Boolean showCapacities) {
    String[] ipRange = new String[2];
    List<String> startIps = new ArrayList<String>();
    List<String> endIps = new ArrayList<String>();
    List<String> forSystemVms = new ArrayList<String>();
    List<String> vlanIds = new ArrayList<String>();
    List<IpRangeResponse> ipRanges = new ArrayList<>();
    if (pod.getDescription() != null && pod.getDescription().length() > 0) {
        final String[] existingPodIpRanges = pod.getDescription().split(",");
        for (String podIpRange : existingPodIpRanges) {
            IpRangeResponse ipRangeResponse = new IpRangeResponse();
            final String[] existingPodIpRange = podIpRange.split("-");
            String startIp = ((existingPodIpRange.length > 0) && (existingPodIpRange[0] != null)) ? existingPodIpRange[0] : "";
            ipRangeResponse.setStartIp(startIp);
            startIps.add(startIp);
            String endIp = ((existingPodIpRange.length > 1) && (existingPodIpRange[1] != null)) ? existingPodIpRange[1] : "";
            ipRangeResponse.setEndIp(endIp);
            endIps.add(endIp);
            String forSystemVm = (existingPodIpRange.length > 2) && (existingPodIpRange[2] != null) ? existingPodIpRange[2] : "0";
            ipRangeResponse.setForSystemVms(forSystemVm);
            forSystemVms.add(forSystemVm);
            String vlanId = (existingPodIpRange.length > 3) && (existingPodIpRange[3] != null && !existingPodIpRange[3].equals("untagged")) ? BroadcastDomainType.Vlan.toUri(existingPodIpRange[3]).toString() : BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED).toString();
            ipRangeResponse.setVlanId(vlanId);
            vlanIds.add(vlanId);
            ipRanges.add(ipRangeResponse);
        }
    }
    PodResponse podResponse = new PodResponse();
    podResponse.setId(pod.getUuid());
    podResponse.setName(pod.getName());
    DataCenter zone = ApiDBUtils.findZoneById(pod.getDataCenterId());
    if (zone != null) {
        podResponse.setZoneId(zone.getUuid());
        podResponse.setZoneName(zone.getName());
    }
    podResponse.setNetmask(NetUtils.getCidrNetmask(pod.getCidrSize()));
    podResponse.setIpRanges(ipRanges);
    podResponse.setStartIp(startIps);
    podResponse.setEndIp(endIps);
    podResponse.setForSystemVms(forSystemVms);
    podResponse.setVlanId(vlanIds);
    podResponse.setGateway(pod.getGateway());
    podResponse.setAllocationState(pod.getAllocationState().toString());
    if (showCapacities != null && showCapacities) {
        List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null, pod.getId(), null);
        Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
        for (SummedCapacity capacity : capacities) {
            CapacityResponse capacityResponse = new CapacityResponse();
            capacityResponse.setCapacityType(capacity.getCapacityType());
            capacityResponse.setCapacityName(CapacityVO.getCapacityName(capacity.getCapacityType()));
            capacityResponse.setCapacityUsed(capacity.getUsedCapacity() + capacity.getReservedCapacity());
            if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
                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.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
            } else {
                capacityResponse.setPercentUsed(s_percentFormat.format(0L));
            }
            capacityResponses.add(capacityResponse);
        }
        // Do it for stats as well.
        capacityResponses.addAll(getStatsCapacityresponse(null, null, pod.getId(), pod.getDataCenterId()));
        podResponse.setCapacities(new ArrayList<CapacityResponse>(capacityResponses));
    }
    podResponse.setHasAnnotation(annotationDao.hasAnnotations(pod.getUuid(), AnnotationService.EntityType.POD.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    podResponse.setObjectName("pod");
    return podResponse;
}
Also used : ArrayList(java.util.ArrayList) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity) DataCenter(com.cloud.dc.DataCenter) StorageNetworkIpRangeResponse(org.apache.cloudstack.api.response.StorageNetworkIpRangeResponse) IpRangeResponse(org.apache.cloudstack.api.response.IpRangeResponse) PortableIpRangeResponse(org.apache.cloudstack.api.response.PortableIpRangeResponse) VlanIpRangeResponse(org.apache.cloudstack.api.response.VlanIpRangeResponse) CapacityResponse(org.apache.cloudstack.api.response.CapacityResponse) PodResponse(org.apache.cloudstack.api.response.PodResponse) HashSet(java.util.HashSet)

Aggregations

PodResponse (org.apache.cloudstack.api.response.PodResponse)5 Pod (com.cloud.dc.Pod)4 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 ArrayList (java.util.ArrayList)2 SummedCapacity (com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity)1 DataCenter (com.cloud.dc.DataCenter)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CapacityResponse (org.apache.cloudstack.api.response.CapacityResponse)1 IpRangeResponse (org.apache.cloudstack.api.response.IpRangeResponse)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 PortableIpRangeResponse (org.apache.cloudstack.api.response.PortableIpRangeResponse)1 StorageNetworkIpRangeResponse (org.apache.cloudstack.api.response.StorageNetworkIpRangeResponse)1 VlanIpRangeResponse (org.apache.cloudstack.api.response.VlanIpRangeResponse)1