Search in sources :

Example 56 with VmDevice

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

the class VmHandler method addDeviceUpdateOnNextRun.

private boolean addDeviceUpdateOnNextRun(Guid vmId, VmDeviceGeneralType generalType, VmDeviceType type, boolean readOnly, String name, Object key, Object value, List<VmDeviceUpdate> updates) {
    if (key != null) {
        VmDeviceGeneralType keyGeneralType = VmDeviceGeneralType.UNKNOWN;
        VmDeviceType keyType = VmDeviceType.UNKNOWN;
        if (key instanceof VmDeviceGeneralType) {
            keyGeneralType = (VmDeviceGeneralType) key;
        } else if (key instanceof VmDeviceType) {
            keyType = (VmDeviceType) key;
        } else if (key instanceof GraphicsType) {
            keyType = ((GraphicsType) key).getCorrespondingDeviceType();
        } else {
            log.warn("addDeviceUpdateOnNextRun: Unsupported map key type: " + key.getClass().getName());
            return false;
        }
        if (keyGeneralType != VmDeviceGeneralType.UNKNOWN) {
            generalType = keyGeneralType;
        }
        if (keyType != VmDeviceType.UNKNOWN) {
            type = keyType;
        }
    }
    // if device type is set to unknown, search by general type only
    // because some devices have more than one type, like sound can be ac97/ich6
    String typeName = type != VmDeviceType.UNKNOWN ? type.getName() : null;
    if (value == null) {
        if (vmDeviceUtils.vmDeviceChanged(vmId, generalType, typeName, false)) {
            updates.add(new VmDeviceUpdate(generalType, type, readOnly, name, false));
        }
    } else if (value instanceof Boolean) {
        if (vmDeviceUtils.vmDeviceChanged(vmId, generalType, typeName, (Boolean) value)) {
            updates.add(new VmDeviceUpdate(generalType, type, readOnly, name, (Boolean) value));
        }
    } else if (value instanceof VmDevice) {
        if (vmDeviceUtils.vmDeviceChanged(vmId, generalType, typeName, (VmDevice) value)) {
            updates.add(new VmDeviceUpdate(generalType, type, readOnly, name, (VmDevice) value));
        }
    } else if (value instanceof VmWatchdog) {
        if (vmDeviceUtils.vmDeviceChanged(vmId, generalType, typeName, ((VmWatchdog) value).getVmDevice())) {
            updates.add(new VmDeviceUpdate(generalType, type, readOnly, name, ((VmWatchdog) value).getVmDevice()));
        }
    } else {
        log.warn("addDeviceUpdateOnNextRun: Unsupported value type: " + value.getClass().getName());
        return false;
    }
    return true;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceUpdate(org.ovirt.engine.core.common.utils.VmDeviceUpdate) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog)

Example 57 with VmDevice

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

the class VmDeviceUtils method disableAnyUsb.

private void disableAnyUsb(VmBase oldVm, VmBase newVm) {
    final List<VmDevice> usbControllers;
    if (UsbPolicy.DISABLED == oldVm.getUsbPolicy() && VmType.HighPerformance == oldVm.getVmType() && (usbControllers = getUsbControllers(newVm.getId())) != null && usbControllers.size() == 1 && UsbControllerModel.NONE.libvirtName.equals(getUsbControllerModelName(usbControllers.get(0)))) {
        return;
    }
    switch(oldVm.getUsbPolicy()) {
        case ENABLED_NATIVE:
            disableSpiceUsb(newVm.getId());
            break;
        case DISABLED:
            disableNormalUsb(newVm.getId());
            break;
    }
    addManagedDevice(new VmDeviceId(Guid.newGuid(), newVm.getId()), VmDeviceGeneralType.CONTROLLER, VmDeviceType.USB, createUsbControllerSpecParams(UsbControllerModel.NONE.libvirtName, 0), true, false);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 58 with VmDevice

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

the class VmDeviceUtils method copyDiskDevices.

/*
     * Disk device
     */
/**
 * Copy disk devices from the given list of devices to the destination VM. Device ids are changed in accordance
 * with the mapping given.
 */
public void copyDiskDevices(Guid dstId, List<VmDevice> srcDevices, Map<Guid, Guid> srcDeviceIdToDstDeviceIdMapping) {
    for (VmDevice device : srcDevices) {
        if (VmDeviceType.DISK.getName().equals(device.getDevice())) {
            if (srcDeviceIdToDstDeviceIdMapping.containsKey(device.getDeviceId())) {
                Guid dstDeviceId = srcDeviceIdToDstDeviceIdMapping.get(device.getDeviceId());
                device.setId(new VmDeviceId(dstDeviceId, dstId));
                device.setSpecParams(Collections.emptyMap());
                vmDeviceDao.save(device);
            }
        }
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Guid(org.ovirt.engine.core.compat.Guid) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 59 with VmDevice

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

the class VmDeviceUtils method addManagedDevice.

/**
 * Create new managed device.
 *
 * @param id            device id
 * @param generalType   device general type
 * @param type          device type
 * @param specParams    device spec params
 * @param isPlugged     is device plugged-in
 * @param isReadOnly    is device read-only
 * @param address       device address
 * @param customProps   device custom properties
 * @param isUsingScsiReservation    is device using SCSI reservation
 * @return      newly created VmDevice instance
 */
public VmDevice addManagedDevice(VmDeviceId id, VmDeviceGeneralType generalType, VmDeviceType type, Map<String, Object> specParams, Boolean isPlugged, Boolean isReadOnly, String address, Map<String, String> customProps) {
    VmDevice managedDevice = new VmDevice(id, generalType, type.getName(), StringUtils.isNotBlank(address) ? address : "", specParams, true, isPlugged, isReadOnly, "", customProps, null, null);
    vmDeviceDao.save(managedDevice);
    return managedDevice;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Example 60 with VmDevice

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

the class VmDeviceUtils method updateNormalUsb.

private void updateNormalUsb(VmBase vmBase, ChipsetType chipset) {
    final Collection<VmDevice> usbControllers = getUsbControllers(vmBase.getId());
    final List<VmDevice> unmanagedControllers = usbControllers.stream().filter(d -> !d.isManaged()).collect(Collectors.toList());
    final List<VmDevice> managedUsbControllers = usbControllers.stream().filter(VmDevice::isManaged).collect(Collectors.toList());
    if (unmanagedControllers.size() > 0) {
        acquireUnmanagedUsbController(vmBase, chipset, managedUsbControllers, unmanagedControllers);
        return;
    }
    final UsbControllerModel controllerModel = getUsbControllerModel(vmBase, chipset);
    if ((managedUsbControllers.isEmpty() && controllerModel == null) || (managedUsbControllers.size() == 1 && controllerModel != null && controllerModel.libvirtName.equals(getUsbControllerModelName(managedUsbControllers.get(0))))) {
        return;
    }
    disableNormalUsb(vmBase.getId());
    enableNormalUsb(vmBase, chipset);
}
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) UsbControllerModel(org.ovirt.engine.core.common.businessentities.UsbControllerModel)

Aggregations

VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)170 HashMap (java.util.HashMap)59 Guid (org.ovirt.engine.core.compat.Guid)53 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)48 ArrayList (java.util.ArrayList)34 Map (java.util.Map)33 VM (org.ovirt.engine.core.common.businessentities.VM)29 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)28 List (java.util.List)26 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)21 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)21 VmDeviceType (org.ovirt.engine.core.common.utils.VmDeviceType)20 Collections (java.util.Collections)19 Test (org.junit.Test)19 Collectors (java.util.stream.Collectors)18 Arrays (java.util.Arrays)17 Optional (java.util.Optional)17 StringUtils (org.apache.commons.lang.StringUtils)17 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)17 Inject (javax.inject.Inject)16