Search in sources :

Example 41 with ListResponse

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

the class ListStorageProvidersCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    if (getType() == null) {
        throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, "need to specify type: either primary or image");
    }
    List<StorageProviderResponse> providers = this.dataStoreProviderApiService.getDataStoreProviders(getType());
    ListResponse<StorageProviderResponse> responses = new ListResponse<StorageProviderResponse>();
    for (StorageProviderResponse provider : providers) {
        provider.setObjectName("dataStoreProvider");
    }
    responses.setResponses(providers);
    responses.setResponseName(this.getCommandName());
    this.setResponseObject(responses);
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) ListResponse(org.apache.cloudstack.api.response.ListResponse) StorageProviderResponse(org.apache.cloudstack.api.response.StorageProviderResponse)

Example 42 with ListResponse

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

the class ListSystemVMsCmd method execute.

@Override
public void execute() {
    Pair<List<? extends VirtualMachine>, Integer> systemVMs = _mgr.searchForSystemVm(this);
    ListResponse<SystemVmResponse> response = new ListResponse<SystemVmResponse>();
    List<SystemVmResponse> vmResponses = new ArrayList<SystemVmResponse>();
    for (VirtualMachine systemVM : systemVMs.first()) {
        SystemVmResponse vmResponse = _responseGenerator.createSystemVmResponse(systemVM);
        vmResponse.setObjectName("systemvm");
        vmResponses.add(vmResponse);
    }
    response.setResponses(vmResponses, systemVMs.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : SystemVmResponse(org.apache.cloudstack.api.response.SystemVmResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 43 with ListResponse

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

the class PrepareTemplateCmd method execute.

@Override
public void execute() {
    ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
    VirtualMachineTemplate vmTemplate = _templateService.prepareTemplate(templateId, zoneId, storageId);
    List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, vmTemplate, zoneId, true);
    response.setResponses(templateResponses);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse)

Example 44 with ListResponse

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

the class RegisterTemplateCmdByAdmin method execute.

@Override
public void execute() throws ResourceAllocationException {
    try {
        VirtualMachineTemplate template = _templateService.registerTemplate(this);
        if (template != null) {
            ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
            List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, template, zoneId, false);
            response.setResponses(templateResponses);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register template");
        }
    } catch (URISyntaxException ex1) {
        s_logger.info(ex1);
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex1.getMessage());
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse) URISyntaxException(java.net.URISyntaxException)

Example 45 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 {
        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) ServerApiException(org.apache.cloudstack.api.ServerApiException) 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) NicResponse(org.apache.cloudstack.api.response.NicResponse)

Aggregations

ListResponse (org.apache.cloudstack.api.response.ListResponse)149 ArrayList (java.util.ArrayList)134 List (java.util.List)62 ServerApiException (org.apache.cloudstack.api.ServerApiException)44 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)29 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)21 Network (com.cloud.network.Network)9 DedicatedResources (com.cloud.dc.DedicatedResources)8 NetworkResponse (org.apache.cloudstack.api.response.NetworkResponse)8 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)7 TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)7 Host (com.cloud.host.Host)6 Domain (com.cloud.domain.Domain)5 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)5 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)4 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 Account (com.cloud.user.Account)4