use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmDeviceUtils method addImportedInterfaces.
/**
* Add network interfaces to an imported VM or template.
*
* @param vmDevicesToUpdate list of devices to be updated in the DB
*/
private void addImportedInterfaces(VmBase vmBase, List<VmDevice> vmDevicesToUpdate) {
for (VmNic iface : vmBase.getInterfaces()) {
Guid deviceId = iface.getId();
VmDevice vmDevice = addInterface(vmBase.getId(), deviceId, true, iface.isPassthrough(), getVmDeviceAddress(vmBase, deviceId));
VmDevice exportedDevice = vmBase.getManagedDeviceMap().get(deviceId);
if (exportedDevice == null) {
vmBase.getManagedDeviceMap().put(deviceId, vmDevice);
exportedDevice = vmDevice;
}
exportedDevice.setPlugged(exportedDevice.isPlugged() && canPlugInterface(iface, vmBase));
updateImportedVmDevice(vmBase, vmDevice, deviceId, vmDevicesToUpdate);
}
}
use of org.ovirt.engine.core.common.businessentities.VmDevice 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.VmDevice in project ovirt-engine by oVirt.
the class VmDeviceUtils method updateImportedVmDevice.
/**
* Set common properties in a device for imported VM or template and add the device
* to the list of devices to be updated in the DB.
*
* @param vmDevicesToUpdate list of devices to be updated in the DB
*/
private void updateImportedVmDevice(VmBase vmBase, VmDevice vmDevice, Guid deviceId, List<VmDevice> vmDevicesToUpdate) {
VmDevice exportedDevice = vmBase.getManagedDeviceMap().get(deviceId);
if (exportedDevice != null) {
vmDevice.setAddress(exportedDevice.getAddress());
vmDevice.setPlugged(exportedDevice.isPlugged());
vmDevice.setReadOnly(exportedDevice.getReadOnly());
vmDevicesToUpdate.add(vmDevice);
}
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class VmDeviceUtils method addImportedDiskDevices.
/**
* Add disk devices to an imported VM or template.
*
* @param vmDevicesToUpdate list of devices to be updated in the DB
*/
private void addImportedDiskDevices(VmBase vmBase, List<VmDevice> vmDevicesToUpdate) {
final Guid vmId = vmBase.getId();
for (BaseDisk disk : getDisks(vmBase.getImages())) {
Guid deviceId = disk.getId();
VmDevice vmDevice = addDiskDevice(vmId, deviceId, getVmDeviceAddress(vmBase, vmId));
updateImportedVmDevice(vmBase, vmDevice, deviceId, vmDevicesToUpdate);
}
}
use of org.ovirt.engine.core.common.businessentities.VmDevice 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