use of org.ovirt.engine.core.common.businessentities.InstanceType in project ovirt-engine by oVirt.
the class NewVmModelBehavior method selectedTemplateChanged.
private void selectedTemplateChanged(final VmTemplate template) {
// Copy VM parameters from template.
buildModel(template, (source, destination) -> {
setSelectedOSType(template, getModel().getSelectedCluster().getArchitecture());
doChangeDefaultHost(template.getDedicatedVmForVdsList());
if (updateStatelessFlag) {
getModel().getIsStateless().setEntity(template.isStateless());
}
updateStatelessFlag = true;
getModel().getIsRunAndPause().setEntity(template.isRunAndPause());
boolean hasCd = !StringHelper.isNullOrEmpty(template.getIsoPath());
getModel().getCdImage().setIsChangeable(hasCd);
getModel().getCdAttached().setEntity(hasCd);
if (hasCd) {
RepoImage currentCD = getModel().getCdImage().getItems().stream().filter(i -> i.getRepoImageId().equals(template.getIsoPath())).findFirst().orElse(null);
getModel().getCdImage().setSelectedItem(currentCD);
}
updateTimeZone(template.getTimeZone());
if (!template.getId().equals(Guid.Empty)) {
getModel().getStorageDomain().setIsChangeable(true);
getModel().getProvisioning().setIsChangeable(true);
getModel().getCopyPermissions().setIsAvailable(true);
initDisks();
} else {
getModel().getStorageDomain().setIsChangeable(false);
getModel().getProvisioning().setIsChangeable(false);
getModel().getCopyPermissions().setIsAvailable(false);
getModel().setDisks(null);
getModel().setIsDisksAvailable(false);
getModel().getInstanceImages().setIsChangeable(true);
}
getModel().getAllowConsoleReconnect().setEntity(template.isAllowConsoleReconnect());
getModel().getVmType().setSelectedItem(template.getVmType());
getModel().getUsbPolicy().setSelectedItem(template.getUsbPolicy());
updateRngDevice(template.getId());
initStorageDomains();
InstanceType selectedInstanceType = getModel().getInstanceTypes().getSelectedItem();
int instanceTypeMinAllocatedMemory = selectedInstanceType != null ? selectedInstanceType.getMinAllocatedMem() : 0;
// do not update if specified on template or instance type
if (template.getMinAllocatedMem() == 0 && instanceTypeMinAllocatedMemory == 0) {
updateMinAllocatedMemory();
}
updateQuotaByCluster(template.getQuotaId(), template.getQuotaName());
getModel().getCustomPropertySheet().deserialize(template.getCustomProperties());
getModel().getVmInitModel().init(template);
getModel().getVmInitEnabled().setEntity(template.getVmInit() != null);
if (getModel().getSelectedCluster() != null) {
updateCpuProfile(getModel().getSelectedCluster().getId(), template.getCpuProfileId());
}
provisioning_SelectedItemChanged();
updateMigrationForLocalSD();
// A workaround for setting the current saved CustomCompatibilityVersion value after
// it was reset by getTemplateWithVersion event
getModel().getCustomCompatibilityVersion().setSelectedItem(getSavedCurrentCustomCompatibilityVersion());
setCustomCompatibilityVersionChangeInProgress(false);
updateLeaseStorageDomains(template.getLeaseStorageDomainId());
});
}
use of org.ovirt.engine.core.common.businessentities.InstanceType in project ovirt-engine by oVirt.
the class BaseVmListModelTest method setUpUnitVmModelExpectations.
protected void setUpUnitVmModelExpectations(UnitVmModel model) {
when(model.getVmType().getSelectedItem()).thenReturn(VM_TYPE);
VmTemplate template = new VmTemplate();
template.setId(TEMPLATE_GUID);
TemplateWithVersion templateWithVersion = mock(TemplateWithVersion.class);
when(templateWithVersion.getTemplateVersion()).thenReturn(template);
when(model.getTemplateWithVersion().getSelectedItem()).thenReturn(templateWithVersion);
when(model.getName().getEntity()).thenReturn(VM_NAME);
InstanceType instanceType = new VmTemplate();
instanceType.setId(INSTANCE_TYPE_ID);
when(model.getInstanceTypes().getSelectedItem()).thenReturn(instanceType);
when(model.getOSType().getSelectedItem()).thenReturn(OS_TYPE);
when(model.getNumOfMonitors().getSelectedItem()).thenReturn(NUM_OF_MONITORS);
when(model.getDescription().getEntity()).thenReturn(DESCRIPTION);
when(model.getComment().getEntity()).thenReturn(COMMENT);
when(model.getEmulatedMachine().getSelectedItem()).thenReturn(EMULATED_MACHINE);
when(model.getCustomCpu().getSelectedItem()).thenReturn(CUSTOM_CPU_NAME);
when(model.getMemSize().getEntity()).thenReturn(MEM_SIZE);
when(model.getMaxMemorySize().getEntity()).thenReturn(MAX_MEMORY_SIZE);
when(model.getMinAllocatedMemory().getEntity()).thenReturn(MIN_MEM);
when(model.getSelectedCluster().getId()).thenReturn(CLUSTER_ID);
ListModel<TimeZoneModel> timeZoneModelListModel = mockTimeZoneListModel();
when(model.getTimeZone()).thenReturn(timeZoneModelListModel);
when(model.getNumOfSockets().getSelectedItem()).thenReturn(NUM_OF_SOCKETS);
when(model.getCoresPerSocket().getSelectedItem()).thenReturn(CORES_PER_SOCKET);
when(model.getThreadsPerCore().getSelectedItem()).thenReturn(THREADS_PER_CORE);
SerialNumberPolicyModel serialNumberPolicyModel = mockSerialNumberPolicyModel();
when(model.getSerialNumberPolicy()).thenReturn(serialNumberPolicyModel);
when(model.getAllowConsoleReconnect().getEntity()).thenReturn(true);
when(model.getIsSingleQxlEnabled().getEntity()).thenReturn(true);
when(model.getTotalCPUCores().getEntity()).thenReturn(Integer.toString(TOTAL_CPU));
when(model.getUsbPolicy().getSelectedItem()).thenReturn(USB_POLICY);
when(model.getIsStateless().getEntity()).thenReturn(true);
when(model.getIsSmartcardEnabled().getEntity()).thenReturn(true);
when(model.getIsDeleteProtected().getEntity()).thenReturn(true);
when(model.extractSelectedSsoMethod()).thenReturn(SSO_METHOD);
when(model.getBootSequence()).thenReturn(BOOT_SEQUENCE);
ListModel<RepoImage> cdListModel = mockCdListModel();
when(model.getCdImage()).thenReturn(cdListModel);
when(model.getIsHighlyAvailable().getEntity()).thenReturn(true);
when(model.getInitrd_path().getEntity()).thenReturn(INITRD_PATH);
when(model.getKernel_path().getEntity()).thenReturn(KERNEL_PATH);
when(model.getKernel_parameters().getEntity()).thenReturn(KERNEL_PARAMS);
when(model.getCustomPropertySheet().serialize()).thenReturn(CUSTOM_PROPERTIES);
ListModel<Quota> quotaListModel = mockQuotaListModel();
when(model.getQuota()).thenReturn(quotaListModel);
when(model.getVncKeyboardLayout().getSelectedItem()).thenReturn(VNC_KEYBOARD_LAYOUT);
when(model.getDisplayType().getSelectedItem()).thenReturn(DISPLAY_TYPE);
EntityModel<Integer> priorityEntityModel = mockEntityModel(PRIORITY);
when(model.getPriority().getSelectedItem()).thenReturn(priorityEntityModel);
when(model.getIsRunAndPause().getEntity()).thenReturn(true);
VDS defaultHost = new VDS();
defaultHost.setId(HOST_ID);
when(model.getDefaultHost().getSelectedItem()).thenReturn(defaultHost);
when(model.getDefaultHost().getSelectedItems()).thenReturn(Collections.singletonList(defaultHost));
when(model.getIsAutoAssign().getEntity()).thenReturn(false);
when(model.getMigrationMode().getSelectedItem()).thenReturn(MIGRATION_SUPPORT);
when(model.getSelectedMigrationDowntime()).thenReturn(MIGRATION_DOWNTIME);
when(model.getBootMenuEnabled().getEntity()).thenReturn(true);
when(model.getSpiceFileTransferEnabled().getEntity()).thenReturn(true);
when(model.getSpiceCopyPasteEnabled().getEntity()).thenReturn(true);
ListModel<CpuProfile> cpuProfiles = mockCpuProfiles();
when(model.getCpuProfiles()).thenReturn(cpuProfiles);
when(model.getNumaNodeCount().getEntity()).thenReturn(0);
when(model.getNumaTuneMode().getSelectedItem()).thenReturn(NumaTuneMode.INTERLEAVE);
when(model.getAutoConverge().getSelectedItem()).thenReturn(true);
when(model.getMigrateCompressed().getSelectedItem()).thenReturn(true);
when(model.getIcon().getEntity()).thenReturn(new IconWithOsDefault(LARGE_ICON_DATA, LARGE_OS_DEFAULT_ICON_DATA, SMALL_ICON_ID, ValidationResult.ok()));
when(model.getIoThreadsEnabled().getEntity()).thenReturn(true);
when(model.getConsoleDisconnectAction().getSelectedItem()).thenReturn(ConsoleDisconnectAction.REBOOT);
when(model.getCustomCompatibilityVersion().getSelectedItem()).thenReturn(Version.v3_6);
when(model.getOverrideMigrationPolicy().getEntity()).thenReturn(false);
when(model.getLease().getSelectedItem()).thenReturn(null);
}
use of org.ovirt.engine.core.common.businessentities.InstanceType in project ovirt-engine by oVirt.
the class BackendVmsResource method add.
@Override
public Response add(Vm vm) {
validateParameters(vm, "cluster.id|name");
validateIconParameters(vm);
Response response = null;
if (vm.isSetInitialization() && vm.getInitialization().isSetConfiguration()) {
validateParameters(vm, "initialization.configuration.type", "initialization.configuration.data");
response = importVmFromConfiguration(vm);
} else {
validateParameters(vm, "name");
if (isCreateFromSnapshot(vm)) {
validateSnapshotExistence(vm);
response = createVmFromSnapshot(vm);
} else {
validateParameters(vm, "template.id|name");
Cluster cluster = getCluster(vm);
VmTemplate template = lookupTemplate(vm.getTemplate(), cluster.getStoragePoolId());
VmStatic builtFromTemplate = VmMapper.map(template, null, cluster.getCompatibilityVersion());
// since the template cpu_profile doesn't match cluster.
if (!vm.isSetCpuProfile() && vm.isSetCluster() && !Objects.equals(Objects.toString(template.getClusterId(), null), vm.getCluster().getId())) {
builtFromTemplate.setCpuProfileId(null);
}
VmStatic builtFromInstanceType = null;
InstanceType instanceTypeEntity = null;
if (vm.isSetInstanceType() && (vm.getInstanceType().isSetId() || vm.getInstanceType().isSetName())) {
instanceTypeEntity = lookupInstance(vm.getInstanceType());
builtFromInstanceType = VmMapper.map(instanceTypeEntity, builtFromTemplate, cluster.getCompatibilityVersion());
builtFromInstanceType.setInstanceTypeId(instanceTypeEntity.getId());
}
VmStatic staticVm = getMapper(Vm.class, VmStatic.class).map(vm, builtFromInstanceType != null ? builtFromInstanceType : builtFromTemplate);
if (namedCluster(vm)) {
staticVm.setClusterId(cluster.getId());
}
updateMaxMemoryIfUnspecified(vm, staticVm);
if (Guid.Empty.equals(template.getId()) && !vm.isSetOs()) {
staticVm.setOsId(OsRepository.AUTO_SELECT_OS);
}
staticVm.setUsbPolicy(VmMapper.getUsbPolicyOnCreate(vm.getUsb()));
if (!isFiltered() && vm.isSetPlacementPolicy()) {
Set<Guid> hostGuidsSet = validateAndUpdateHostsInPlacementPolicy(vm.getPlacementPolicy());
staticVm.setDedicatedVmForVdsList(new LinkedList<>(hostGuidsSet));
} else {
vm.setPlacementPolicy(null);
}
// migration support (disabling it in architectures that do not support this feature)
if (!vm.isSetPlacementPolicy() && template.getId().equals(Guid.Empty)) {
staticVm.setMigrationSupport(null);
}
Guid storageDomainId = (vm.isSetStorageDomain() && vm.getStorageDomain().isSetId()) ? asGuid(vm.getStorageDomain().getId()) : Guid.Empty;
boolean clone = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, CLONE, true, false);
if (clone) {
response = cloneVmFromTemplate(staticVm, vm, template, instanceTypeEntity, cluster);
} else if (Guid.Empty.equals(template.getId())) {
response = addVmFromScratch(staticVm, vm, instanceTypeEntity, cluster);
} else {
response = addVm(staticVm, vm, storageDomainId, template, instanceTypeEntity, cluster);
}
}
}
Vm result = (Vm) response.getEntity();
if (result != null) {
DisplayHelper.adjustDisplayData(this, result, false);
removeRestrictedInfo(result);
}
return response;
}
use of org.ovirt.engine.core.common.businessentities.InstanceType in project ovirt-engine by oVirt.
the class InstanceTypeManager method updateAll.
/**
* First updates the list of instance types and selects the one which is supposed to be selected and then
* updates all the fields which are taken from the instance type (by calling the updateFields()).
*/
public void updateAll() {
final Guid selectedInstanceTypeId = getSelectedInstanceTypeId();
Frontend.getInstance().runQuery(QueryType.GetAllInstanceTypes, new QueryParametersBase(), new AsyncQuery<QueryReturnValue>(returnValue -> {
if (returnValue == null || !returnValue.getSucceeded()) {
return;
}
List<InstanceType> instanceTypes = new ArrayList<>();
// add this only if the user is allowed to
if (!getModel().isCreateInstanceOnly()) {
instanceTypes.add(CustomInstanceType.INSTANCE);
}
for (InstanceType instanceType : (Iterable<InstanceType>) returnValue.getReturnValue()) {
instanceTypes.add(instanceType);
}
getModel().getInstanceTypes().setItems(instanceTypes);
for (InstanceType instanceType : instanceTypes) {
if ((instanceType instanceof CustomInstanceType) && selectedInstanceTypeId == null) {
getModel().getInstanceTypes().setSelectedItem(CustomInstanceType.INSTANCE);
break;
}
if (instanceType.getId() == null || selectedInstanceTypeId == null) {
continue;
}
if (instanceType.getId().equals(selectedInstanceTypeId)) {
getModel().getInstanceTypes().setSelectedItem(instanceType);
break;
}
}
if (getModel().getInstanceTypes().getSelectedItem() instanceof CustomInstanceType) {
// detach if the instance type is "custom"
getModel().getAttachedToInstanceType().setEntity(false);
}
updateFields();
}));
}
use of org.ovirt.engine.core.common.businessentities.InstanceType in project ovirt-engine by oVirt.
the class VmTemplateDaoTest method testGetInstanceType.
/**
* Ensures that the template returned is instance type.
*/
@Test
public void testGetInstanceType() {
InstanceType result = dao.getInstanceType(FixturesTool.INSTANCE_TYPE);
assertNotNull(result);
assertEquals(FixturesTool.INSTANCE_TYPE, result.getId());
}
Aggregations