Search in sources :

Example 96 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice 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 97 with VmDevice

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

the class VmInfoBuilderImpl method buildUnmanagedDevices.

@Override
public void buildUnmanagedDevices(String hibernationVolHandle) {
    @SuppressWarnings("unchecked") Map<String, String> customMap = (Map<String, String>) createInfo.getOrDefault(VdsProperties.Custom, new HashMap<>());
    List<VmDevice> vmDevices = vmDeviceDao.getUnmanagedDevicesByVmId(vm.getId());
    if (!vmDevices.isEmpty()) {
        StringBuilder id = new StringBuilder();
        for (VmDevice vmDevice : vmDevices) {
            Map<String, Object> struct = new HashMap<>();
            id.append(VdsProperties.Device);
            id.append("_");
            id.append(vmDevice.getDeviceId());
            if (VmDeviceCommonUtils.isMemory(vmDevice)) {
                handleMemoryDevice(vmDevice, hibernationVolHandle, devices);
                continue;
            }
            if (VmDeviceCommonUtils.isInWhiteList(vmDevice.getType(), vmDevice.getDevice())) {
                struct.put(VdsProperties.Type, vmDevice.getType().getValue());
                struct.put(VdsProperties.Device, vmDevice.getDevice());
                vmInfoBuildUtils.addAddress(vmDevice, struct);
                struct.put(VdsProperties.SpecParams, vmDevice.getSpecParams());
                struct.put(VdsProperties.DeviceId, String.valueOf(vmDevice.getId().getDeviceId()));
                devices.add(struct);
            } else {
                customMap.put(id.toString(), vmDevice.toString());
            }
        }
    }
    createInfo.put(VdsProperties.Custom, customMap);
    createInfo.put(DEVICES, devices);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 98 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice 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 99 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice 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 100 with VmDevice

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

the class VmInfoBuilderImpl method buildSmartcardDevice.

private void buildSmartcardDevice() {
    List<VmDevice> vmDevices = vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.SMARTCARD, VmDeviceType.SMARTCARD);
    for (VmDevice vmDevice : vmDevices) {
        Map<String, Object> struct = new HashMap<>();
        struct.put(VdsProperties.Type, vmDevice.getType().getValue());
        struct.put(VdsProperties.Device, vmDevice.getDevice());
        addDevice(struct, vmDevice, null);
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap)

Aggregations

VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)170 HashMap (java.util.HashMap)59 Guid (org.ovirt.engine.core.compat.Guid)53 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)48 ArrayList (java.util.ArrayList)34 Map (java.util.Map)33 VM (org.ovirt.engine.core.common.businessentities.VM)29 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)28 List (java.util.List)26 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)21 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)21 VmDeviceType (org.ovirt.engine.core.common.utils.VmDeviceType)20 Collections (java.util.Collections)19 Test (org.junit.Test)19 Collectors (java.util.stream.Collectors)18 Arrays (java.util.Arrays)17 Optional (java.util.Optional)17 StringUtils (org.apache.commons.lang.StringUtils)17 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)17 Inject (javax.inject.Inject)16