Search in sources :

Example 71 with DiskVmElement

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

the class MultipleDiskVmElementValidatorTest method setUp.

@Before
public void setUp() {
    diskWithOneVmElement = createDiskImage();
    diskWithOneVmElement.setDiskAlias("diskWithOneVmElement");
    diskVmElement1 = new DiskVmElement(diskWithOneVmElement.getId(), Guid.newGuid());
    diskWithTwoVmElements = createDiskImage();
    diskWithOneVmElement.setDiskAlias("diskWithTwoVmElements");
    diskVmElement2 = new DiskVmElement(diskWithOneVmElement.getId(), Guid.newGuid());
    diskVmElement3 = new DiskVmElement(diskWithTwoVmElements.getId(), Guid.newGuid());
    diskToDiskVmElements = new HashMap<>();
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Before(org.junit.Before)

Example 72 with DiskVmElement

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

the class ImportRepoImageCommand method attachDiskToTemplate.

private void attachDiskToTemplate(Guid templateId) {
    DiskImage templateDiskImage = getParameters().getDiskImage();
    DiskVmElement dve = new DiskVmElement(templateDiskImage.getId(), templateId);
    dve.setBoot(true);
    dve.setDiskInterface(DiskInterface.VirtIO);
    diskVmElementDao.save(dve);
    vmDeviceUtils.addDiskDevice(templateId, templateDiskImage.getId());
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 73 with DiskVmElement

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

the class BlockStorageDiscardFunctionalityHelper method logIfDisksWithIllegalPassDiscardExist.

public void logIfDisksWithIllegalPassDiscardExist(Guid vmId) {
    Collection<DiskImage> disks = DisksFilter.filterImageDisks(diskDao.getAllForVm(vmId));
    Collection<DiskVmElement> diskVmElements = diskVmElementDao.getAllForVm(vmId);
    Map<Disk, DiskVmElement> diskToDiskVmElement = diskHandler.getDiskToDiskVmElementMap(disks, diskVmElements);
    Map<Guid, Guid> diskIdToDestSdId = disks.stream().collect(Collectors.toMap(DiskImage::getId, diskImage -> diskImage.getStorageIds().get(0)));
    MultipleDiskVmElementValidator multipleDiskVmElementValidator = new MultipleDiskVmElementValidator(diskToDiskVmElement);
    Collection<Guid> disksWithoutSupportForPassDiscard = multipleDiskVmElementValidator.getDisksWithoutSupportForPassDiscard(diskIdToDestSdId);
    if (!disksWithoutSupportForPassDiscard.isEmpty()) {
        AuditLogable auditLog = new AuditLogableImpl();
        auditLog.addCustomValue("DisksIds", disksWithoutSupportForPassDiscard.stream().map(Guid::toString).collect(Collectors.joining(", ")));
        auditLogDirector.log(auditLog, AuditLogType.DISKS_WITH_ILLEGAL_PASS_DISCARD_EXIST);
    }
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) Singleton(javax.inject.Singleton) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Inject(javax.inject.Inject) MultipleDiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.MultipleDiskVmElementValidator) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) DiskImageDao(org.ovirt.engine.core.dao.DiskImageDao) Map(java.util.Map) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskVmElementDao(org.ovirt.engine.core.dao.DiskVmElementDao) Collectors(java.util.stream.Collectors) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) DiskHandler(org.ovirt.engine.core.bll.storage.disk.DiskHandler) List(java.util.List) DiskDao(org.ovirt.engine.core.dao.DiskDao) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) AuditLogType(org.ovirt.engine.core.common.AuditLogType) Collections(java.util.Collections) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) MultipleDiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.MultipleDiskVmElementValidator) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) Guid(org.ovirt.engine.core.compat.Guid) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 74 with DiskVmElement

use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement 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 75 with DiskVmElement

use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement 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)

Aggregations

DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)91 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)30 Test (org.junit.Test)26 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)23 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)22 Guid (org.ovirt.engine.core.compat.Guid)17 ArrayList (java.util.ArrayList)16 VM (org.ovirt.engine.core.common.businessentities.VM)12 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)11 HashMap (java.util.HashMap)8 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)8 Map (java.util.Map)7 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)7 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)7 ActionType (org.ovirt.engine.core.common.action.ActionType)6 AttachDetachVmDiskParameters (org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 VmDiskOperationParameterBase (org.ovirt.engine.core.common.action.VmDiskOperationParameterBase)5 Collection (java.util.Collection)4