Search in sources :

Example 61 with DiskVmElement

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

the class BackendDiskAttachmentsResource method getAddParameters.

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;
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) AddDiskParameters(org.ovirt.engine.core.common.action.AddDiskParameters)

Example 62 with DiskVmElement

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

the class OvfOvirtWriter method writeDisk.

@Override
protected void writeDisk(DiskImage image) {
    DiskVmElement dve = image.getDiskVmElementForVm(vmBase.getId());
    _writer.writeAttributeString(getOvfUri(), "diskId", image.getImageId().toString());
    _writer.writeAttributeString(getOvfUri(), "size", String.valueOf(bytesToGigabyte(image.getSize())));
    _writer.writeAttributeString(getOvfUri(), "actual_size", String.valueOf(bytesToGigabyte(image.getActualSizeInBytes())));
    _writer.writeAttributeString(getOvfUri(), "vm_snapshot_id", (image.getVmSnapshotId() != null) ? image.getVmSnapshotId().toString() : "");
    writeDiskParentRef(image);
    _writer.writeAttributeString(getOvfUri(), "fileRef", OvfParser.createImageFile(image));
    _writer.writeAttributeString(getOvfUri(), "format", getVolumeImageFormat(image.getVolumeFormat()));
    _writer.writeAttributeString(getOvfUri(), "volume-format", image.getVolumeFormat().toString());
    _writer.writeAttributeString(getOvfUri(), "volume-type", image.getVolumeType().toString());
    _writer.writeAttributeString(getOvfUri(), "disk-interface", dve.getDiskInterface().toString());
    _writer.writeAttributeString(getOvfUri(), "read-only", String.valueOf(dve.isReadOnly()));
    _writer.writeAttributeString(getOvfUri(), "shareable", String.valueOf(image.isShareable()));
    _writer.writeAttributeString(getOvfUri(), "boot", String.valueOf(dve.isBoot()));
    if (FeatureSupported.passDiscardSupported(version)) {
        _writer.writeAttributeString(getOvfUri(), "pass-discard", String.valueOf(dve.isPassDiscard()));
    }
    if (image.getDiskAlias() != null) {
        _writer.writeAttributeString(getOvfUri(), "disk-alias", image.getDiskAlias());
    }
    if (image.getDiskDescription() != null) {
        _writer.writeAttributeString(getOvfUri(), "disk-description", image.getDiskDescription());
    }
    _writer.writeAttributeString(getOvfUri(), "wipe-after-delete", String.valueOf(image.isWipeAfterDelete()));
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)

Example 63 with DiskVmElement

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

the class VdsBrokerObjectsBuilder method buildDiskVmElementWithDiskInterfaceFromExternalProvider.

/**
 * TODO: NOTE that currently there is a limitation of VDSM sending only the
 * disk target dev name per each disk, therefore it will send "sdx" for 3 different
 * disk interfaces: SCSI,USB and SATA.
 * As a result, all those 3 mentioned disk interfaces will be mapped to SCSI
 * interface in target VM.
 * We need to receive the target bus name for each disk in order to differentiate.
 */
private static DiskVmElement buildDiskVmElementWithDiskInterfaceFromExternalProvider(Map<String, Object> map, DiskImage image, Guid vmId) {
    DiskVmElement dve = new DiskVmElement(image.getId(), vmId);
    String diskDevName = (String) map.get(VdsProperties.DISK_TARGET_DEV_NAME);
    diskDevName = (diskDevName == null || diskDevName.length() < 3) ? "" : diskDevName.substring(0, 2);
    switch(diskDevName) {
        case "sd":
            dve.setDiskInterface(DiskInterface.VirtIO_SCSI);
            break;
        case "hd":
            dve.setDiskInterface(DiskInterface.IDE);
            break;
        case "vd":
        default:
            dve.setDiskInterface(DiskInterface.VirtIO);
    }
    return dve;
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)

Example 64 with DiskVmElement

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

the class HotPlugDiskVDSCommand method initDriveData.

private Map<String, Object> initDriveData() {
    Map<String, Object> drive = new HashMap<>();
    Disk disk = getParameters().getDisk();
    VmDevice vmDevice = getParameters().getVmDevice();
    drive.put(VdsProperties.Type, VmDeviceType.DISK.getName());
    drive.put(VdsProperties.Address, getParameters().getAddressMap() != null ? getParameters().getAddressMap() : StringUtils.EMPTY);
    drive.put(VdsProperties.INTERFACE, getParameters().getDiskInterface().getName());
    if (FeatureSupported.passDiscardSupported(getParameters().getVm().getCompatibilityVersion())) {
        drive.put(VdsProperties.DISCARD, getParameters().isPassDiscard());
    }
    int numOfIoThreads = getParameters().getVm().getNumOfIoThreads();
    if (numOfIoThreads != 0 && getParameters().getDiskInterface() == DiskInterface.VirtIO) {
        if (vmDevice.getSpecParams() == null) {
            vmDevice.setSpecParams(new HashMap<>());
        }
        List<DiskVmElement> diskVmElements = diskVmElementDao.getAllPluggedToVm(getParameters().getVmId());
        int numOfAttachedVirtioInterfaces = 0;
        for (DiskVmElement dve : diskVmElements) {
            if (dve.getDiskInterface() == DiskInterface.VirtIO) {
                numOfAttachedVirtioInterfaces++;
            }
        }
        int pinToIoThread = numOfAttachedVirtioInterfaces % numOfIoThreads + 1;
        vmDevice.getSpecParams().put(VdsProperties.pinToIoThread, pinToIoThread);
    }
    drive.put(VdsProperties.Shareable, (vmDevice.getSnapshotId() != null) ? VdsProperties.Transient : String.valueOf(disk.isShareable()));
    drive.put(VdsProperties.Optional, Boolean.FALSE.toString());
    drive.put(VdsProperties.ReadOnly, String.valueOf(vmDevice.getReadOnly()));
    drive.put(VdsProperties.DeviceId, vmDevice.getId().getDeviceId().toString());
    switch(disk.getDiskStorageType()) {
        case IMAGE:
            DiskImage diskImage = (DiskImage) disk;
            drive.put(VdsProperties.DiskType, vmInfoBuildUtils.getDiskType(getParameters().getVm(), diskImage));
            drive.put(VdsProperties.Device, VmDeviceType.DISK.getName());
            drive.put(VdsProperties.Format, diskImage.getVolumeFormat().toString().toLowerCase());
            drive.put(VdsProperties.DomainId, diskImage.getStorageIds().get(0).toString());
            drive.put(VdsProperties.PoolId, diskImage.getStoragePoolId().toString());
            drive.put(VdsProperties.VolumeId, diskImage.getImageId().toString());
            drive.put(VdsProperties.ImageId, diskImage.getId().toString());
            drive.put(VdsProperties.PropagateErrors, disk.getPropagateErrors().toString().toLowerCase());
            vmInfoBuildUtils.handleIoTune(vmDevice, vmInfoBuildUtils.loadStorageQos(diskImage));
            if (vmDevice.getSpecParams() != null) {
                drive.put(VdsProperties.SpecParams, vmDevice.getSpecParams());
            }
            break;
        case LUN:
            LunDisk lunDisk = (LunDisk) disk;
            // If SCSI pass-through is enabled (VirtIO-SCSI/DirectLUN disk and SGIO is defined),
            // set device type as 'lun' (instead of 'disk') and set the specified SGIO
            boolean isVirtioScsi = getParameters().getDiskInterface() == DiskInterface.VirtIO_SCSI;
            boolean isScsiPassthrough = getParameters().getDisk().isScsiPassthrough();
            if (isVirtioScsi) {
                if (isScsiPassthrough) {
                    drive.put(VdsProperties.Device, VmDeviceType.LUN.getName());
                    drive.put(VdsProperties.Sgio, getParameters().getDisk().getSgio().toString().toLowerCase());
                } else {
                    drive.put(VdsProperties.Device, VmDeviceType.DISK.getName());
                }
            } else {
                drive.put(VdsProperties.Device, VmDeviceType.DISK.getName());
            }
            drive.put(VdsProperties.Guid, lunDisk.getLun().getLUNId());
            drive.put(VdsProperties.Format, VolumeFormat.RAW.toString().toLowerCase());
            drive.put(VdsProperties.PropagateErrors, PropagateErrors.Off.toString().toLowerCase());
            break;
        case CINDER:
            CinderDisk cinderDisk = (CinderDisk) disk;
            vmInfoBuildUtils.buildCinderDisk(cinderDisk, drive);
            drive.put(VdsProperties.Device, VmDeviceType.DISK.getName());
            break;
    }
    return drive;
}
Also used : HashMap(java.util.HashMap) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 65 with DiskVmElement

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

the class VmValidatorTest method canDisableVirtioScsiSuccess.

@Test
public void canDisableVirtioScsiSuccess() {
    Disk disk = new DiskImage();
    DiskVmElement dve = new DiskVmElement(disk.getId(), vm.getId());
    dve.setDiskInterface(DiskInterface.VirtIO);
    disk.setDiskVmElements(Collections.singletonList(dve));
    assertThat(validator.canDisableVirtioScsi(Collections.singletonList(disk)), isValid());
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

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