Search in sources :

Example 21 with VmDevice

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

the class VmInfoBuilderImpl method buildVmUsbControllers.

private void buildVmUsbControllers() {
    List<VmDevice> vmDevices = vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.CONTROLLER, VmDeviceType.USB);
    for (VmDevice vmDevice : vmDevices) {
        Map<String, Object> struct = new HashMap<>();
        struct.put(VdsProperties.Type, vmDevice.getType().getValue());
        struct.put(VdsProperties.Device, vmDevice.getDevice());
        vmInfoBuildUtils.setVdsPropertiesFromSpecParams(vmDevice.getSpecParams(), struct);
        struct.put(VdsProperties.SpecParams, new HashMap<String, Object>());
        struct.put(VdsProperties.DeviceId, String.valueOf(vmDevice.getId().getDeviceId()));
        vmInfoBuildUtils.addAddress(vmDevice, struct);
        String model = (String) struct.get(VdsProperties.Model);
        // This is a workaround until libvirt will fix the requirement to order these controllers
        if (model != null && vmInfoBuildUtils.isFirstMasterController(model)) {
            devices.add(0, struct);
        } else {
            devices.add(struct);
        }
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap)

Example 22 with VmDevice

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

the class VmInfoBuilderImpl method buildVmDevicesFromDb.

/**
 * @param deviceComparator allows to sort devices in resulting {@link #devices} list and thus
 *                         also in libvirt domain xml. {@code null} indicates no special
 *                         ordering.
 */
private void buildVmDevicesFromDb(VmDeviceGeneralType generalType, boolean addAddress, Map<String, Object> extraSpecParams, Comparator<VmDevice> deviceComparator) {
    final List<VmDevice> vmDevices = vmDeviceDao.getVmDeviceByVmIdAndType(vm.getId(), generalType);
    List<VmDevice> sortedDevices = deviceComparator == null ? vmDevices : vmDevices.stream().sorted(deviceComparator).collect(Collectors.toList());
    for (VmDevice vmDevice : sortedDevices) {
        Map<String, Object> struct = new HashMap<>();
        struct.put(VdsProperties.Type, vmDevice.getType().getValue());
        struct.put(VdsProperties.Device, vmDevice.getDevice());
        Map<String, Object> specParams = vmDevice.getSpecParams();
        if (extraSpecParams != null) {
            specParams.putAll(extraSpecParams);
        }
        struct.put(VdsProperties.SpecParams, specParams);
        struct.put(VdsProperties.DeviceId, String.valueOf(vmDevice.getId().getDeviceId()));
        if (addAddress) {
            vmInfoBuildUtils.addAddress(vmDevice, struct);
        }
        devices.add(struct);
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap)

Example 23 with VmDevice

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

the class VmInfoBuilderImpl method buildVmVirtioScsi.

@Override
public void buildVmVirtioScsi() {
    List<VmDevice> vmDevices = vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.CONTROLLER, VmDeviceType.VIRTIOSCSI);
    Map<DiskInterface, Integer> controllerIndexMap = ArchStrategyFactory.getStrategy(vm.getClusterArch()).run(new GetControllerIndices()).returnValue();
    int virtioScsiIndex = controllerIndexMap.get(DiskInterface.VirtIO_SCSI);
    for (VmDevice vmDevice : vmDevices) {
        Map<String, Object> struct = new HashMap<>();
        struct.put(VdsProperties.Type, VmDeviceGeneralType.CONTROLLER.getValue());
        struct.put(VdsProperties.Device, VdsProperties.Scsi);
        struct.put(VdsProperties.Model, VdsProperties.VirtioScsi);
        struct.put(VdsProperties.Index, Integer.toString(virtioScsiIndex));
        vmInfoBuildUtils.addAddress(vmDevice, struct);
        virtioScsiIndex++;
        addDevice(struct, vmDevice, null);
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) GetControllerIndices(org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices)

Example 24 with VmDevice

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

the class VmInfoBuilderImpl method buildVmRngDevice.

@Override
public void buildVmRngDevice() {
    List<VmDevice> vmDevices = vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vm.getId(), VmDeviceGeneralType.RNG, VmDeviceType.VIRTIO);
    for (VmDevice vmDevice : vmDevices) {
        Map<String, Object> struct = new HashMap<>();
        struct.put(VdsProperties.Type, VmDeviceGeneralType.RNG.getValue());
        struct.put(VdsProperties.Device, VmDeviceType.VIRTIO.getName());
        struct.put(VdsProperties.Model, VdsProperties.Virtio);
        struct.put(VdsProperties.SpecParams, vmDevice.getSpecParams());
        addDevice(struct, vmDevice, null);
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap)

Example 25 with VmDevice

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

the class HotPlugOrUnplugNicVDSCommand method generateDomainXml.

private String generateDomainXml() {
    VmNic nic = getParameters().getNic();
    VmDevice vmDevice = getParameters().getVmDevice();
    LibvirtVmXmlBuilder builder = new LibvirtVmXmlBuilder(getParameters().getVm(), getVds().getId(), nic, vmDevice, vmInfoBuildUtils, nic.isPassthrough() ? Collections.singletonMap(nic.getId(), vmDevice.getHostDevice()) : Collections.emptyMap());
    String libvirtXml = builder.buildHotplugNic();
    String prettyLibvirtXml = XmlUtils.prettify(libvirtXml);
    if (prettyLibvirtXml != null) {
        log.info("NIC hot-set: {}", prettyLibvirtXml);
    }
    return libvirtXml;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) LibvirtVmXmlBuilder(org.ovirt.engine.core.vdsbroker.builder.vminfo.LibvirtVmXmlBuilder)

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