Search in sources :

Example 6 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 7 with VirtualMachineTemplate

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

the class RegisterIsoCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    VirtualMachineTemplate template = _templateService.registerIso(this);
    if (template != null) {
        ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
        List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(ResponseView.Restricted, template, zoneId, false);
        response.setResponses(templateResponses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register ISO");
    }
}
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)

Example 8 with VirtualMachineTemplate

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

the class UpdateIsoCmd method execute.

@Override
public void execute() {
    VirtualMachineTemplate result = _templateService.updateTemplate(this);
    if (result != null) {
        TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(ResponseView.Restricted, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update ISO");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(org.apache.cloudstack.api.ServerApiException) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse)

Example 9 with VirtualMachineTemplate

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

the class CreateServiceInstanceCmd method create.

@Override
public void create() throws ResourceAllocationException {
    // Parameter validation
    try {
        DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find zone ID " + zoneId);
        }
        Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
        VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
        if (template == null) {
            throw new InvalidParameterValueException("Invalid template ID " + templateId);
        }
        ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
        if (serviceOffering == null) {
            throw new InvalidParameterValueException("Invalid service offering ID " + serviceOfferingId);
        }
        Network left = _networkService.getNetwork(leftNetworkId);
        if (left == null) {
            throw new InvalidParameterValueException("Invalid ID for left network " + leftNetworkId);
        }
        Network right = _networkService.getNetwork(rightNetworkId);
        if (right == null) {
            throw new InvalidParameterValueException("Invalid ID for right network " + rightNetworkId);
        }
        if (name.isEmpty()) {
            throw new InvalidParameterValueException("service instance name is empty");
        }
        ServiceVirtualMachine svm = _vrouterService.createServiceInstance(zone, owner, template, serviceOffering, name, left, right);
        if (svm == null) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to create service instance");
        }
        setEntityId(svm.getId());
        setEntityUuid(svm.getUuid());
    } catch (Exception ex) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering) Network(com.cloud.network.Network) ServiceVirtualMachine(org.apache.cloudstack.network.contrail.management.ServiceVirtualMachine) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 10 with VirtualMachineTemplate

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

the class CopyTemplateCmdByAdmin 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.Full, 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)

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