Search in sources :

Example 1 with VirtualMachineTemplate

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

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

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

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

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

VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)65 ServerApiException (com.cloud.api.ServerApiException)22 TemplateResponse (com.cloud.api.response.TemplateResponse)20 Account (com.cloud.user.Account)16 ServerApiException (org.apache.cloudstack.api.ServerApiException)15 TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)9 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)9 ArrayList (java.util.ArrayList)9 ListResponse (com.cloud.api.response.ListResponse)8 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)8 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)8 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)8 DiskOffering (com.cloud.offering.DiskOffering)8 DataCenter (com.cloud.dc.DataCenter)7 Network (com.cloud.network.Network)7 VolumeVO (com.cloud.storage.VolumeVO)7 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7