Search in sources :

Example 81 with DiskImage

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

the class BackendStorageDomainDisksResourceTest method getEntity.

@Override
protected org.ovirt.engine.core.common.businessentities.storage.Disk getEntity(int index) {
    DiskImage entity = new DiskImage();
    entity.setId(GUIDS[index]);
    entity.setVolumeFormat(VolumeFormat.RAW);
    entity.setImageStatus(ImageStatus.OK);
    entity.setVolumeType(VolumeType.Sparse);
    entity.setShareable(false);
    entity.setPropagateErrors(PropagateErrors.On);
    return setUpStatisticalEntityExpectations(entity);
}
Also used : DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 82 with DiskImage

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

the class GetImageInfoVDSCommand method executeIrsBrokerCommand.

@Override
protected void executeIrsBrokerCommand() {
    GetVolumeInfoVDSCommandParameters p = new GetVolumeInfoVDSCommandParameters(getCurrentIrsProxy().getCurrentVdsId(), getParameters().getStoragePoolId(), getParameters().getStorageDomainId(), getParameters().getImageGroupId(), getParameters().getImageId());
    DiskImage di = (DiskImage) resourceManager.runVdsCommand(VDSCommandType.GetVolumeInfo, p).getReturnValue();
    // if couldn't parse image then succeeded should be false
    getVDSReturnValue().setSucceeded(di != null);
    if (!getVDSReturnValue().getSucceeded()) {
        log.error("Failed to get the volume information, marking as FAILED");
    }
    setReturnValue(di);
}
Also used : GetVolumeInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetVolumeInfoVDSCommandParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 83 with DiskImage

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

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

the class VdsBrokerObjectsBuilder method buildVmStaticDataFromExternalProvider.

private static VmStatic buildVmStaticDataFromExternalProvider(Map<String, Object> struct) {
    if (!struct.containsKey(VdsProperties.vm_guid) || !struct.containsKey(VdsProperties.vm_name) || !struct.containsKey(VdsProperties.mem_size_mb) || !struct.containsKey(VdsProperties.num_of_cpus)) {
        return null;
    }
    VmStatic vmStatic = new VmStatic();
    vmStatic.setId(Guid.createGuidFromString((String) struct.get(VdsProperties.vm_guid)));
    vmStatic.setName((String) struct.get(VdsProperties.vm_name));
    vmStatic.setMemSizeMb(parseIntVdsProperty(struct.get(VdsProperties.mem_size_mb)));
    vmStatic.setNumOfSockets(parseIntVdsProperty(struct.get(VdsProperties.num_of_cpus)));
    vmStatic.setCustomCpuName((String) struct.get(VdsProperties.cpu_model));
    vmStatic.setCustomEmulatedMachine((String) struct.get(VdsProperties.emulatedMachine));
    addGraphicsDeviceFromExternalProvider(vmStatic, struct);
    if (struct.containsKey(VdsProperties.vm_disks)) {
        for (Object disk : (Object[]) struct.get(VdsProperties.vm_disks)) {
            Map<String, Object> diskMap = (Map<String, Object>) disk;
            if (VdsProperties.Disk.equals(diskMap.get(VdsProperties.type))) {
                DiskImage image = buildDiskImageFromExternalProvider(diskMap, vmStatic.getId());
                vmStatic.getImages().add(image);
            }
        }
    }
    if (struct.containsKey(VdsProperties.NETWORKS)) {
        int idx = 0;
        for (Object networkMap : (Object[]) struct.get(VdsProperties.NETWORKS)) {
            VmNetworkInterface nic = buildNetworkInterfaceFromExternalProvider((Map<String, Object>) networkMap);
            nic.setName(String.format("nic%d", ++idx));
            nic.setVmName(vmStatic.getName());
            nic.setVmId(vmStatic.getId());
            vmStatic.getInterfaces().add(nic);
        }
    }
    return vmStatic;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Map(java.util.Map) HashMap(java.util.HashMap) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 85 with DiskImage

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

Aggregations

DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)635 Guid (org.ovirt.engine.core.compat.Guid)212 ArrayList (java.util.ArrayList)167 Test (org.junit.Test)132 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)80 VM (org.ovirt.engine.core.common.businessentities.VM)77 HashMap (java.util.HashMap)64 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)62 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)62 List (java.util.List)56 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)48 Map (java.util.Map)39 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)38 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)35 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)34 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)31 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)31 EngineException (org.ovirt.engine.core.common.errors.EngineException)29 ActionType (org.ovirt.engine.core.common.action.ActionType)22 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)22