Search in sources :

Example 1 with CpuProfile

use of org.ovirt.engine.core.common.businessentities.profiles.CpuProfile in project ovirt-engine by oVirt.

the class CpuProfileHelper method setAndValidateCpuProfile.

public ValidationResult setAndValidateCpuProfile(VmBase vmBase, Guid userId) {
    if (vmBase.getCpuProfileId() == null) {
        return assignFirstCpuProfile(vmBase, userId);
    }
    Guid clusterId = vmBase.getClusterId();
    if (clusterId == null) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_CPU_PROFILE_CLUSTER_NOT_PROVIDED);
    }
    CpuProfile fetchedCpuProfile = cpuProfileDao.get(vmBase.getCpuProfileId());
    if (fetchedCpuProfile == null) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_CPU_PROFILE_NOT_FOUND);
    }
    if (!clusterId.equals(fetchedCpuProfile.getClusterId())) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_CPU_PROFILE_NOT_MATCH_CLUSTER);
    }
    if (!checkPermissions(vmBase.getCpuProfileId(), userId)) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_NO_PERMISSION_TO_ASSIGN_CPU_PROFILE, String.format("$cpuProfileId %s", vmBase.getCpuProfileId()), String.format("$cpuProfileName %s", fetchedCpuProfile.getName()));
    }
    return ValidationResult.VALID;
}
Also used : CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 2 with CpuProfile

use of org.ovirt.engine.core.common.businessentities.profiles.CpuProfile in project ovirt-engine by oVirt.

the class ImportVmFromExportDomainModel method buildImportVmParameters.

private List<ActionParametersBase> buildImportVmParameters() {
    List<ActionParametersBase> prms = new ArrayList<>();
    for (Object item : getItems()) {
        VM vm = ((ImportVmData) item).getVm();
        ImportVmParameters prm = new ImportVmParameters(vm, (Guid) getEntity(), Guid.Empty, getStoragePool().getId(), getCluster().getSelectedItem().getId());
        if (getClusterQuota().getSelectedItem() != null && getClusterQuota().getIsAvailable()) {
            prm.setQuotaId(getClusterQuota().getSelectedItem().getId());
        }
        CpuProfile cpuProfile = getCpuProfiles().getSelectedItem();
        if (cpuProfile != null) {
            prm.setCpuProfileId(cpuProfile.getId());
        }
        prm.setForceOverride(true);
        prm.setCopyCollapse(((ImportVmData) item).getCollapseSnapshots().getEntity());
        Map<Guid, Guid> map = new HashMap<>();
        for (Map.Entry<Guid, Disk> entry : vm.getDiskMap().entrySet()) {
            DiskImage disk = (DiskImage) entry.getValue();
            map.put(disk.getId(), getDiskImportData(disk.getId()).getSelectedStorageDomain().getId());
            disk.setVolumeFormat(AsyncDataProvider.getInstance().getDiskVolumeFormat(getDiskImportData(disk.getId()).getSelectedVolumeType(), getDiskImportData(disk.getId()).getSelectedStorageDomain().getStorageType()));
            disk.setVolumeType(getDiskImportData(disk.getId()).getSelectedVolumeType());
            if (getDiskImportData(disk.getId()).getSelectedQuota() != null) {
                disk.setQuotaId(getDiskImportData(disk.getId()).getSelectedQuota().getId());
            }
        }
        prm.setImageToDestinationDomainMap(map);
        if (((ImportVmData) item).isExistsInSystem() || ((ImportVmData) item).getClone().getEntity()) {
            prm.setImportAsNewEntity(true);
            prm.setCopyCollapse(true);
        }
        prms.add(prm);
    }
    return prms;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) VM(org.ovirt.engine.core.common.businessentities.VM) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) ImportVmParameters(org.ovirt.engine.core.common.action.ImportVmParameters) HashMap(java.util.HashMap) Map(java.util.Map) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 3 with CpuProfile

use of org.ovirt.engine.core.common.businessentities.profiles.CpuProfile in project ovirt-engine by oVirt.

the class ImportVmFromExternalSourceModel method buildImportVmFromExternalProviderParameters.

private List<ActionParametersBase> buildImportVmFromExternalProviderParameters() {
    List<ActionParametersBase> prms = new ArrayList<>();
    for (Object item : getItems()) {
        ImportVmData importVmData = (ImportVmData) item;
        VM vm = importVmData.getVm();
        ImportVmFromExternalProviderParameters prm = new ImportVmFromExternalProviderParameters(vm, getStorage().getSelectedItem().getId(), getStoragePool().getId(), getCluster().getSelectedItem().getId());
        prm.setUrl(url);
        prm.setUsername(username);
        prm.setPassword(password);
        prm.setProxyHostId(proxyHostId);
        prm.setVirtioIsoName(getIso().getIsChangable() && getIso().getSelectedItem() != null ? getIso().getSelectedItem().getRepoImageId() : null);
        prm.setExternalName(importVmData.getName());
        if (getClusterQuota().getSelectedItem() != null && getClusterQuota().getIsAvailable()) {
            prm.setQuotaId(getClusterQuota().getSelectedItem().getId());
        }
        CpuProfile cpuProfile = getCpuProfiles().getSelectedItem();
        if (cpuProfile != null) {
            prm.setCpuProfileId(cpuProfile.getId());
        }
        prm.setForceOverride(true);
        prm.setCopyCollapse(importVmData.getCollapseSnapshots().getEntity());
        for (Map.Entry<Guid, Disk> entry : vm.getDiskMap().entrySet()) {
            DiskImage disk = (DiskImage) entry.getValue();
            ImportDiskData importDiskData = getDiskImportData(disk.getDiskAlias());
            disk.setVolumeType(getAllocation().getSelectedItem());
            // virt-v2v which converts the image format as well
            if (vm.getOrigin() != OriginType.KVM) {
                disk.setVolumeFormat(AsyncDataProvider.getInstance().getDiskVolumeFormat(disk.getVolumeType(), getStorage().getSelectedItem().getStorageType()));
            }
            if (getDiskImportData(disk.getDiskAlias()).getSelectedQuota() != null) {
                disk.setQuotaId(importDiskData.getSelectedQuota().getId());
            }
        }
        updateNetworkInterfacesForVm(vm);
        if (importVmData.isExistsInSystem() || importVmData.getClone().getEntity()) {
            prm.setImportAsNewEntity(true);
            prm.setCopyCollapse(true);
        }
        prms.add(prm);
    }
    return prms;
}
Also used : ArrayList(java.util.ArrayList) ImportVmFromExternalProviderParameters(org.ovirt.engine.core.common.action.ImportVmFromExternalProviderParameters) Guid(org.ovirt.engine.core.compat.Guid) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) VM(org.ovirt.engine.core.common.businessentities.VM) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) Map(java.util.Map) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 4 with CpuProfile

use of org.ovirt.engine.core.common.businessentities.profiles.CpuProfile in project ovirt-engine by oVirt.

the class ImportVmFromOvaModel method buildImportVmFromOvaParameters.

private List<ActionParametersBase> buildImportVmFromOvaParameters() {
    ImportVmData importVmData = (ImportVmData) getItems().iterator().next();
    VM vm = importVmData.getVm();
    ImportVmFromOvaParameters prm = new ImportVmFromOvaParameters(vm, getStorage().getSelectedItem().getId(), getStoragePool().getId(), getCluster().getSelectedItem().getId());
    prm.setOvaPath(ovaPath);
    prm.setProxyHostId(hostId);
    prm.setVirtioIsoName(getIso().getIsChangable() && getIso().getSelectedItem() != null ? getIso().getSelectedItem().getRepoImageId() : null);
    prm.setExternalName(importVmData.getName());
    if (getClusterQuota().getSelectedItem() != null && getClusterQuota().getIsAvailable()) {
        prm.setQuotaId(getClusterQuota().getSelectedItem().getId());
    }
    CpuProfile cpuProfile = getCpuProfiles().getSelectedItem();
    if (cpuProfile != null) {
        prm.setCpuProfileId(cpuProfile.getId());
    }
    prm.setForceOverride(true);
    prm.setCopyCollapse(importVmData.getCollapseSnapshots().getEntity());
    for (Map.Entry<Guid, Disk> entry : vm.getDiskMap().entrySet()) {
        DiskImage disk = (DiskImage) entry.getValue();
        ImportDiskData importDiskData = getDiskImportData(disk.getDiskAlias());
        disk.setVolumeType(getAllocation().getSelectedItem());
        disk.setVolumeFormat(AsyncDataProvider.getInstance().getDiskVolumeFormat(disk.getVolumeType(), getStorage().getSelectedItem().getStorageType()));
        if (getDiskImportData(disk.getDiskAlias()).getSelectedQuota() != null) {
            disk.setQuotaId(importDiskData.getSelectedQuota().getId());
        }
    }
    updateNetworkInterfacesForVm(vm);
    if (importVmData.isExistsInSystem() || importVmData.getClone().getEntity()) {
        prm.setImportAsNewEntity(true);
        prm.setCopyCollapse(true);
    }
    return Collections.singletonList(prm);
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) ImportVmFromOvaParameters(org.ovirt.engine.core.common.action.ImportVmFromOvaParameters) Guid(org.ovirt.engine.core.compat.Guid) Map(java.util.Map) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 5 with CpuProfile

use of org.ovirt.engine.core.common.businessentities.profiles.CpuProfile 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)

Aggregations

CpuProfile (org.ovirt.engine.core.common.businessentities.profiles.CpuProfile)20 Guid (org.ovirt.engine.core.compat.Guid)5 VM (org.ovirt.engine.core.common.businessentities.VM)4 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Test (org.junit.Test)3 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)3 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)3 HashMap (java.util.HashMap)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 CpuProfileParameters (org.ovirt.engine.core.common.action.CpuProfileParameters)2 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)2 Quota (org.ovirt.engine.core.common.businessentities.Quota)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 CpuQos (org.ovirt.engine.core.common.businessentities.qos.CpuQos)2 RepoImage (org.ovirt.engine.core.common.businessentities.storage.RepoImage)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 ImportVmFromExternalProviderParameters (org.ovirt.engine.core.common.action.ImportVmFromExternalProviderParameters)1 ImportVmFromOvaParameters (org.ovirt.engine.core.common.action.ImportVmFromOvaParameters)1