Search in sources :

Example 51 with ListResponse

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

the class ListStorageNetworkIpRangeCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<StorageNetworkIpRange> results = _storageNetworkService.listIpRange(this);
        ListResponse<StorageNetworkIpRangeResponse> response = new ListResponse<StorageNetworkIpRangeResponse>();
        List<StorageNetworkIpRangeResponse> resList = new ArrayList<StorageNetworkIpRangeResponse>(results.size());
        for (StorageNetworkIpRange r : results) {
            StorageNetworkIpRangeResponse resp = _responseGenerator.createStorageNetworkIpRangeResponse(r);
            resList.add(resp);
        }
        response.setResponses(resList);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (Exception e) {
        s_logger.warn("Failed to list storage network ip range for rangeId=" + getRangeId() + " podId=" + getPodId() + " zoneId=" + getZoneId());
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) StorageNetworkIpRange(com.cloud.dc.StorageNetworkIpRange) StorageNetworkIpRangeResponse(org.apache.cloudstack.api.response.StorageNetworkIpRangeResponse) ArrayList(java.util.ArrayList) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 52 with ListResponse

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

the class ListOvsElementsCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    List<? extends OvsProvider> providers = _service.get(0).searchForOvsElement(this);
    ListResponse<OvsProviderResponse> response = new ListResponse<OvsProviderResponse>();
    List<OvsProviderResponse> providerResponses = new ArrayList<OvsProviderResponse>();
    for (OvsProvider provider : providers) {
        OvsProviderResponse providerResponse = _responseGenerator.createOvsProviderResponse(provider);
        providerResponses.add(providerResponse);
    }
    response.setResponses(providerResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) OvsProvider(com.cloud.network.OvsProvider) ArrayList(java.util.ArrayList) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse)

Example 53 with ListResponse

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

the class ListNicsCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
    try {
        if (this.getKeyword() != null && !this.getKeyword().isEmpty() && this.getNicId() != null) {
            List<? extends NicSecondaryIp> results = _networkService.listVmNicSecondaryIps(this);
            ListResponse<NicSecondaryIpResponse> response = new ListResponse<NicSecondaryIpResponse>();
            List<NicSecondaryIpResponse> resList = new ArrayList<NicSecondaryIpResponse>();
            NicSecondaryIpResponse res = new NicSecondaryIpResponse();
            List<NicSecondaryIpResponse> res_List = new ArrayList<NicSecondaryIpResponse>();
            if (results != null) {
                for (NicSecondaryIp r : results) {
                    NicSecondaryIpResponse ipRes = _responseGenerator.createSecondaryIPToNicResponse(r);
                    resList.add(ipRes);
                    res.setSecondaryIpsList(resList);
                    res.setObjectName("nic");
                }
                res_List.add(res);
                response.setResponses(res_List);
            }
            response.setResponses(res_List);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            List<? extends Nic> results = _networkService.listNics(this);
            ListResponse<NicResponse> response = new ListResponse<NicResponse>();
            List<NicResponse> resList = null;
            if (results != null) {
                resList = new ArrayList<NicResponse>(results.size());
                for (Nic r : results) {
                    NicResponse resp = _responseGenerator.createNicResponse(r);
                    resp.setObjectName("nic");
                    resList.add(resp);
                }
                response.setResponses(resList);
            }
            response.setResponses(resList);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        }
    } catch (Exception e) {
        s_logger.warn("Failed to list secondary ip address per nic ");
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) NicSecondaryIp(com.cloud.vm.NicSecondaryIp) Nic(com.cloud.vm.Nic) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NicSecondaryIpResponse(org.apache.cloudstack.api.response.NicSecondaryIpResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) NicResponse(org.apache.cloudstack.api.response.NicResponse)

Example 54 with ListResponse

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

the class ListSSHKeyPairsCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    Pair<List<? extends SSHKeyPair>, Integer> resultList = _mgr.listSSHKeyPairs(this);
    List<SSHKeyPairResponse> responses = new ArrayList<SSHKeyPairResponse>();
    for (SSHKeyPair result : resultList.first()) {
        SSHKeyPairResponse r = _responseGenerator.createSSHKeyPairResponse(result, false);
        r.setObjectName("sshkeypair");
        responses.add(r);
    }
    ListResponse<SSHKeyPairResponse> response = new ListResponse<SSHKeyPairResponse>();
    response.setResponses(responses, resultList.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : SSHKeyPairResponse(org.apache.cloudstack.api.response.SSHKeyPairResponse) SSHKeyPair(com.cloud.user.SSHKeyPair) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 55 with ListResponse

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

the class ListRegionsCmd method execute.

@Override
public void execute() {
    List<? extends Region> result = _regionService.listRegions(this);
    ListResponse<RegionResponse> response = new ListResponse<RegionResponse>();
    List<RegionResponse> regionResponses = new ArrayList<RegionResponse>();
    for (Region region : result) {
        RegionResponse regionResponse = _responseGenerator.createRegionResponse(region);
        regionResponse.setObjectName("region");
        regionResponses.add(regionResponse);
    }
    response.setResponses(regionResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : RegionResponse(org.apache.cloudstack.api.response.RegionResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) Region(org.apache.cloudstack.region.Region)

Aggregations

ListResponse (org.apache.cloudstack.api.response.ListResponse)177 ArrayList (java.util.ArrayList)160 List (java.util.List)70 ServerApiException (org.apache.cloudstack.api.ServerApiException)49 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)32 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 Account (com.cloud.user.Account)10 Network (com.cloud.network.Network)9 Host (com.cloud.host.Host)8 NetworkResponse (org.apache.cloudstack.api.response.NetworkResponse)8 Test (org.junit.Test)8 DedicatedResources (com.cloud.dc.DedicatedResources)7 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)7 TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)7 Domain (com.cloud.domain.Domain)6 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)5 ApiDiscoveryResponse (org.apache.cloudstack.api.response.ApiDiscoveryResponse)5 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)4 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4