use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class RemoveImageCommand method removeImageFromDB.
private void removeImageFromDB() {
final DiskImage diskImage = getDiskImage();
final List<Snapshot> updatedSnapshots;
try {
VM vm = getVmForNonShareableDiskImage(diskImage);
// so no lock is required.
if (getParameters().isRemoveFromSnapshots() && vm != null) {
lockVmSnapshotsWithWait(vm);
updatedSnapshots = prepareSnapshotConfigWithoutImage(diskImage.getId());
} else {
updatedSnapshots = Collections.emptyList();
}
TransactionSupport.executeInScope(TransactionScopeOption.Required, () -> {
diskImageDynamicDao.remove(diskImage.getImageId());
Guid imageTemplate = diskImage.getImageTemplateId();
Guid currentGuid = diskImage.getImageId();
// the storage).
while (!currentGuid.equals(imageTemplate) && !currentGuid.equals(Guid.Empty)) {
removeChildren(currentGuid);
DiskImage image = diskImageDao.getSnapshotById(currentGuid);
if (image != null) {
removeSnapshot(image);
currentGuid = image.getParentId();
} else {
currentGuid = Guid.Empty;
log.warn("'image' (snapshot of image '{}') is null, cannot remove it.", diskImage.getImageId());
}
}
baseDiskDao.remove(diskImage.getId());
vmDeviceDao.remove(new VmDeviceId(diskImage.getId(), null));
updatedSnapshots.forEach(snapshotDao::update);
return null;
});
} finally {
if (getSnapshotsEngineLock() != null) {
lockManager.releaseLock(getSnapshotsEngineLock());
}
}
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmDeviceCommonUtilsTest method createCdRomDevice.
private VmDevice createCdRomDevice() {
Guid id = Guid.newGuid();
VmDevice device = new VmDevice();
device.setType(VmDeviceGeneralType.DISK);
device.setDevice(VmDeviceType.CDROM.getName());
device.setPlugged(true);
device.setId(new VmDeviceId(id, null));
return device;
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmDeviceCommonUtilsTest method testUpdateVmDevicesBootOrder.
@Test
public void testUpdateVmDevicesBootOrder() {
Map<VmDeviceId, DiskVmElement> idToDiskElement = new HashMap<>();
List<VmNetworkInterface> interfaces = new LinkedList<>();
VmDevice nic1 = createNetworkInterface(true, NIC_1_NAME, interfaces);
VmDevice unmanagedNic = createUnmanagedNetworkInterface(true);
VmDevice nic2 = createNetworkInterface(true, NIC_2_NAME, interfaces);
VmDevice nonBootableNic = createNetworkInterface(false, "", interfaces);
VmDevice bootableDisk = createDiskDevice(true, idToDiskElement);
VmDevice nonBootableDisk = createDiskDevice(false, idToDiskElement);
VmDevice cd = createCdRomDevice();
doReturn(BootSequence.DNC).when(vm).getDefaultBootSequence();
// it is important that nic2 will be before nic1 to ensure their boot order is
// ordered according to their names and not according to their position in the list
VmDeviceCommonUtils.updateVmDevicesBootOrder(vm.getDefaultBootSequence(), Arrays.asList(bootableDisk, nic2, cd, nic1, nonBootableDisk, unmanagedNic), interfaces, idToDiskElement);
int index = 1;
assertEquals("Wrong boot order for CD", index++, cd.getBootOrder());
assertEquals("Wrong boot order for nic1", index++, nic1.getBootOrder());
assertEquals("Wrong boot order for nic2", index++, nic2.getBootOrder());
assertEquals("Wrong boot order for non bootable nic", 0, nonBootableNic.getBootOrder());
assertEquals("Wrong boot order for unmanaged nic", 0, unmanagedNic.getBootOrder());
assertEquals("Wrong boot order for bootable disk", index++, bootableDisk.getBootOrder());
assertEquals("Wrong boot order for non bootable disk", 0, nonBootableDisk.getBootOrder());
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmDeviceCommonUtilsTest method createDiskDevice.
private VmDevice createDiskDevice(boolean boot, Map<VmDeviceId, DiskVmElement> idToDiskElement) {
Guid id = Guid.newGuid();
VmDevice device = new VmDevice();
device.setType(VmDeviceGeneralType.DISK);
device.setDevice(VmDeviceType.DISK.getName());
device.setId(new VmDeviceId(id, null));
DiskVmElement dve = new DiskVmElement(new VmDeviceId(id, null));
dve.setBoot(boot);
idToDiskElement.put(dve.getId(), dve);
return device;
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmStaticDaoTest method addVmDevice.
private void addVmDevice(Guid vmId, Guid diskId, Guid snapshotId) {
VmDevice device = new VmDevice(new VmDeviceId(diskId, vmId), VmDeviceGeneralType.DISK, VmDeviceType.DISK.getName(), "", null, true, false, false, "", null, snapshotId, null);
dbFacade.getVmDeviceDao().save(device);
}
Aggregations