Search in sources :

Example 1 with TemplateResponse

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

the class TemplateJoinDaoImpl method newTemplateResponse.

@Override
public TemplateResponse newTemplateResponse(ResponseView view, TemplateJoinVO template) {
    TemplateResponse templateResponse = new TemplateResponse();
    templateResponse.setId(template.getUuid());
    templateResponse.setName(template.getName());
    templateResponse.setDisplayText(template.getDisplayText());
    templateResponse.setPublic(template.isPublicTemplate());
    templateResponse.setCreated(template.getCreatedOnStore());
    if (template.getFormat() == Storage.ImageFormat.BAREMETAL) {
        // for baremetal template, we didn't download, but is ready to use.
        templateResponse.setReady(true);
    } else {
        templateResponse.setReady(template.getState() == ObjectInDataStoreStateMachine.State.Ready);
    }
    templateResponse.setFeatured(template.isFeatured());
    templateResponse.setExtractable(template.isExtractable() && !(template.getTemplateType() == TemplateType.SYSTEM));
    templateResponse.setPasswordEnabled(template.isEnablePassword());
    templateResponse.setDynamicallyScalable(template.isDynamicallyScalable());
    templateResponse.setSshKeyEnabled(template.isEnableSshKey());
    templateResponse.setCrossZones(template.isCrossZones());
    templateResponse.setFormat(template.getFormat());
    if (template.getTemplateType() != null) {
        templateResponse.setTemplateType(template.getTemplateType().toString());
    }
    templateResponse.setHypervisor(template.getHypervisorType().toString());
    templateResponse.setOsTypeId(template.getGuestOSUuid());
    templateResponse.setOsTypeName(template.getGuestOSName());
    // populate owner.
    ApiResponseHelper.populateOwner(templateResponse, template);
    // populate domain
    templateResponse.setDomainId(template.getDomainUuid());
    templateResponse.setDomainName(template.getDomainName());
    // If the user is an 'Admin' or 'the owner of template', add the template download status
    if (view == ResponseView.Full || template.getAccountId() == CallContext.current().getCallingAccount().getId()) {
        String templateStatus = getTemplateStatus(template);
        if (templateStatus != null) {
            templateResponse.setStatus(templateStatus);
        }
    }
    if (template.getDataCenterId() > 0) {
        templateResponse.setZoneId(template.getDataCenterUuid());
        templateResponse.setZoneName(template.getDataCenterName());
    }
    Long templateSize = template.getSize();
    if (templateSize > 0) {
        templateResponse.setSize(templateSize);
    }
    templateResponse.setChecksum(template.getChecksum());
    if (template.getSourceTemplateId() != null) {
        templateResponse.setSourceTemplateId(template.getSourceTemplateUuid());
    }
    templateResponse.setTemplateTag(template.getTemplateTag());
    // set details map
    if (template.getDetailName() != null) {
        Map<String, String> details = new HashMap<String, String>();
        details.put(template.getDetailName(), template.getDetailValue());
        templateResponse.setDetails(details);
    }
    // update tag information
    long tag_id = template.getTagId();
    if (tag_id > 0) {
        addTagInformation(template, templateResponse);
    }
    templateResponse.setObjectName("template");
    return templateResponse;
}
Also used : HashMap(java.util.HashMap) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse)

Example 2 with TemplateResponse

use of org.apache.cloudstack.api.response.TemplateResponse 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 3 with TemplateResponse

use of org.apache.cloudstack.api.response.TemplateResponse 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 4 with TemplateResponse

use of org.apache.cloudstack.api.response.TemplateResponse 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)

Example 5 with TemplateResponse

use of org.apache.cloudstack.api.response.TemplateResponse 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)

Aggregations

TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)21 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)13 ServerApiException (org.apache.cloudstack.api.ServerApiException)12 ListResponse (org.apache.cloudstack.api.response.ListResponse)7 TemplateJoinVO (com.cloud.api.query.vo.TemplateJoinVO)5 ArrayList (java.util.ArrayList)5 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)2 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 List (java.util.List)2 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)2 Account (com.cloud.user.Account)1 LinkedHashMap (java.util.LinkedHashMap)1 ListIsosCmdByAdmin (org.apache.cloudstack.api.command.admin.iso.ListIsosCmdByAdmin)1 ListTemplatesCmdByAdmin (org.apache.cloudstack.api.command.admin.template.ListTemplatesCmdByAdmin)1