HostVO host = ApiDBUtils.findHostById(templateHostRef.getHostId());
if (host.getType() == Host.Type.LocalSecondaryStorage && host.getStatus() != com.cloud.host.Status.Up) {
return responses;
}
TemplateResponse templateResponse = new TemplateResponse();
templateResponse.setId(template.getId());
templateResponse.setName(template.getName());
templateResponse.setDisplayText(template.getDisplayText());
templateResponse.setPublic(template.isPublicTemplate());
templateResponse.setCreated(templateHostRef.getCreated());
templateResponse.setReady(templateHostRef.getDownloadState() == Status.DOWNLOADED);
templateResponse.setFeatured(template.isFeatured());
templateResponse.setExtractable(template.isExtractable() && !(template.getTemplateType() == TemplateType.SYSTEM));
templateResponse.setPasswordEnabled(template.getEnablePassword());
templateResponse.setCrossZones(template.isCrossZones());
templateResponse.setFormat(template.getFormat());
if (template.getTemplateType() != null) {
templateResponse.setTemplateType(template.getTemplateType().toString());
}
templateResponse.setHypervisor(template.getHypervisorType().toString());
templateResponse.setDetails(template.getDetails());
GuestOS os = ApiDBUtils.findGuestOSById(template.getGuestOSId());
if (os != null) {
templateResponse.setOsTypeId(os.getId());
templateResponse.setOsTypeName(os.getDisplayName());
} else {
templateResponse.setOsTypeId(-1L);
templateResponse.setOsTypeName("");
}
Account account = ApiDBUtils.findAccountByIdIncludingRemoved(template.getAccountId());
populateAccount(templateResponse, account.getId());
populateDomain(templateResponse, account.getDomainId());
DataCenterVO datacenter = ApiDBUtils.findZoneById(zoneId);
// Add the zone ID
templateResponse.setZoneId(zoneId);
templateResponse.setZoneName(datacenter.getName());
boolean isAdmin = false;
Account caller = UserContext.current().getCaller();
if ((caller == null) || BaseCmd.isAdmin(caller.getType())) {
isAdmin = true;
}
// If the user is an Admin, add the template download status
if (isAdmin || caller.getId() == template.getAccountId()) {
// add download status
if (templateHostRef.getDownloadState() != Status.DOWNLOADED) {
String templateStatus = "Processing";
if (templateHostRef.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
if (templateHostRef.getDownloadPercent() == 100) {
templateStatus = "Installing Template";
} else {
templateStatus = templateHostRef.getDownloadPercent() + "% Downloaded";
}
} else {
templateStatus = templateHostRef.getErrorString();
}
templateResponse.setStatus(templateStatus);
} else if (templateHostRef.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) {
templateResponse.setStatus("Download Complete");
} else {
templateResponse.setStatus("Successfully Installed");
}
}
Long templateSize = templateHostRef.getSize();
if (templateSize > 0) {
templateResponse.setSize(templateSize);
}
templateResponse.setChecksum(template.getChecksum());
templateResponse.setSourceTemplateId(template.getSourceTemplateId());
templateResponse.setChecksum(template.getChecksum());
templateResponse.setTemplateTag(template.getTemplateTag());
//set tag information
List<? extends ResourceTag> tags = null;
if (template.getFormat() == ImageFormat.ISO) {
tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.ISO, template.getId());
} else {
tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Template, template.getId());
}
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
tagResponses.add(tagResponse);
}
templateResponse.setTags(tagResponses);
templateResponse.setObjectName("template");
responses.add(templateResponse);
return responses;
}