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;
}
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");
}
}
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");
}
}
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());
}
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());
}
Aggregations