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