Search in sources :

Example 1 with InstanceType

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());
    });
}
Also used : RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType)

Example 2 with InstanceType

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);
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) TemplateWithVersion(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateWithVersion) RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) Quota(org.ovirt.engine.core.common.businessentities.Quota) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType)

Example 3 with InstanceType

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;
}
Also used : Response(javax.ws.rs.core.Response) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Vm(org.ovirt.engine.api.model.Vm) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Guid(org.ovirt.engine.core.compat.Guid) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType)

Example 4 with InstanceType

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();
    }));
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) QueryType(org.ovirt.engine.core.common.queries.QueryType) Guid(org.ovirt.engine.core.compat.Guid) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) PriorityUtil(org.ovirt.engine.ui.uicommonweb.models.vms.PriorityUtil) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) Event(org.ovirt.engine.ui.uicompat.Event) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) HashSet(java.util.HashSet) Frontend(org.ovirt.engine.ui.frontend.Frontend) VmWatchdogType(org.ovirt.engine.core.common.businessentities.VmWatchdogType) UnitVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) VirtioScsiUtil(org.ovirt.engine.ui.uicommonweb.models.vms.VirtioScsiUtil) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType)

Example 5 with InstanceType

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());
}
Also used : InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) Test(org.junit.Test)

Aggregations

InstanceType (org.ovirt.engine.core.common.businessentities.InstanceType)10 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4 RepoImage (org.ovirt.engine.core.common.businessentities.storage.RepoImage)3 Quota (org.ovirt.engine.core.common.businessentities.Quota)2 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)2 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)2 Guid (org.ovirt.engine.core.compat.Guid)2 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)2 UnitVmModel (org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel)2 AbstractRenderer (com.google.gwt.text.shared.AbstractRenderer)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 GraphicsConsoles (org.ovirt.engine.api.model.GraphicsConsoles)1 Vm (org.ovirt.engine.api.model.Vm)1 BootSequence (org.ovirt.engine.core.common.businessentities.BootSequence)1