Search in sources :

Example 11 with VirtualMachineTemplate

use of com.cloud.template.VirtualMachineTemplate in project cloudstack by apache.

the class CreateTemplateCmdByAdmin method execute.

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

Example 12 with VirtualMachineTemplate

use of com.cloud.template.VirtualMachineTemplate 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 13 with VirtualMachineTemplate

use of com.cloud.template.VirtualMachineTemplate 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 14 with VirtualMachineTemplate

use of com.cloud.template.VirtualMachineTemplate in project cloudstack by apache.

the class CopyTemplateCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    try {
        CallContext.current().setEventDetails(getEventDescription());
        VirtualMachineTemplate template = _templateService.copyTemplate(this);
        if (template != null) {
            List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(ResponseView.Restricted, template, getDestinationZoneId(), false);
            TemplateResponse response = new TemplateResponse();
            if (listResponse != null && !listResponse.isEmpty()) {
                response = listResponse.get(0);
            }
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to copy template");
        }
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(org.apache.cloudstack.api.ServerApiException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse)

Example 15 with VirtualMachineTemplate

use of com.cloud.template.VirtualMachineTemplate in project cloudstack by apache.

the class CreateTemplateCmd method create.

@Override
public void create() throws ResourceAllocationException {
    VirtualMachineTemplate template = null;
    //TemplateOwner should be the caller https://issues.citrite.net/browse/CS-17530
    template = _templateService.createPrivateTemplateRecord(this, _accountService.getAccount(getEntityOwnerId()));
    if (template != null) {
        setEntityId(template.getId());
        setEntityUuid(template.getUuid());
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a template");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Aggregations

VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)37 ServerApiException (org.apache.cloudstack.api.ServerApiException)15 TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)13 ServerApiException (com.cloud.api.ServerApiException)8 Account (com.cloud.user.Account)8 TemplateResponse (com.cloud.api.response.TemplateResponse)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 DataCenter (com.cloud.dc.DataCenter)5 ServiceOffering (com.cloud.offering.ServiceOffering)5 ListResponse (org.apache.cloudstack.api.response.ListResponse)5 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 URISyntaxException (java.net.URISyntaxException)4 ListResponse (com.cloud.api.response.ListResponse)3 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 Network (com.cloud.network.Network)3