Search in sources :

Example 56 with VmDeviceId

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());
        }
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 57 with VmDeviceId

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;
}
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 58 with VmDeviceId

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());
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 59 with VmDeviceId

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;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 60 with VmDeviceId

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);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Aggregations

VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)75 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)40 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)21 Guid (org.ovirt.engine.core.compat.Guid)19 HashMap (java.util.HashMap)13 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)12 Test (org.junit.Test)10 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)9 ArrayList (java.util.ArrayList)7 Map (java.util.Map)5 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)5 VM (org.ovirt.engine.core.common.businessentities.VM)5 VmPayload (org.ovirt.engine.core.common.businessentities.VmPayload)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)4 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)3 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)3