@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } DiskVmElement that = (DiskVmElement) o; return boot == that.boot && passDiscard == that.passDiscard && diskInterface == that.diskInterface && usingScsiReservation == that.usingScsiReservation && plugged == that.plugged && Objects.equals(logicalName, that.logicalName) && readOnly == that.readOnly && Objects.equals(id, that.getId()); }
public Guid getDiskId() { return getId().getDeviceId(); }
public Guid getVmId() { return getId().getVmId(); }
public void setDiskVmElements(Collection<DiskVmElement> diskVmElements) { diskVmElementsMap = diskVmElements.stream().collect(Collectors.toMap(d -> d.getId().getVmId(), Function.identity())); }
public static Map<VmDeviceId, DiskVmElement> extractDiskVmElements(VM vm) { Map<VmDeviceId, DiskVmElement> result = new HashMap<>(); for(Disk disk : vm.getDiskMap().values()) { DiskVmElement element = disk.getDiskVmElementForVm(vm.getId()); if (element != null) { result.put(element.getId(), element); } } return result; }
private void storeNextDisk(final Iterator<InstanceImageLineModel> lineModelIterator, final VM vm) { if (!lineModelIterator.hasNext()) { return; } InstanceImageLineModel instanceImageLineModel = lineModelIterator.next(); AbstractDiskModel diskModel = instanceImageLineModel.getDiskModel().getEntity(); if (diskModel == null || !instanceImageLineModel.isChanged()) { storeNextDisk(lineModelIterator, vm); } else { diskModel.setVm(vm); diskModel.getDiskVmElement().getId().setVmId(vm.getId()); diskModel.store(result -> { // have to wait until the previous returned because the operation needs a lock on the VM storeNextDisk(lineModelIterator, vm); }); } }
@Override protected MapSqlParameterSource createFullParametersMapper(DiskVmElement entity) { return createIdParameterMapper(entity.getId()) .addValue("is_boot", entity.isBoot()) .addValue("pass_discard", entity.isPassDiscard()) .addValue("disk_interface", EnumUtils.nameOrNull(entity.getDiskInterface())) .addValue("is_using_scsi_reservation", entity.isUsingScsiReservation()); }
protected Response attachDiskToVm(AbstractBackendCollectionResource resource, DiskAttachment attachment, IResolver entityResolver) { Guid diskId = Guid.createGuidFromStringDefaultEmpty(attachment.getDisk().getId()); DiskVmElement dve = map(attachment); dve.getId().setVmId(vmId); dve.getId().setDeviceId(diskId); AttachDetachVmDiskParameters params = new AttachDetachVmDiskParameters(dve); Disk disk = attachment.getDisk(); boolean isDiskActive = false; if (attachment.isSetActive()) { isDiskActive = BooleanUtils.toBoolean(attachment.isActive()); } params.setPlugUnPlug(isDiskActive); if (disk.isSetReadOnly()) { dve.setReadOnly(BooleanUtils.toBoolean(disk.isReadOnly())); } if (disk.isSetSnapshot()) { validateParameters(disk, "snapshot.id"); params.setSnapshotId(asGuid(disk.getSnapshot().getId())); } return resource.performCreate(ActionType.AttachDiskToVm, params, entityResolver); }
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; }
@Test public void testGetFilteredWithPermissions() { DiskVmElement result = dao.get(getExistingEntityId(), PRIVILEGED_USER_ID, true); assertNotNull(result); assertEquals(getExistingEntityId().toString(), result.getId().toString()); }
private ActionParametersBase getAddParameters(DiskAttachment attachment, org.ovirt.engine.core.common.businessentities.storage.Disk entity, Disk disk) { DiskVmElement dve = map(attachment); dve.getId().setVmId(vmId); AddDiskParameters parameters = new AddDiskParameters(dve, entity); Guid storageDomainId = getStorageDomainId(disk); if (storageDomainId != null) { parameters.setStorageDomainId(storageDomainId); } if (attachment.isSetActive()) { parameters.setPlugDiskToVm(attachment.isActive()); } if (disk.isSetLunStorage() && disk.getLunStorage().isSetHost()) { parameters.setVdsId(getHostId(disk.getLunStorage().getHost())); } return parameters; }
@Override public ActionParametersBase getParameters(DiskAttachment incoming, org.ovirt.engine.core.common.businessentities.storage.DiskVmElement entity) { DiskVmElement dve = map(incoming, entity); dve.getId().setVmId(vmId); // Disk has to be sent along with the attachment data to the update command Disk disk = runQuery(QueryType.GetDiskByDiskId, new IdQueryParameters(Guid.createGuidFromString(diskId))).getReturnValue(); // If a <disk> was specified inside the attachment data we can update its properties too if (incoming.isSetDisk()) { disk = DiskMapper.map(incoming.getDisk(), disk); // TODO: Remove this in version 5 of the API as the setting of the read only attribute should be from DiskAttachment if (incoming.getDisk().isSetReadOnly()) { dve.setReadOnly(incoming.getDisk().isReadOnly()); } } return new VmDiskOperationParameterBase(dve, disk); } }