Search in sources :

Example 51 with VmDeviceId

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

the class VmInfoBuildUtils method createCloudInitPayloadDevice.

public VmDevice createCloudInitPayloadDevice(Map<String, byte[]> cloudInitContent, VM vm) {
    VmPayload vmPayload = new VmPayload();
    vmPayload.setDeviceType(VmDeviceType.CDROM);
    vmPayload.setVolumeId(CLOUD_INIT_VOL_ID);
    for (Entry<String, byte[]> entry : cloudInitContent.entrySet()) {
        vmPayload.getFiles().put(entry.getKey(), new String(BASE_64.encode(entry.getValue()), StandardCharsets.UTF_8));
    }
    return new VmDevice(new VmDeviceId(Guid.newGuid(), vm.getId()), VmDeviceGeneralType.DISK, VmDeviceType.CDROM.getName(), "", vmPayload.getSpecParams(), true, true, true, "", null, null, null);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 52 with VmDeviceId

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

the class VmInfoBuilderImpl method buildVmCD.

@Override
public void buildVmCD(VmPayload vmPayload) {
    boolean hasPayload = vmPayload != null && vmPayload.getDeviceType() == VmDeviceType.CDROM;
    // check if we have payload CD
    if (hasPayload) {
        Map<String, Object> struct = vmInfoBuildUtils.buildCdDetails(vmPayload, vm);
        addDevice(struct, vmPayload, "");
    }
    // check first if CD was given as a RunOnce parameter
    if (vm.isRunOnce() && !StringUtils.isEmpty(vm.getCdPath())) {
        VmDevice vmDevice = new VmDevice(new VmDeviceId(Guid.newGuid(), vm.getId()), VmDeviceGeneralType.DISK, VmDeviceType.CDROM.getName(), "", null, true, true, true, "", null, null, null);
        Map<String, Object> struct = vmInfoBuildUtils.buildCdDetails(vmDevice, vm);
        addDevice(struct, vmDevice, vm.getCdPath());
    } else {
        // get vm device for this CD from DB
        List<VmDevice> vmDevices = vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.DISK, VmDeviceType.CDROM);
        for (VmDevice vmDevice : vmDevices) {
            // skip unmanaged devices (handled separately)
            if (!vmDevice.isManaged()) {
                continue;
            }
            // the method, so no need to add the device again,
            if (VmPayload.isPayload(vmDevice.getSpecParams())) {
                continue;
            }
            String cdPath = vm.getCdPath();
            Map<String, Object> struct = vmInfoBuildUtils.buildCdDetails(vmDevice, vm);
            vmInfoBuildUtils.addAddress(vmDevice, struct);
            addDevice(struct, vmDevice, cdPath == null ? "" : cdPath);
        }
    }
    numOfReservedScsiIndexes++;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 53 with VmDeviceId

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

the class VmInfoBuilderImpl method buildVmNetworkInterfaces.

@Override
public void buildVmNetworkInterfaces(Map<Guid, String> passthroughVnicToVfMap) {
    Map<VmDeviceId, VmDevice> devicesByDeviceId = Entities.businessEntitiesById(vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.INTERFACE, VmDeviceType.BRIDGE));
    devicesByDeviceId.putAll(Entities.businessEntitiesById(vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.INTERFACE, VmDeviceType.HOST_DEVICE)));
    for (VmNic vmInterface : vm.getInterfaces()) {
        // get vm device for this nic from DB
        VmDevice vmDevice = devicesByDeviceId.get(new VmDeviceId(vmInterface.getId(), vmInterface.getVmId()));
        if (vmDevice != null && vmDevice.isManaged() && vmDevice.isPlugged()) {
            Map<String, Object> struct = new HashMap<>();
            VmInterfaceType ifaceType = VmInterfaceType.rtl8139;
            if (vmInterface.getType() != null) {
                ifaceType = VmInterfaceType.forValue(vmInterface.getType());
            }
            if (vmInterface.isPassthrough()) {
                String vfDeviceName = passthroughVnicToVfMap.get(vmInterface.getId());
                vmInfoBuildUtils.addNetworkVirtualFunctionProperties(struct, vmInterface, vmDevice, vfDeviceName, vm);
            } else {
                addNetworkInterfaceProperties(struct, vmInterface, vmDevice, vmInfoBuildUtils.evaluateInterfaceType(ifaceType, vm.getHasAgent()));
            }
            devices.add(struct);
            bootableDevices.add(vmDevice);
        }
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 54 with VmDeviceId

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

the class OvfReader method addDefaultGraphicsDevice.

private void addDefaultGraphicsDevice() {
    VmDevice device = VmDeviceCommonUtils.findVmDeviceByGeneralType(vmBase.getManagedDeviceMap(), VmDeviceGeneralType.GRAPHICS);
    if (device != null) {
        return;
    }
    List<Pair<GraphicsType, DisplayType>> graphicsAndDisplays = osRepository.getGraphicsAndDisplays(vmBase.getOsId(), new Version(getVersion()));
    GraphicsType graphicsType = vmBase.getDefaultDisplayType() == DisplayType.cirrus ? GraphicsType.VNC : GraphicsType.SPICE;
    GraphicsType supportedGraphicsType = null;
    for (Pair<GraphicsType, DisplayType> pair : graphicsAndDisplays) {
        if (pair.getSecond() == vmBase.getDefaultDisplayType()) {
            if (pair.getFirst() == graphicsType) {
                supportedGraphicsType = graphicsType;
                break;
            }
            if (supportedGraphicsType == null) {
                supportedGraphicsType = pair.getFirst();
            }
        }
    }
    if (supportedGraphicsType != null) {
        device = new GraphicsDevice(supportedGraphicsType.getCorrespondingDeviceType());
        device.setId(new VmDeviceId(Guid.newGuid(), vmBase.getId()));
        addManagedVmDevice(device);
    } else {
        log.warn("Cannot find any graphics type for display type {} supported by OS {} in compatibility version {}", vmBase.getDefaultDisplayType().name(), osRepository.getOsName(vmBase.getOsId()), getVersion());
    }
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) Version(org.ovirt.engine.core.compat.Version) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 55 with VmDeviceId

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

the class VdsBrokerObjectsBuilder method buildConsoleDevice.

public static VmDevice buildConsoleDevice(Map<String, Object> vmStruct, Guid vmId) {
    Object[] devices = (Object[]) vmStruct.get(VdsProperties.Devices);
    if (devices != null) {
        for (Object device : devices) {
            Map<String, Object> vdsmDevice = (Map<String, Object>) device;
            String deviceName = (String) vdsmDevice.get(VdsProperties.Device);
            if (VmDeviceType.CONSOLE.getName().equals(deviceName)) {
                String typeName = (String) vdsmDevice.get(VdsProperties.Type);
                String alias = StringUtils.defaultString((String) vdsmDevice.get(VdsProperties.Alias));
                Guid newDeviceId = Guid.createGuidFromString((String) vdsmDevice.get(VdsProperties.DeviceId));
                VmDeviceId id = new VmDeviceId(newDeviceId, vmId);
                VmDevice consoleDevice = new VmDevice(id, VmDeviceGeneralType.forValue(typeName), deviceName, "", new HashMap<>(), false, true, false, alias, null, null, null);
                return consoleDevice;
            }
        }
    }
    return null;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Guid(org.ovirt.engine.core.compat.Guid) Map(java.util.Map) HashMap(java.util.HashMap) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Aggregations

VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)75 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)40 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)21 Guid (org.ovirt.engine.core.compat.Guid)19 HashMap (java.util.HashMap)13 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)12 Test (org.junit.Test)10 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)9 ArrayList (java.util.ArrayList)7 Map (java.util.Map)5 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)5 VM (org.ovirt.engine.core.common.businessentities.VM)5 VmPayload (org.ovirt.engine.core.common.businessentities.VmPayload)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)4 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)3 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)3