use of com.cloud.template.VirtualMachineTemplate in project CloudStack-archive by CloudStack-extras.
the class CreateTemplateCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Template Id: " + getEntityId() + ((getSnapshotId() == null) ? " from volume Id: " + getVolumeId() : " from snapshot Id: " + getSnapshotId()));
VirtualMachineTemplate template = null;
if (isBareMetal()) {
template = _bareMetalVmService.createPrivateTemplate(this);
} else {
template = _userVmService.createPrivateTemplate(this);
}
if (template != null) {
List<TemplateResponse> templateResponses;
if (isBareMetal()) {
templateResponses = _responseGenerator.createTemplateResponses(template.getId(), vmId);
} else {
templateResponses = _responseGenerator.createTemplateResponses(template.getId(), snapshotId, volumeId, false);
}
TemplateResponse response = new TemplateResponse();
if (templateResponses != null && !templateResponses.isEmpty()) {
response = templateResponses.get(0);
}
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private template");
}
}
use of com.cloud.template.VirtualMachineTemplate 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 com.cloud.template.VirtualMachineTemplate 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 com.cloud.template.VirtualMachineTemplate in project cloudstack by apache.
the class CreateServiceInstanceCmd method create.
@Override
public void create() throws ResourceAllocationException {
// Parameter validation
try {
DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone == null) {
throw new InvalidParameterValueException("Unable to find zone ID " + zoneId);
}
Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
if (template == null) {
throw new InvalidParameterValueException("Invalid template ID " + templateId);
}
ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Invalid service offering ID " + serviceOfferingId);
}
Network left = _networkService.getNetwork(leftNetworkId);
if (left == null) {
throw new InvalidParameterValueException("Invalid ID for left network " + leftNetworkId);
}
Network right = _networkService.getNetwork(rightNetworkId);
if (right == null) {
throw new InvalidParameterValueException("Invalid ID for right network " + rightNetworkId);
}
if (name.isEmpty()) {
throw new InvalidParameterValueException("service instance name is empty");
}
ServiceVirtualMachine svm = _vrouterService.createServiceInstance(zone, owner, template, serviceOffering, name, left, right);
if (svm == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to create service instance");
}
setEntityId(svm.getId());
setEntityUuid(svm.getUuid());
} catch (Exception ex) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
}
use of com.cloud.template.VirtualMachineTemplate 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());
}
}
Aggregations