use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmTemplateHandler method updateDisksFromDb.
public void updateDisksFromDb(VmTemplate vmt) {
vmt.getDiskTemplateMap().clear();
vmt.getDiskImageMap().clear();
vmt.getDiskList().clear();
List<Disk> diskList = diskDao.getAllForVm(vmt.getId());
for (Disk dit : diskList) {
DiskImage diskImage = (DiskImage) dit;
vmt.getDiskTemplateMap().put(dit.getId(), diskImage);
vmt.getDiskImageMap().put(dit.getId(), diskImage);
DiskVmElement dve = diskVmElementDao.get(new VmDeviceId(dit.getId(), vmt.getId()));
dit.setDiskVmElements(Collections.singletonList(dve));
vmt.getDiskList().add(diskImage);
}
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId 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.VmDeviceId 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.VmDeviceId in project ovirt-engine by oVirt.
the class VmDeviceUtils method copyVmDevices.
/**
* Copy devices from the given VmDevice list to the destination VM/VmBase.
*/
public void copyVmDevices(Guid srcId, Guid dstId, VmBase srcVmBase, VmBase dstVmBase, List<VmDevice> srcDevices, Map<Guid, Guid> srcDeviceIdToDstDeviceIdMapping, boolean isSoundEnabled, boolean isConsoleEnabled, Boolean isVirtioScsiEnabled, boolean isBalloonEnabled, Set<GraphicsType> graphicsToSkip, boolean copySnapshotDevices, boolean copyHostDevices, Version versionToUpdateRngDeviceWith) {
if (graphicsToSkip == null) {
graphicsToSkip = Collections.emptySet();
}
String dstCdPath = dstVmBase.getIsoPath();
boolean dstIsVm = !(dstVmBase instanceof VmTemplate);
boolean hasCd = hasCdDevice(dstVmBase.getId());
boolean hasSound = false;
boolean hasConsole = false;
boolean hasVirtioScsi = false;
boolean hasBalloon = false;
boolean hasRng = hasRngDevice(dstId);
Cluster cluster = null;
if (dstVmBase.getClusterId() != null) {
cluster = clusterDao.get(dstVmBase.getClusterId());
}
for (VmDevice device : srcDevices) {
if (device.getSnapshotId() != null && !copySnapshotDevices) {
continue;
}
Guid deviceId = Guid.newGuid();
Map<String, Object> specParams = new HashMap<>();
switch(device.getType()) {
case DISK:
if (VmDeviceType.DISK.getName().equals(device.getDevice())) {
if (srcDeviceIdToDstDeviceIdMapping.containsKey(device.getDeviceId())) {
deviceId = srcDeviceIdToDstDeviceIdMapping.get(device.getDeviceId());
}
} else if (VmDeviceType.CDROM.getName().equals(device.getDevice())) {
if (!hasCd) {
hasCd = true;
// check here is source VM had CD (VM from snapshot)
String srcCdPath = (String) device.getSpecParams().get(VdsProperties.Path);
specParams.putAll(getCdDeviceSpecParams(srcCdPath, dstCdPath));
} else {
// CD already exists
continue;
}
}
break;
case INTERFACE:
if (srcDeviceIdToDstDeviceIdMapping.containsKey(device.getDeviceId())) {
deviceId = srcDeviceIdToDstDeviceIdMapping.get(device.getDeviceId());
}
break;
case CONTROLLER:
if (VmDeviceType.USB.getName().equals(device.getDevice())) {
specParams = device.getSpecParams();
} else if (VmDeviceType.VIRTIOSCSI.getName().equals(device.getDevice())) {
hasVirtioScsi = true;
if (Boolean.FALSE.equals(isVirtioScsiEnabled)) {
continue;
}
}
break;
case VIDEO:
if (dstIsVm) {
// to the new Vm params.
continue;
}
specParams.putAll(getVideoDeviceSpecParams(dstVmBase));
break;
case BALLOON:
if (!isBalloonEnabled) {
continue;
}
hasBalloon = true;
specParams.putAll(getMemoryBalloonSpecParams());
break;
case SMARTCARD:
specParams.putAll(getSmartcardDeviceSpecParams());
break;
case WATCHDOG:
specParams.putAll(device.getSpecParams());
break;
case RNG:
if (hasRng) {
continue;
}
if (!new VirtIoRngValidator().canAddRngDevice(cluster, new VmRngDevice(device)).isValid()) {
continue;
}
final VmRngDevice rngDevice = new VmRngDevice(device);
if (versionToUpdateRngDeviceWith != null) {
rngDevice.updateSourceByVersion(versionToUpdateRngDeviceWith);
}
specParams.putAll(rngDevice.getSpecParams());
break;
case CONSOLE:
if (!isConsoleEnabled) {
continue;
}
specParams.putAll(device.getSpecParams());
hasConsole = true;
break;
case SOUND:
if (!isSoundEnabled) {
continue;
}
hasSound = true;
break;
case GRAPHICS:
GraphicsType type = GraphicsType.fromVmDeviceType(VmDeviceType.getByName(device.getDevice()));
// OR if we already have it
if (graphicsToSkip.contains(type) || hasGraphicsDevice(dstId, GraphicsType.fromString(device.getDevice()))) {
continue;
}
break;
case HOSTDEV:
if (!copyHostDevices) {
continue;
}
specParams.putAll(device.getSpecParams());
break;
default:
break;
}
device.setId(new VmDeviceId(deviceId, dstId));
device.setSpecParams(specParams);
vmDeviceDao.save(device);
}
if (!hasCd) {
addCdDevice(dstId, dstCdPath);
}
updateUsbSlots(srcVmBase, dstVmBase, () -> clusterDao.get(dstVmBase.getClusterId()));
if (isSoundEnabled && !hasSound) {
if (dstIsVm) {
addSoundDevice(dstVmBase);
} else {
addSoundDevice(dstVmBase.getId(), dstVmBase.getOsId(), cluster != null ? cluster.getCompatibilityVersion() : null);
}
}
if (isConsoleEnabled && !hasConsole) {
addConsoleDevice(dstId);
}
if (Boolean.TRUE.equals(isVirtioScsiEnabled) && !hasVirtioScsi) {
addVirtioScsiController(dstVmBase, getVmCompatibilityVersion(dstVmBase));
}
if (isBalloonEnabled && !hasBalloon) {
addMemoryBalloon(dstId);
}
if (dstIsVm) {
addVideoDevices(dstVmBase, getNeededNumberOfVideoDevices(dstVmBase));
}
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmDeviceUtils method addVirtioScsiController.
/**
* Add new VirtIO-SCSI controllers to the VM.
*/
public void addVirtioScsiController(VmBase vm, Version version) {
boolean hasIoThreads = vm.getNumOfIoThreads() > 0 && FeatureSupported.virtioScsiIoThread(version);
int numOfScsiControllers = hasIoThreads ? vm.getNumOfIoThreads() : 1;
for (int i = 0; i < numOfScsiControllers; i++) {
Map<String, Object> specParams = new HashMap<>();
if (hasIoThreads) {
// i + 1 because libvirt is indexing the io threads from 1 to N, not 0 to N - 1
specParams.put(VdsProperties.ioThreadId, i + 1);
}
VmDevice device = addManagedDevice(new VmDeviceId(Guid.newGuid(), vm.getId()), VmDeviceGeneralType.CONTROLLER, VmDeviceType.VIRTIOSCSI, specParams, true, false);
}
}
Aggregations