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;
}
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);
}
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);
}
}
}
}
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;
}
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);
}
Aggregations