Search in sources :

Example 31 with VmBase

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

the class VmDeviceUtils method addImportedOtherDevices.

/**
 * Add other managed and unmanaged devices to imported VM or template.
 *
 * @param vmDeviceToAdd list of devices to be added to the DB
 * @param withMemory true ~ devices are being added to a VM that is imported from snapshot with memory
 */
private void addImportedOtherDevices(VmBase vmBase, List<VmDevice> vmDeviceToAdd, boolean withMemory) {
    boolean hasCd = false;
    for (VmDevice vmDevice : vmBase.getManagedDeviceMap().values()) {
        switch(vmDevice.getType()) {
            case DISK:
                if (VmDeviceType.CDROM.getName().equals(vmDevice.getDevice())) {
                    hasCd = true;
                } else {
                    // disks are added separately
                    continue;
                }
                break;
            case INTERFACE:
                // network interfaces are added separately
                continue;
            case VIDEO:
                vmDevice.setSpecParams(getVideoDeviceSpecParams(vmBase));
                break;
            case HOSTDEV:
                // it is currently unsafe to import host devices, due to possibility of invalid dedicatedVmForVds
                continue;
        }
        vmDevice.setManaged(true);
        vmDeviceToAdd.add(vmDevice);
    }
    if (!hasCd) {
        // add an empty CD
        addCdDevice(vmBase.getId());
    }
    // add unmanaged devices
    final List<VmDevice> unmanagedDevicesToAdd = vmBase.getUnmanagedDeviceList().stream().filter(device -> !VmDeviceCommonUtils.isMemory(device) || withMemory).collect(Collectors.toList());
    vmDeviceToAdd.addAll(unmanagedDevicesToAdd);
}
Also used : UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) ClusterDao(org.ovirt.engine.core.dao.ClusterDao) StringUtils(org.apache.commons.lang.StringUtils) VmType(org.ovirt.engine.core.common.businessentities.VmType) VmDeviceUpdate(org.ovirt.engine.core.common.utils.VmDeviceUpdate) VmTemplateDao(org.ovirt.engine.core.dao.VmTemplateDao) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) ChipsetType(org.ovirt.engine.core.common.businessentities.ChipsetType) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) Map(java.util.Map) MacPoolPerCluster(org.ovirt.engine.core.bll.network.macpool.MacPoolPerCluster) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceDao(org.ovirt.engine.core.dao.VmDeviceDao) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) Version(org.ovirt.engine.core.compat.Version) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) VmHandler(org.ovirt.engine.core.bll.VmHandler) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Optional(java.util.Optional) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) ReadMacPool(org.ovirt.engine.core.bll.network.macpool.ReadMacPool) Guid(org.ovirt.engine.core.compat.Guid) UsbControllerModel(org.ovirt.engine.core.common.businessentities.UsbControllerModel) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) VdsProperties(org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Config(org.ovirt.engine.core.common.config.Config) CompatibilityVersionUtils(org.ovirt.engine.core.common.utils.CompatibilityVersionUtils) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VM(org.ovirt.engine.core.common.businessentities.VM) ConsoleTargetType(org.ovirt.engine.core.common.businessentities.ConsoleTargetType) VirtIoRngValidator(org.ovirt.engine.core.bll.validator.VirtIoRngValidator) VmManagementParametersBase(org.ovirt.engine.core.common.action.VmManagementParametersBase) Collections(java.util.Collections) VmInterfaceManager(org.ovirt.engine.core.bll.network.VmInterfaceManager) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Example 32 with VmBase

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

the class VmDeviceUtils method updateVmDevices.

/**
 * Update the VM devices according to the changes made.
 *
 * @param params    changes made
 * @param oldVm     previous state of the VM being modified
 */
public void updateVmDevices(VmManagementParametersBase params, VM oldVm, Supplier<Cluster> clusterSupplier) {
    VmBase oldVmBase = oldVm.getStaticData();
    VmBase newVmBase = params.getVmStaticData();
    if (newVmBase == null) {
        return;
    }
    updateCdPath(oldVmBase, newVmBase);
    updateVideoDevices(oldVmBase, newVmBase);
    updateUsbSlots(oldVmBase, newVmBase, clusterSupplier);
    updateMemoryBalloon(newVmBase.getId(), params.isBalloonEnabled());
    updateSoundDevice(oldVmBase, newVmBase, oldVm.getCompatibilityVersion(), params.isSoundDeviceEnabled());
    updateSmartcardDevice(oldVm, newVmBase);
    updateConsoleDevice(newVmBase.getId(), params.isConsoleEnabled());
    updateVirtioScsiController(newVmBase, params.isVirtioScsiEnabled());
}
Also used : VmBase(org.ovirt.engine.core.common.businessentities.VmBase)

Example 33 with VmBase

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

the class CpuProfileHelperTest method testDifferentClusters.

@Test
public void testDifferentClusters() {
    VmBase vmBase = createVmBase(cpuProfile1.getId());
    vmBase.setClusterId(Guid.newGuid());
    ValidationResult res = cpuProfileHelper.setAndValidateCpuProfile(vmBase, USER_1_ID);
    assertThat(res, failsWith(EngineMessage.ACTION_TYPE_CPU_PROFILE_NOT_MATCH_CLUSTER));
}
Also used : VmBase(org.ovirt.engine.core.common.businessentities.VmBase) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Test(org.junit.Test)

Example 34 with VmBase

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

the class CpuProfileHelperTest method testNoPermission.

@Test
public void testNoPermission() {
    VmBase vmBase = createVmBase(cpuProfile2.getId());
    ValidationResult res = cpuProfileHelper.setAndValidateCpuProfile(vmBase, USER_1_ID);
    assertThat(res, failsWith(EngineMessage.ACTION_TYPE_NO_PERMISSION_TO_ASSIGN_CPU_PROFILE));
}
Also used : VmBase(org.ovirt.engine.core.common.businessentities.VmBase) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) Test(org.junit.Test)

Example 35 with VmBase

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

the class CpuProfileHelperTest method createVmBase.

private VmBase createVmBase(Guid cpuProfileId) {
    VmBase vmBase = new VmBase();
    vmBase.setId(Guid.newGuid());
    vmBase.setClusterId(CLUSTER_ID);
    vmBase.setCpuProfileId(cpuProfileId);
    return vmBase;
}
Also used : VmBase(org.ovirt.engine.core.common.businessentities.VmBase)

Aggregations

VmBase (org.ovirt.engine.core.common.businessentities.VmBase)38 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)15 Guid (org.ovirt.engine.core.compat.Guid)11 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)9 VM (org.ovirt.engine.core.common.businessentities.VM)8 HashSet (java.util.HashSet)7 List (java.util.List)7 Set (java.util.Set)7 HashMap (java.util.HashMap)6 Collection (java.util.Collection)5 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)5 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)5 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)5 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)5 Collections (java.util.Collections)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4