Search in sources :

Example 1 with VmInterfaceType

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

the class VdsBrokerObjectsBuilder method buildVmNetworkInterfacesFromDevices.

/**
 * Convert the devices map and make a list of {@linkplain VmNetworkInterface}
 * Mainly used to import the Hosted Engine Vm disks.
 *
 * @return A List of VM network interfaces {@linkplain VmNetworkInterface}
 */
public static ArrayList<VmNetworkInterface> buildVmNetworkInterfacesFromDevices(Map<String, Object> vmStruct) {
    ArrayList<VmNetworkInterface> nics = new ArrayList<>();
    Object[] devices = (Object[]) vmStruct.get(VdsProperties.Devices);
    if (devices != null) {
        for (Object device : devices) {
            Map<String, Object> deviceMap = (Map<String, Object>) device;
            if (VdsProperties.VM_INTERFACE_DEVICE_TYPE.equals(deviceMap.get(VdsProperties.Type))) {
                VmNetworkInterface nic = new VmNetworkInterface();
                nic.setId(Guid.createGuidFromString((String) deviceMap.get(VdsProperties.DeviceId)));
                nic.setMacAddress((String) deviceMap.get(VdsProperties.MAC_ADDR));
                nic.setName((String) deviceMap.get(VdsProperties.Name));
                // FIXME we can't deduce the network profile by the network name. its many to many.
                nic.setNetworkName((String) deviceMap.get(VdsProperties.NETWORK));
                String nicModel = (String) deviceMap.get(VdsProperties.NIC_TYPE);
                if ("virtio".equals(nicModel)) {
                    nicModel = "pv";
                }
                nic.setType(VmInterfaceType.valueOf(nicModel).getValue());
                if (deviceMap.containsKey(VdsProperties.Model)) {
                    String model = (String) deviceMap.get(VdsProperties.Model);
                    for (VmInterfaceType type : VmInterfaceType.values()) {
                        if (model.equals(type.getInternalName())) {
                            nic.setType(type.getValue());
                            break;
                        }
                    }
                }
                nics.add(nic);
            }
        }
    }
    return nics;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) ArrayList(java.util.ArrayList) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with VmInterfaceType

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

the class VdsBrokerObjectsBuilder method buildNetworkInterfaceFromExternalProvider.

private static VmNetworkInterface buildNetworkInterfaceFromExternalProvider(Map<String, Object> map) {
    VmNetworkInterface nic = new VmNetworkInterface();
    nic.setMacAddress((String) map.get(VdsProperties.MAC_ADDR));
    nic.setRemoteNetworkName((String) map.get(VdsProperties.BRIDGE));
    nic.setType(VmInterfaceType.pv.getValue());
    if (map.containsKey(VdsProperties.Model)) {
        String model = (String) map.get(VdsProperties.Model);
        for (VmInterfaceType type : VmInterfaceType.values()) {
            if (model.equals(type.getInternalName())) {
                nic.setType(type.getValue());
                break;
            }
        }
    }
    return nic;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType)

Example 3 with VmInterfaceType

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

the class AsyncDataProvider method getNicTypeList.

public void getNicTypeList(final int osId, Version version, AsyncQuery<List<VmInterfaceType>> asyncQuery) {
    asyncQuery.converterCallback = returnValue -> {
        ArrayList<String> nics = (ArrayList<String>) returnValue;
        List<VmInterfaceType> interfaceTypes = new ArrayList<>();
        for (String nic : nics) {
            try {
                interfaceTypes.add(VmInterfaceType.valueOf(nic));
            } catch (IllegalArgumentException e) {
            // ignore if we can't find the enum value.
            }
        }
        return interfaceTypes;
    };
    Frontend.getInstance().runQuery(QueryType.OsRepository, new OsQueryParameters(OsRepositoryVerb.GetNetworkDevices, osId, version), asyncQuery);
}
Also used : OsQueryParameters(org.ovirt.engine.core.common.queries.OsQueryParameters) ArrayList(java.util.ArrayList) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType)

Example 4 with VmInterfaceType

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

the class BaseInterfaceCreatingManager method updateVnicType.

private void updateVnicType(VnicProfileView profile, VmNetworkInterface existingVnic, VmNetworkInterface editedVnic) {
    boolean shouldBePciPassthroughType = profile != null && profile.isPassthrough() && supportedInterfaceTypes != null && supportedInterfaceTypes.contains(VmInterfaceType.pciPassthrough);
    if (existingVnic == null) {
        if (shouldBePciPassthroughType) {
            editedVnic.setType(VmInterfaceType.pciPassthrough.getValue());
        } else {
            editedVnic.setType(defaultType == null ? null : defaultType.getValue());
        }
    } else {
        VmInterfaceType existingInterfaceType = VmInterfaceType.forValue(existingVnic.getType());
        boolean shouldRestoreToDefault = profile != null && !profile.isPassthrough() && VmInterfaceType.pciPassthrough.equals(existingInterfaceType);
        if (shouldBePciPassthroughType) {
            existingVnic.setType(VmInterfaceType.pciPassthrough.getValue());
        } else if (shouldRestoreToDefault || supportedInterfaceTypes == null || !supportedInterfaceTypes.contains(existingInterfaceType)) {
            existingVnic.setType(defaultType == null ? null : defaultType.getValue());
        }
    }
}
Also used : VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType)

Example 5 with VmInterfaceType

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

the class LibvirtVmXmlBuilder method writeInterface.

private void writeInterface(VmDevice device, VmNic nic) {
    // <interface type="bridge">
    // <mac address="aa:bb:dd:dd:aa:bb"/>
    // <model type="virtio"/>
    // <source bridge="engine"/>
    // [<driver name="vhost/qemu" queues="int"/>]
    // [<filterref filter='filter name'>
    // [<parameter name='parameter name' value='parameter value'>]
    // </filterref>]
    // [<tune><sndbuf>0</sndbuf></tune>]
    // [<link state='up|down'/>]
    // [<bandwidth>
    // [<inbound average="int" [burst="int"]  [peak="int"]/>]
    // [<outbound average="int" [burst="int"]  [peak="int"]/>]
    // </bandwidth>]
    // </interface>
    // 
    // -- or -- a slightly different SR-IOV network interface
    // <interface type='hostdev' managed='no'>
    // <driver name='vfio'/>
    // <source>
    // <address type='pci' domain='0x0000' bus='0x00' slot='0x07'
    // function='0x0'/>
    // </source>
    // <mac address='52:54:00:6d:90:02'/>
    // <vlan>
    // <tag id=100/>
    // </vlan>
    // <address type='pci' domain='0x0000' bus='0x00' slot='0x07'
    // function='0x0'/>
    // <boot order='1'/>
    // </interface>
    writer.writeStartElement("interface");
    VnicProfile vnicProfile = vmInfoBuildUtils.getVnicProfile(nic.getVnicProfileId());
    Network network = vnicProfile != null ? vmInfoBuildUtils.getNetwork(vnicProfile.getNetworkId()) : null;
    boolean networkless = network == null;
    switch(device.getDevice()) {
        case "bridge":
            writer.writeAttributeString("type", "bridge");
            writer.writeStartElement("model");
            VmInterfaceType ifaceType = nic.getType() != null ? VmInterfaceType.forValue(nic.getType()) : VmInterfaceType.rtl8139;
            String evaluatedIfaceType = vmInfoBuildUtils.evaluateInterfaceType(ifaceType, vm.getHasAgent());
            if ("pv".equals(evaluatedIfaceType)) {
                evaluatedIfaceType = "virtio";
            }
            writer.writeAttributeString("type", evaluatedIfaceType);
            writer.writeEndElement();
            writer.writeStartElement("link");
            writer.writeAttributeString("state", !networkless && nic.isLinked() ? "up" : "down");
            writer.writeEndElement();
            // The source element is different when using legacy or OVS bridge. We
            // expect VDSM to replace the source element if it is a non legacy bridge
            writer.writeStartElement("source");
            writer.writeAttributeString("bridge", !networkless ? network.getVdsmName() : ";vdsmdummy;");
            writer.writeEndElement();
            String queues = vnicProfile != null ? vnicProfile.getCustomProperties().remove("queues") : null;
            String driverName = getDriverNameForNetwork(!networkless ? network.getName() : "");
            if (queues != null || driverName != null) {
                writer.writeStartElement("driver");
                if (queues != null) {
                    writer.writeAttributeString("queues", queues);
                    if (driverName == null) {
                        driverName = "vhost";
                    }
                }
                writer.writeAttributeString("name", driverName);
                writer.writeEndElement();
            }
            break;
        case "hostdev":
            writer.writeAttributeString("type", "hostdev");
            writer.writeAttributeString("managed", "no");
            writer.writeStartElement("driver");
            writer.writeAttributeString("name", "vfio");
            writer.writeEndElement();
            if (!networkless && NetworkUtils.isVlan(network)) {
                writer.writeStartElement("vlan");
                writer.writeStartElement("tag");
                writer.writeAttributeString("id", network.getVlanId().toString());
                writer.writeEndElement();
                writer.writeEndElement();
            }
            writer.writeStartElement("source");
            writer.writeStartElement("address");
            String vfDeviceName = passthroughVnicToVfMap.get(nic.getId());
            Map<String, String> sourceAddress = hostDevicesSupplier.get().get(vfDeviceName).getAddress();
            sourceAddress.put("type", "pci");
            sourceAddress.forEach(writer::writeAttributeString);
            writer.writeEndElement();
            writer.writeEndElement();
            break;
    }
    writeAlias(device);
    writeAddress(device);
    writeBootOrder(device.getBootOrder());
    writer.writeStartElement("mac");
    writer.writeAttributeString("address", nic.getMacAddress());
    writer.writeEndElement();
    NetworkFilter networkFilter = vmInfoBuildUtils.fetchVnicProfileNetworkFilter(nic);
    if (networkFilter != null) {
        writer.writeStartElement("filterref");
        writer.writeAttributeString("filter", networkFilter.getName());
        vmInfoBuildUtils.getAllNetworkFiltersForVmNic(nic.getId()).forEach(parameter -> {
            writer.writeStartElement("parameter");
            writer.writeAttributeString("name", parameter.getName());
            writer.writeAttributeString("value", parameter.getValue());
            writer.writeEndElement();
        });
        writer.writeEndElement();
    }
    String sndbuf = vmCustomProperties.get("sndbuf");
    if (sndbuf != null) {
        writer.writeStartElement("tune");
        writer.writeElement("sndbuf", sndbuf);
        writer.writeEndElement();
    }
    Map<String, Object> profileData = new HashMap<>();
    vmInfoBuildUtils.addProfileDataToNic(profileData, vm, device, nic);
    List<String> portMirroring = (List<String>) profileData.get(VdsProperties.PORT_MIRRORING);
    if (portMirroring != null && !portMirroring.isEmpty()) {
        // store port mirroring in the metadata
        vnicMetadata.computeIfAbsent(nic.getMacAddress(), mac -> new HashMap<>());
        vnicMetadata.get(nic.getMacAddress()).put("portMirroring", portMirroring);
    }
    Map<String, String> runtimeCustomProperties = vm.getRuntimeDeviceCustomProperties().get(device.getId());
    if (runtimeCustomProperties != null && !runtimeCustomProperties.isEmpty()) {
        // store runtime custom properties in the metadata
        vnicMetadata.computeIfAbsent(nic.getMacAddress(), mac -> new HashMap<>());
        vnicMetadata.get(nic.getMacAddress()).put("runtimeCustomProperties", runtimeCustomProperties);
    }
    if (vnicProfile != null && vnicProfile.getCustomProperties() != null) {
        vnicMetadata.computeIfAbsent(nic.getMacAddress(), mac -> new HashMap<>());
        vnicMetadata.get(nic.getMacAddress()).putAll(vnicProfile.getCustomProperties());
    }
    writer.writeStartElement("bandwidth");
    @SuppressWarnings("unchecked") Map<String, Object> specParams = (Map<String, Object>) profileData.get("specParams");
    if (specParams != null && (specParams.containsKey("inbound") || specParams.containsKey("outbound"))) {
        @SuppressWarnings("unchecked") Map<String, String> inboundMap = (Map<String, String>) specParams.get("inbound");
        if (inboundMap != null && !inboundMap.isEmpty()) {
            writer.writeStartElement("inbound");
            writer.writeAttributeString("average", String.valueOf(inboundMap.get("average")));
            writer.writeAttributeString("burst", String.valueOf(inboundMap.get("burst")));
            writer.writeAttributeString("peak", String.valueOf(inboundMap.get("peak")));
            writer.writeEndElement();
        }
        @SuppressWarnings("unchecked") Map<String, String> outboundMap = (Map<String, String>) specParams.get("outbound");
        if (outboundMap != null && !outboundMap.isEmpty()) {
            writer.writeStartElement("outbound");
            writer.writeAttributeString("average", String.valueOf(outboundMap.get("average")));
            writer.writeAttributeString("burst", String.valueOf(outboundMap.get("burst")));
            writer.writeAttributeString("peak", String.valueOf(outboundMap.get("peak")));
            writer.writeEndElement();
        }
    }
    writer.writeEndElement();
    writer.writeEndElement();
}
Also used : HashMap(java.util.HashMap) NetworkFilter(org.ovirt.engine.core.common.businessentities.network.NetworkFilter) Network(org.ovirt.engine.core.common.businessentities.network.Network) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

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