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);
}
}
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;
}
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();
}
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)));
}
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);
}
Aggregations