Search in sources :

Example 6 with VmInterfaceType

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

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

the class OvfReader method setDeviceByResource.

private void setDeviceByResource(XmlNode node, VmDevice vmDevice) {
    String resourceType = selectSingleNode(node, VMD_RESOURCE_TYPE, _xmlNS).innerText;
    XmlNode resourceSubTypeNode = selectSingleNode(node, VMD_SUB_RESOURCE_TYPE, _xmlNS);
    if (resourceSubTypeNode == null) {
        // we need special handling for Monitor to define it as vnc or spice
        if (OvfHardware.Monitor.equals(adjustHardwareResourceType(resourceType))) {
            // get number of monitors from VirtualQuantity in OVF
            if (selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS).innerText)) {
                int virtualQuantity = Integer.parseInt(selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS).innerText);
                if (virtualQuantity > 1) {
                    vmDevice.setDevice(VmDeviceType.QXL.getName());
                } else {
                    // get first supported display device
                    List<Pair<GraphicsType, DisplayType>> supportedGraphicsAndDisplays = osRepository.getGraphicsAndDisplays(vmBase.getOsId(), new Version(getVersion()));
                    if (!supportedGraphicsAndDisplays.isEmpty()) {
                        DisplayType firstDisplayType = supportedGraphicsAndDisplays.get(0).getSecond();
                        vmDevice.setDevice(firstDisplayType.getDefaultVmDeviceType().getName());
                    } else {
                        vmDevice.setDevice(VmDeviceType.QXL.getName());
                    }
                }
            } else {
                // default to spice if quantity not found
                vmDevice.setDevice(VmDeviceType.QXL.getName());
            }
        } else {
            vmDevice.setDevice(VmDeviceType.getoVirtDevice(Integer.parseInt(resourceType)).getName());
        }
    } else if (OvfHardware.Network.equals(resourceType)) {
        // handle interfaces with different sub types : we have 0-5 as the VmInterfaceType enum
        Integer nicTypeValue = getVmInterfaceType(resourceSubTypeNode);
        VmInterfaceType nicType = nicTypeValue != null ? VmInterfaceType.forValue(nicTypeValue) : null;
        if (nicType != null) {
            if (nicType == VmInterfaceType.pciPassthrough) {
                vmDevice.setDevice(VmDeviceType.HOST_DEVICE.getName());
            } else {
                vmDevice.setDevice(VmDeviceType.BRIDGE.getName());
            }
        } else {
            vmDevice.setDevice(VmDeviceType.getoVirtDevice(Integer.parseInt(resourceType)).getName());
        }
    }
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) Version(org.ovirt.engine.core.compat.Version) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 8 with VmInterfaceType

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

the class VmNicValidator method isCompatibleWithOs.

/**
 * @return An error if the network interface type is not compatible with the selected operating
 *         system.
 */
public ValidationResult isCompatibleWithOs() {
    List<String> networkDevices = Injector.get(OsRepository.class).getNetworkDevices(osId, version);
    List<VmInterfaceType> interfaceTypes = new ArrayList<>();
    for (String networkDevice : networkDevices) {
        interfaceTypes.add(VmInterfaceType.valueOf(networkDevice));
    }
    return !interfaceTypes.contains(VmInterfaceType.forValue(nic.getType())) ? new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_VM_INTERFACE_TYPE_IS_NOT_SUPPORTED_BY_OS) : ValidationResult.VALID;
}
Also used : ArrayList(java.util.ArrayList) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Aggregations

VmInterfaceType (org.ovirt.engine.core.common.businessentities.network.VmInterfaceType)8 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 Map (java.util.Map)2 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)2 List (java.util.List)1 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)1 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)1 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)1 Network (org.ovirt.engine.core.common.businessentities.network.Network)1 NetworkFilter (org.ovirt.engine.core.common.businessentities.network.NetworkFilter)1 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)1 VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)1 OsRepository (org.ovirt.engine.core.common.osinfo.OsRepository)1 OsQueryParameters (org.ovirt.engine.core.common.queries.OsQueryParameters)1 Pair (org.ovirt.engine.core.common.utils.Pair)1 Version (org.ovirt.engine.core.compat.Version)1 XmlNode (org.ovirt.engine.core.utils.ovf.xml.XmlNode)1