use of org.ovirt.engine.core.common.action.AddVmTemplateParameters in project ovirt-engine by oVirt.
the class BackendTemplatesResource method add.
@Override
public Response add(Template template) {
validateParameters(template, "name", "vm.id|name");
validateIconParameters(template);
Guid clusterId = null;
Cluster cluster = null;
if (namedCluster(template)) {
clusterId = getClusterId(template);
cluster = lookupCluster(clusterId);
}
if (template.getVersion() != null) {
validateParameters(template.getVersion(), "baseTemplate");
}
VmStatic originalVm = getVm(cluster, template);
VmStatic staticVm = getMapper(Template.class, VmStatic.class).map(template, originalVm);
if (namedCluster(template)) {
staticVm.setClusterId(clusterId);
}
// REVISIT: powershell has a IsVmTemlateWithSameNameExist safety check
AddVmTemplateParameters params = new AddVmTemplateParameters(staticVm, template.getName(), template.getDescription());
if (template.getVersion() != null) {
params.setBaseTemplateId(Guid.createGuidFromString(template.getVersion().getBaseTemplate().getId()));
params.setTemplateVersionName(template.getVersion().getVersionName());
}
params.setConsoleEnabled(template.getConsole() != null && template.getConsole().isSetEnabled() ? template.getConsole().isEnabled() : !getConsoleDevicesForEntity(originalVm.getId()).isEmpty());
params.setVirtioScsiEnabled(template.isSetVirtioScsi() && template.getVirtioScsi().isSetEnabled() ? template.getVirtioScsi().isEnabled() : null);
if (template.isSetSoundcardEnabled()) {
params.setSoundDeviceEnabled(template.isSoundcardEnabled());
} else {
params.setSoundDeviceEnabled(!VmHelper.getSoundDevicesForEntity(this, originalVm.getId()).isEmpty());
}
if (template.isSetRngDevice()) {
params.setUpdateRngDevice(true);
params.setRngDevice(RngDeviceMapper.map(template.getRngDevice(), null));
}
DisplayHelper.setGraphicsToParams(template.getDisplay(), params);
boolean isDomainSet = false;
if (template.isSetStorageDomain() && template.getStorageDomain().isSetId()) {
params.setDestinationStorageDomainId(asGuid(template.getStorageDomain().getId()));
isDomainSet = true;
}
params.setDiskInfoDestinationMap(getDestinationTemplateDiskMap(template.getVm(), originalVm.getId(), params.getDestinationStorageDomainId(), isDomainSet));
setupOptionalParameters(params);
IconHelper.setIconToParams(template, params);
Response response = performCreate(ActionType.AddVmTemplate, params, new QueryIdResolver<Guid>(QueryType.GetVmTemplate, GetVmTemplateParameters.class));
Template result = (Template) response.getEntity();
if (result != null) {
DisplayHelper.adjustDisplayData(this, result);
}
return response;
}
use of org.ovirt.engine.core.common.action.AddVmTemplateParameters in project ovirt-engine by oVirt.
the class InstanceTypeListModel method postInstanceTypeNameUniqueCheck.
private void postInstanceTypeNameUniqueCheck() {
UnitVmModel model = (UnitVmModel) getWindow();
VM vm = new VM();
buildVmStatic(vm.getStaticData());
vm.setVmDescription(model.getDescription().getEntity());
AddVmTemplateParameters addInstanceTypeParameters = new AddVmTemplateParameters(vm, model.getName().getEntity(), model.getDescription().getEntity());
addInstanceTypeParameters.setTemplateType(VmEntityType.INSTANCE_TYPE);
addInstanceTypeParameters.setVmTemplateId(null);
addInstanceTypeParameters.setPublicUse(true);
addInstanceTypeParameters.setSoundDeviceEnabled(model.getIsSoundcardEnabled().getEntity());
addInstanceTypeParameters.setConsoleEnabled(model.getIsConsoleDeviceEnabled().getEntity());
addInstanceTypeParameters.setBalloonEnabled(model.getMemoryBalloonDeviceEnabled().getEntity());
addInstanceTypeParameters.setVirtioScsiEnabled(model.getIsVirtioScsiEnabled().getEntity());
if (model.getIsHeadlessModeEnabled().getEntity()) {
addInstanceTypeParameters.getVm().setDefaultDisplayType(DisplayType.none);
}
setVmWatchdogToParams(model, addInstanceTypeParameters);
setRngDeviceToParams(model, addInstanceTypeParameters);
BuilderExecutor.build(model, addInstanceTypeParameters, new UnitToGraphicsDeviceParamsBuilder());
getWindow().startProgress();
Frontend.getInstance().runAction(ActionType.AddVmTemplate, addInstanceTypeParameters, new UnitVmModelNetworkAsyncCallback(model, addInstanceTypeNetworkManager), this);
}
use of org.ovirt.engine.core.common.action.AddVmTemplateParameters in project ovirt-engine by oVirt.
the class AddVmTemplateCommandTest method setupDedicatedHostForVmAndTemplate.
private void setupDedicatedHostForVmAndTemplate(boolean setDefaultHostForTemplate) {
Guid hostId = Guid.newGuid();
vm.setDedicatedVmForVdsList(Collections.singletonList(hostId));
AddVmTemplateParameters parameters = new AddVmTemplateParameters();
VmStatic vmStatic = new VmStatic();
vmStatic.setDedicatedVmForVdsList(setDefaultHostForTemplate ? Collections.singletonList(hostId) : Collections.emptyList());
parameters.setMasterVm(vmStatic);
parameters.setTemplateType(VmEntityType.TEMPLATE);
doReturn(parameters).when(cmd).getParameters();
}
use of org.ovirt.engine.core.common.action.AddVmTemplateParameters in project ovirt-engine by oVirt.
the class ImportRepoImageCommand method createTemplate.
private Guid createTemplate() {
VmTemplate blankTemplate = vmTemplateDao.get(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
VmStatic masterVm = new VmStatic(blankTemplate);
DiskImage templateDiskImage = getParameters().getDiskImage();
String vmTemplateName = getParameters().getTemplateName();
AddVmTemplateParameters parameters = new AddVmTemplateParameters(masterVm, vmTemplateName, templateDiskImage.getDiskDescription());
// Setting the user from the parent command, as the session might already be invalid
parameters.setParametersCurrentUser(getParameters().getParametersCurrentUser());
// Setting the cluster ID, and other related properties derived from it
if (getParameters().getClusterId() != null) {
masterVm.setClusterId(getParameters().getClusterId());
Cluster vdsGroup = getCluster(masterVm.getClusterId());
masterVm.setOsId(osRepository.getDefaultOSes().get(vdsGroup.getArchitecture()));
DisplayType defaultDisplayType = osRepository.getGraphicsAndDisplays(masterVm.getOsId(), vdsGroup.getCompatibilityVersion()).get(0).getSecond();
masterVm.setDefaultDisplayType(defaultDisplayType);
}
parameters.setBalloonEnabled(true);
ActionReturnValue addVmTemplateReturnValue = Backend.getInstance().runInternalAction(ActionType.AddVmTemplate, parameters, ExecutionHandler.createDefaultContextForTasks(getContext()));
// No reason for this to return null, but checking just to make sure, and returning the created template, or null if failed
return addVmTemplateReturnValue.getActionReturnValue() != null ? (Guid) addVmTemplateReturnValue.getActionReturnValue() : null;
}
use of org.ovirt.engine.core.common.action.AddVmTemplateParameters in project ovirt-engine by oVirt.
the class BackendInstanceTypesResource method add.
@Override
public Response add(InstanceType instanceType) {
validateParameters(instanceType, "name");
VmStatic vmStatic = getMapper(InstanceType.class, VmStatic.class).map(instanceType, new VmStatic());
VM vm = new VM();
vm.setStaticData(vmStatic);
String name = instanceType.getName();
String description = "";
if (instanceType.isSetDescription()) {
description = instanceType.getDescription();
}
vm.setVmDescription(description);
updateMaxMemoryIfUnspecified(instanceType, vm);
AddVmTemplateParameters addInstanceTypeParameters = new AddVmTemplateParameters(vm, name, description);
addInstanceTypeParameters.setTemplateType(VmEntityType.INSTANCE_TYPE);
addInstanceTypeParameters.setVmTemplateId(null);
addInstanceTypeParameters.setPublicUse(true);
addInstanceTypeParameters.setConsoleEnabled(instanceType.getConsole() != null && instanceType.getConsole().isSetEnabled() ? instanceType.getConsole().isEnabled() : false);
addInstanceTypeParameters.setVirtioScsiEnabled(instanceType.isSetVirtioScsi() && instanceType.getVirtioScsi().isSetEnabled() ? instanceType.getVirtioScsi().isEnabled() : null);
if (instanceType.isSetSoundcardEnabled()) {
addInstanceTypeParameters.setSoundDeviceEnabled(instanceType.isSoundcardEnabled());
}
DisplayHelper.setGraphicsToParams(instanceType.getDisplay(), addInstanceTypeParameters);
Response response = performCreate(ActionType.AddVmTemplate, addInstanceTypeParameters, new QueryIdResolver<Guid>(QueryType.GetInstanceType, GetVmTemplateParameters.class));
Template result = (Template) response.getEntity();
if (result != null) {
DisplayHelper.adjustDisplayData(this, result);
}
return response;
}
Aggregations