Search in sources :

Example 86 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class AttachDiskToVmCommand method executeVmCommand.

@Override
protected void executeVmCommand() {
    if (!isOperationPerformedOnDiskSnapshot()) {
        vmStaticDao.incrementDbGeneration(getVm().getId());
    }
    final VmDevice vmDevice = createVmDevice();
    vmDeviceDao.save(vmDevice);
    DiskVmElement diskVmElement = getDiskVmElement();
    diskVmElement.getId().setDeviceId(disk.getId());
    diskVmElementDao.save(diskVmElement);
    // When performing hot plug for VirtIO-SCSI or SPAPR_VSCSI the address map calculation needs this info to be populated
    disk.setDiskVmElements(Collections.singletonList(diskVmElement));
    // update cached image
    List<Disk> imageList = new ArrayList<>();
    imageList.add(disk);
    vmHandler.updateDisksForVm(getVm(), imageList);
    if (!isOperationPerformedOnDiskSnapshot()) {
        if (disk.isAllowSnapshot()) {
            updateDiskVmSnapshotId();
        }
    }
    if (getParameters().isPlugUnPlug() && getVm().getStatus() != VMStatus.Down) {
        performPlugCommand(VDSCommandType.HotPlugDisk, disk, vmDevice);
    }
    setSucceeded(true);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) ArrayList(java.util.ArrayList) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 87 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class HotPlugDiskToVmCommand method updateDeviceProperties.

protected void updateDeviceProperties() {
    VmDevice device = vmDeviceDao.get(oldVmDevice.getId());
    device.setPlugged(true);
    vmDeviceDao.updateHotPlugDisk(device);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Example 88 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class UpdateVmDiskCommandTest method validateFailedROVmAttachedToPool.

@Test
public void validateFailedROVmAttachedToPool() {
    when(diskDao.get(diskImageGuid)).thenReturn(createDiskImage());
    command.getParameters().getDiskVmElement().setReadOnly(true);
    VM vm = createVm(VMStatus.Down);
    vm.setVmPoolId(Guid.newGuid());
    initializeCommand(vm);
    // Default RO is false
    VmDevice vmDevice = stubVmDevice(diskImageGuid, vmId);
    ValidateTestUtils.runAndAssertValidateFailure(command, EngineMessage.ACTION_TYPE_FAILED_VM_ATTACHED_TO_POOL);
    vmDevice.setReadOnly(true);
    command.getParameters().getDiskVmElement().setReadOnly(false);
    ValidateTestUtils.runAndAssertValidateFailure(command, EngineMessage.ACTION_TYPE_FAILED_VM_ATTACHED_TO_POOL);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VM(org.ovirt.engine.core.common.businessentities.VM) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 89 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class UpdateVmDiskCommandTest method stubVmDevice.

private VmDevice stubVmDevice(Guid diskId, Guid vmId) {
    VmDevice vmDevice = createVmDevice(diskId, vmId);
    doReturn(vmDevice).when(command).getVmDeviceForVm();
    return vmDevice;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Example 90 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class SnapshotsManager method removeDisksNotInSnapshot.

/**
 * Remove all the disks which are allowed to be snapshot but not exist in the snapshot and are not disk snapshots
 * @param vmId - The vm id which is being snapshot.
 * @param diskIdsFromSnapshot - An image group id list for images which are part of the VM.
 */
private void removeDisksNotInSnapshot(Guid vmId, List<Guid> diskIdsFromSnapshot) {
    for (VmDevice vmDevice : vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vmId, VmDeviceGeneralType.DISK, VmDeviceType.DISK)) {
        if (!diskIdsFromSnapshot.contains(vmDevice.getDeviceId()) && vmDevice.getSnapshotId() == null) {
            Disk disk = diskDao.get(vmDevice.getDeviceId());
            if (disk != null && disk.isAllowSnapshot()) {
                baseDiskDao.remove(vmDevice.getDeviceId());
                vmDeviceDao.remove(vmDevice.getId());
            }
        }
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Aggregations

VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)170 HashMap (java.util.HashMap)59 Guid (org.ovirt.engine.core.compat.Guid)53 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)48 ArrayList (java.util.ArrayList)34 Map (java.util.Map)33 VM (org.ovirt.engine.core.common.businessentities.VM)29 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)28 List (java.util.List)26 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)21 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)21 VmDeviceType (org.ovirt.engine.core.common.utils.VmDeviceType)20 Collections (java.util.Collections)19 Test (org.junit.Test)19 Collectors (java.util.stream.Collectors)18 Arrays (java.util.Arrays)17 Optional (java.util.Optional)17 StringUtils (org.apache.commons.lang.StringUtils)17 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)17 Inject (javax.inject.Inject)16