Search in sources :

Example 6 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 7 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 8 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 9 with TemplateResponse

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

the class ViewResponseHelper method createTemplateUpdateResponse.

public static List<TemplateResponse> createTemplateUpdateResponse(ResponseView view, TemplateJoinVO... templates) {
    Hashtable<Long, TemplateResponse> vrDataList = new Hashtable<Long, TemplateResponse>();
    for (TemplateJoinVO vr : templates) {
        TemplateResponse vrData = vrDataList.get(vr.getId());
        if (vrData == null) {
            // first time encountering this volume
            vrData = ApiDBUtils.newTemplateUpdateResponse(vr);
        } else {
            // update tags
            vrData = ApiDBUtils.fillTemplateDetails(view, vrData, vr);
        }
        vrDataList.put(vr.getId(), vrData);
    }
    return new ArrayList<TemplateResponse>(vrDataList.values());
}
Also used : Hashtable(java.util.Hashtable) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) ArrayList(java.util.ArrayList) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse)

Example 10 with TemplateResponse

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

the class ViewResponseHelper method createIsoResponse.

public static List<TemplateResponse> createIsoResponse(ResponseView view, TemplateJoinVO... templates) {
    Hashtable<String, TemplateResponse> vrDataList = new Hashtable<String, TemplateResponse>();
    for (TemplateJoinVO vr : templates) {
        TemplateResponse vrData = vrDataList.get(vr.getTempZonePair());
        if (vrData == null) {
            // first time encountering this volume
            vrData = ApiDBUtils.newIsoResponse(vr);
        } else {
            // update tags
            vrData = ApiDBUtils.fillTemplateDetails(view, vrData, vr);
        }
        vrDataList.put(vr.getTempZonePair(), vrData);
    }
    return new ArrayList<TemplateResponse>(vrDataList.values());
}
Also used : Hashtable(java.util.Hashtable) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) ArrayList(java.util.ArrayList) 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