use of com.cloud.api.response.TemplateResponse in project cosmic by MissionCriticalCloud.
the class TemplateJoinDaoImpl method newUpdateResponse.
// TODO: This is to keep compatibility with 4.1 API, where updateTemplateCmd and updateIsoCmd will return a simpler TemplateResponse
// compared to listTemplates and listIsos.
@Override
public TemplateResponse newUpdateResponse(final TemplateJoinVO result) {
final TemplateResponse response = new TemplateResponse();
response.setId(result.getUuid());
response.setName(result.getName());
response.setDisplayText(result.getDisplayText());
response.setPublic(result.isPublicTemplate());
response.setCreated(result.getCreated());
response.setFormat(result.getFormat());
response.setOsTypeId(result.getGuestOSUuid());
response.setOsTypeName(result.getGuestOSName());
response.setBootable(result.isBootable());
response.setHypervisor(result.getHypervisorType().toString());
// populate owner.
ApiResponseHelper.populateOwner(response, result);
// populate domain
response.setDomainId(result.getDomainUuid());
response.setDomainName(result.getDomainName());
// set details map
if (result.getDetailName() != null) {
final Map<String, String> details = new HashMap<>();
details.put(result.getDetailName(), result.getDetailValue());
response.setDetails(details);
}
// update tag information
final long tag_id = result.getTagId();
if (tag_id > 0) {
final ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
if (vtag != null) {
response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
}
}
response.setObjectName("iso");
return response;
}
use of com.cloud.api.response.TemplateResponse in project cosmic by MissionCriticalCloud.
the class CreateTemplateCmd 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) {
final List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Restricted, 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");
}
}
use of com.cloud.api.response.TemplateResponse in project cosmic by MissionCriticalCloud.
the class RegisterTemplateCmd method execute.
@Override
public void execute() throws ResourceAllocationException {
try {
final VirtualMachineTemplate template = _templateService.registerTemplate(this);
if (template != null) {
final ListResponse<TemplateResponse> response = new ListResponse<>();
final List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Restricted, template, zoneId, false);
response.setResponses(templateResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register template");
}
} catch (final URISyntaxException ex1) {
s_logger.info(ex1.toString());
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex1.getMessage());
}
}
use of com.cloud.api.response.TemplateResponse in project cosmic by MissionCriticalCloud.
the class UpdateTemplateCmd method execute.
@Override
public void execute() {
final VirtualMachineTemplate result = _templateService.updateTemplate(this);
if (result != null) {
final TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(ResponseView.Restricted, result);
response.setObjectName("template");
// Template can be either USER or ROUTING type
response.setTemplateType(result.getTemplateType().toString());
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update template");
}
}
use of com.cloud.api.response.TemplateResponse in project cosmic by MissionCriticalCloud.
the class RegisterIsoCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceAllocationException {
final VirtualMachineTemplate template = _templateService.registerIso(this);
if (template != null) {
final ListResponse<TemplateResponse> response = new ListResponse<>();
final 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");
}
}
Aggregations