Search in sources :

Example 1 with TemplateResponse

use of com.cloud.api.response.TemplateResponse in project CloudStack-archive by CloudStack-extras.

the class CreateTemplateCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Template Id: " + getEntityId() + ((getSnapshotId() == null) ? " from volume Id: " + getVolumeId() : " from snapshot Id: " + getSnapshotId()));
    VirtualMachineTemplate template = null;
    if (isBareMetal()) {
        template = _bareMetalVmService.createPrivateTemplate(this);
    } else {
        template = _userVmService.createPrivateTemplate(this);
    }
    if (template != null) {
        List<TemplateResponse> templateResponses;
        if (isBareMetal()) {
            templateResponses = _responseGenerator.createTemplateResponses(template.getId(), vmId);
        } else {
            templateResponses = _responseGenerator.createTemplateResponses(template.getId(), snapshotId, volumeId, false);
        }
        TemplateResponse response = new TemplateResponse();
        if (templateResponses != null && !templateResponses.isEmpty()) {
            response = templateResponses.get(0);
        }
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private template");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 2 with TemplateResponse

use of com.cloud.api.response.TemplateResponse in project CloudStack-archive by CloudStack-extras.

the class UpdateIsoCmd method execute.

@Override
public void execute() {
    VirtualMachineTemplate result = _mgr.updateTemplate(this);
    if (result != null) {
        TemplateResponse response = _responseGenerator.createIsoResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update iso");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 3 with TemplateResponse

use of com.cloud.api.response.TemplateResponse in project CloudStack-archive by CloudStack-extras.

the class PrepareTemplateCmd method execute.

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

Example 4 with TemplateResponse

use of com.cloud.api.response.TemplateResponse in project CloudStack-archive by CloudStack-extras.

the class UpdateTemplateCmd method execute.

@Override
public void execute() {
    VirtualMachineTemplate result = _mgr.updateTemplate(this);
    if (result != null) {
        TemplateResponse response = _responseGenerator.createIsoResponse(result);
        response.setObjectName("template");
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update template");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 5 with TemplateResponse

use of com.cloud.api.response.TemplateResponse in project CloudStack-archive by CloudStack-extras.

the class RegisterTemplateCmd 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(template.getId(), zoneId, false);
            response.setResponses(templateResponses);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to register template");
        }
    } catch (URISyntaxException ex1) {
        s_logger.info(ex1);
        throw new ServerApiException(BaseCmd.PARAM_ERROR, ex1.getMessage());
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse) URISyntaxException(java.net.URISyntaxException)

Aggregations

TemplateResponse (com.cloud.api.response.TemplateResponse)28 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)20 ServerApiException (com.cloud.api.ServerApiException)18 ListResponse (com.cloud.api.response.ListResponse)10 TemplateJoinVO (com.cloud.api.query.vo.TemplateJoinVO)5 ArrayList (java.util.ArrayList)5 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 URISyntaxException (java.net.URISyntaxException)3 ResponseView (com.cloud.api.ResponseObject.ResponseView)2 Account (com.cloud.user.Account)2 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 List (java.util.List)2 ListIsosCmdByAdmin (com.cloud.api.command.admin.iso.ListIsosCmdByAdmin)1 ListTemplatesCmdByAdmin (com.cloud.api.command.admin.template.ListTemplatesCmdByAdmin)1 LinkedHashMap (java.util.LinkedHashMap)1