Search in sources :

Example 6 with DiskVmElement

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

the class VdsBrokerObjectsBuilder method buildDiskImagesFromDevices.

/**
 * Convert the devices map and make a list of {@linkplain DiskImage}
 * Mainly used to import the Hosted Engine Vm disks.
 *
 * @return A List of Disk Images {@linkplain DiskImage}
 */
public static ArrayList<DiskImage> buildDiskImagesFromDevices(Map<String, Object> vmStruct, Guid vmId) {
    ArrayList<DiskImage> diskImages = new ArrayList<>();
    Object[] devices = (Object[]) vmStruct.get("devices");
    if (devices != null) {
        for (Object device : devices) {
            Map<String, Object> deviceMap = (Map<String, Object>) device;
            if (VdsProperties.Disk.equals(deviceMap.get(VdsProperties.Device))) {
                DiskImage image = new DiskImage();
                image.setDiskAlias((String) deviceMap.get(VdsProperties.Alias));
                Long size = assignLongValue(deviceMap, VdsProperties.disk_apparent_size);
                image.setSize(size != null ? size : 0);
                Double actualSize = assignDoubleValue(deviceMap, VdsProperties.disk_true_size);
                image.setActualSize(actualSize != null ? actualSize : 0);
                image.setVolumeFormat(VolumeFormat.valueOf(((String) deviceMap.get(VdsProperties.Format)).toUpperCase()));
                image.setShareable(false);
                String id = assignStringValue(deviceMap, VdsProperties.DeviceId);
                if (id == null) {
                    id = assignStringValue(deviceMap, VdsProperties.ImageId);
                }
                image.setId(Guid.createGuidFromString(id));
                image.setImageId(Guid.createGuidFromString((String) deviceMap.get(VdsProperties.VolumeId)));
                Guid domainId = Guid.createGuidFromString((String) deviceMap.get(VdsProperties.DomainId));
                List<Guid> domainIds = Collections.singletonList(domainId);
                image.setStorageIds(new ArrayList<>(domainIds));
                // TODO not sure how to extract that info
                image.setVolumeType(VolumeType.Preallocated);
                DiskVmElement dve = new DiskVmElement(image.getId(), vmId);
                image.setDiskVmElements(Collections.singletonList(dve));
                switch((String) deviceMap.get("iface")) {
                    case "virtio":
                        dve.setDiskInterface(DiskInterface.VirtIO);
                        break;
                    case "iscsi":
                    case "scsi":
                        dve.setDiskInterface(DiskInterface.VirtIO_SCSI);
                        break;
                    case "ide":
                        dve.setDiskInterface(DiskInterface.IDE);
                        break;
                }
                diskImages.add(image);
            }
        }
    }
    return diskImages;
}
Also used : ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with DiskVmElement

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

the class VdsBrokerObjectsBuilder method buildDiskImageFromExternalProvider.

private static DiskImage buildDiskImageFromExternalProvider(Map<String, Object> map, Guid vmId) {
    DiskImage image = new DiskImage();
    image.setDiskAlias((String) map.get(VdsProperties.Alias));
    image.setSize(Long.parseLong((String) map.get(VdsProperties.DISK_VIRTUAL_SIZE)));
    image.setActualSizeInBytes(Long.parseLong((String) map.get(VdsProperties.DISK_ALLOCATION)));
    image.setId(Guid.newGuid());
    if (map.containsKey(VdsProperties.Format)) {
        image.setVolumeFormat(VolumeFormat.valueOf(((String) map.get(VdsProperties.Format)).toUpperCase()));
    }
    DiskVmElement dve = buildDiskVmElementWithDiskInterfaceFromExternalProvider(map, image, vmId);
    image.setDiskVmElements(Collections.singletonList(dve));
    return image;
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 8 with DiskVmElement

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

the class AttachDiskModel method store.

@Override
public void store(IFrontendActionAsyncCallback callback) {
    if (getProgress() != null || !validate()) {
        return;
    }
    ArrayList<ActionType> actionTypes = new ArrayList<>();
    ArrayList<ActionParametersBase> paramerterList = new ArrayList<>();
    ArrayList<IFrontendActionAsyncCallback> callbacks = new ArrayList<>();
    IFrontendActionAsyncCallback onFinishCallback = callback != null ? callback : result -> {
        NewDiskModel diskModel = (NewDiskModel) result.getState();
        diskModel.stopProgress();
        diskModel.cancel();
    };
    List<EntityModel<DiskModel>> disksToAttach = getSelectedDisks();
    for (int i = 0; i < disksToAttach.size(); i++) {
        DiskModel disk = disksToAttach.get(i).getEntity();
        /*
            IDE disks can be activated only when the VM is down.
            Other disks can be hot plugged.
             */
        boolean activate = false;
        if (getIsPlugged().getEntity()) {
            activate = disk.getDiskInterface().getSelectedItem() == DiskInterface.IDE ? getVm().getStatus() == VMStatus.Down : true;
        }
        DiskVmElement dve = new DiskVmElement(disk.getDisk().getId(), getVm().getId());
        dve.setBoot(disk.getIsBootable().getEntity());
        dve.setDiskInterface(disk.getDiskInterface().getSelectedItem());
        dve.setReadOnly(disk.isReadOnly());
        AttachDetachVmDiskParameters parameters = new AttachDetachVmDiskParameters(dve, activate);
        actionTypes.add(ActionType.AttachDiskToVm);
        paramerterList.add(parameters);
        callbacks.add(i == disksToAttach.size() - 1 ? onFinishCallback : null);
    }
    startProgress();
    Frontend.getInstance().runMultipleActions(actionTypes, paramerterList, callbacks, null, this);
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) AttachDetachVmDiskParameters(org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)

Example 9 with DiskVmElement

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

the class NewDiskModel method initialize.

@Override
public void initialize(List<DiskModel> currentDisks) {
    super.initialize(currentDisks);
    setDiskVmElement(new DiskVmElement(new VmDeviceId(null, getIsFloating() ? null : getVm().getId())));
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 10 with DiskVmElement

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

the class SnapshotsManager method populateDisksWithVmData.

private void populateDisksWithVmData(List<? extends Disk> disks, Guid vmId) {
    for (Disk disk : disks) {
        DiskVmElement dve = diskVmElementDao.get(new VmDeviceId(disk.getId(), vmId));
        disk.setDiskVmElements(Collections.singletonList(dve));
    }
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) 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