Search in sources :

Example 36 with VmDevice

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

the class ReorderVmNicsCommand method reorderNics.

private void reorderNics() {
    Map<Guid, VmDevice> vmInterfaceDevices = getVmInterfaceDevices();
    List<VmNic> nics = vmNicDao.getAllForVm(getParameters().getVmId());
    List<VmNic> nicsToReorder = new ArrayList<>();
    List<String> macsToReorder = new ArrayList<>();
    for (VmNic nic : nics) {
        VmDevice nicDevice = vmInterfaceDevices.get(nic.getId());
        // If there is not device, or the PCI address is empty
        if (nicDevice == null || StringUtils.isEmpty(nicDevice.getAddress())) {
            nicsToReorder.add(nic);
            // We know that all the NICs have a MAC address
            macsToReorder.add(nic.getMacAddress());
        }
    }
    // Sorting the NICs to reorder by name
    Collections.sort(nicsToReorder, numericSuffixNameableComparator);
    // Sorting the MAC addresses to reorder
    Collections.sort(macsToReorder);
    for (int i = 0; i < nicsToReorder.size(); ++i) {
        VmNic nic = nicsToReorder.get(i);
        nic.setMacAddress(macsToReorder.get(i));
        vmNicDao.update(nic);
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 37 with VmDevice

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

the class DiskImagesValidator method diskImagesSnapshotsAttachedToVm.

public ValidationResult diskImagesSnapshotsAttachedToVm(Guid vmId) {
    LinkedList<String> diskSnapshotInfo = new LinkedList<>();
    VM vm = getVmDao().get(vmId);
    for (DiskImage diskImage : diskImages) {
        List<VmDevice> devices = getVmDeviceDao().getVmDevicesByDeviceId(diskImage.getId(), vmId);
        if (devices.isEmpty()) {
            // The specified disk image does not belong to the vm
            Snapshot snapshot = getSnapshotDao().get(diskImage.getSnapshotId());
            Disk disk = getDbFacade().getDiskDao().get(diskImage.getId());
            diskSnapshotInfo.add(String.format("%s ,%s", disk.getDiskAlias(), snapshot.getDescription()));
        }
    }
    if (!diskSnapshotInfo.isEmpty()) {
        EngineMessage message = EngineMessage.ACTION_TYPE_FAILED_VM_DISK_SNAPSHOT_NOT_ATTACHED_TO_VM;
        return new ValidationResult(message, String.format("$disksInfo %s", String.format(StringUtils.join(diskSnapshotInfo, "%n"))), String.format("$vmName %s", vm.getName()));
    }
    return ValidationResult.VALID;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) LinkedList(java.util.LinkedList) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage)

Example 38 with VmDevice

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

the class RemoveDiskCommandTest method setUp.

@Before
public void setUp() {
    disk = new DiskImage();
    setupDisk();
    Guid vmId = Guid.newGuid();
    vm = new VM();
    vm.setId(vmId);
    VmDeviceId vmDeviceId = new VmDeviceId(diskId, vmId);
    VmDevice vmDevice = new VmDevice();
    vmDevice.setId(vmDeviceId);
    vmDevice.setPlugged(true);
    when(vmDao.getVmsListForDisk(diskId, Boolean.TRUE)).thenReturn(Collections.singletonList(vm));
    when(vmDeviceDao.get(vmDeviceId)).thenReturn(vmDevice);
    doReturn(disk).when(cmd).getDisk();
    doReturn(ActionType.RemoveDisk).when(cmd).getActionType();
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) 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) Before(org.junit.Before)

Example 39 with VmDevice

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

the class UpdateVmDiskCommandTest method mockGetVmsListForDisk.

private void mockGetVmsListForDisk(VM vm) {
    VmDevice device = createVmDevice(diskImageGuid, vm.getId());
    when(vmDao.getVmsWithPlugInfo(diskImageGuid)).thenReturn(Collections.singletonList(new Pair<>(vm, device)));
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 40 with VmDevice

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

the class UpdateVmDiskCommandTest method testFailedRoDiskResize.

@Test
public void testFailedRoDiskResize() {
    ((DiskImage) command.getParameters().getDiskInfo()).setSize(command.getParameters().getDiskInfo().getSize() * 2L);
    initializeCommand();
    DiskImage oldDisk = createDiskImage();
    doReturn(oldDisk).when(command).getOldDisk();
    VmDevice vmDevice = stubVmDevice(diskImageGuid, vmId);
    vmDevice.setReadOnly(true);
    assertFalse(command.validateCanResizeDisk());
    ValidateTestUtils.assertValidationMessages("wrong failure", command, EngineMessage.ACTION_TYPE_FAILED_CANNOT_RESIZE_READ_ONLY_DISK);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

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