Search in sources :

Example 16 with VnicProfile

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

the class AddNetworkCommand method runAddVnicProfile.

private void runAddVnicProfile() {
    if (getNetwork().isVmNetwork() && getParameters().isVnicProfileRequired()) {
        VnicProfile vnicProfile = networkHelper.createVnicProfile(getNetwork());
        AddVnicProfileParameters vnicProfileParameters = new AddVnicProfileParameters(vnicProfile);
        vnicProfileParameters.setPublicUse(getParameters().isVnicProfilePublicUse());
        runInternalAction(ActionType.AddVnicProfile, vnicProfileParameters, getContext().clone().withoutLock());
    }
}
Also used : VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) AddVnicProfileParameters(org.ovirt.engine.core.common.action.AddVnicProfileParameters)

Example 17 with VnicProfile

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

Example 18 with VnicProfile

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

the class VmInfoBuildUtils method addNetworkVirtualFunctionProperties.

public void addNetworkVirtualFunctionProperties(Map<String, Object> struct, VmNic vmInterface, VmDevice vmDevice, String vfName, VM vm) {
    struct.put(VdsProperties.Type, vmDevice.getType().getValue());
    struct.put(VdsProperties.Device, vmDevice.getDevice());
    struct.put(VdsProperties.HostDev, vfName);
    addAddress(vmDevice, struct);
    struct.put(VdsProperties.MAC_ADDR, vmInterface.getMacAddress());
    struct.put(VdsProperties.DeviceId, String.valueOf(vmDevice.getId().getDeviceId()));
    Map<String, Object> specParams = new HashMap<>();
    VnicProfile vnicProfile = getVnicProfile(vmInterface.getVnicProfileId());
    Network network = getNetwork(vnicProfile.getNetworkId());
    if (NetworkUtils.isVlan(network)) {
        specParams.put(VdsProperties.VLAN_ID, network.getVlanId());
    }
    struct.put(VdsProperties.SpecParams, specParams);
    addCustomPropertiesForDevice(struct, vm, vmDevice, getVnicCustomProperties(vnicProfile));
}
Also used : HashMap(java.util.HashMap) Network(org.ovirt.engine.core.common.businessentities.network.Network) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile)

Example 19 with VnicProfile

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

the class EntityDaoImplTest method testGetEntityNameByIdAndTypeForVNICProfile.

@Test
public void testGetEntityNameByIdAndTypeForVNICProfile() {
    VnicProfile vnicProfile = vnicProfileDao.get(FixturesTool.VM_NETWORK_INTERFACE_PROFILE);
    assertNotNull(vnicProfile);
    String name = vnicProfile.getName();
    assertEquals(name, underTest.getEntityNameByIdAndType(FixturesTool.VM_NETWORK_INTERFACE_PROFILE, VdcObjectType.VnicProfile));
}
Also used : VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) Test(org.junit.Test)

Example 20 with VnicProfile

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

the class VmInfoBuildUtils method addProfileDataToNic.

public void addProfileDataToNic(Map<String, Object> struct, VM vm, VmDevice vmDevice, VmNic nic) {
    VnicProfile vnicProfile = null;
    Network network = null;
    String networkName = "";
    String vdsmName = "";
    List<VnicProfileProperties> unsupportedFeatures = new ArrayList<>();
    if (nic.getVnicProfileId() != null) {
        vnicProfile = getVnicProfile(nic.getVnicProfileId());
        if (vnicProfile != null) {
            network = getNetwork(vnicProfile.getNetworkId());
            networkName = network.getName();
            vdsmName = network.getVdsmName();
            log.debug("VNIC '{}' is using profile '{}' on network '{}' with vdsmName '{}'", nic.getName(), vnicProfile, networkName, vdsmName);
            addQosForDevice(struct, vnicProfile);
        }
    }
    struct.put(VdsProperties.NETWORK, vdsmName);
    addPortMirroringToVmInterface(struct, vnicProfile, network);
    addCustomPropertiesForDevice(struct, vm, vmDevice, getVnicCustomProperties(vnicProfile));
    reportUnsupportedVnicProfileFeatures(vm, nic, vnicProfile, unsupportedFeatures);
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) ArrayList(java.util.ArrayList)

Aggregations

VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)31 Network (org.ovirt.engine.core.common.businessentities.network.Network)12 NetworkFilter (org.ovirt.engine.core.common.businessentities.network.NetworkFilter)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Test (org.junit.Test)3 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)3 Guid (org.ovirt.engine.core.compat.Guid)3 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)2 AddVnicProfileParameters (org.ovirt.engine.core.common.action.AddVnicProfileParameters)2 VM (org.ovirt.engine.core.common.businessentities.VM)2 NewVnicProfileModel (org.ovirt.engine.ui.uicommonweb.models.profiles.NewVnicProfileModel)2 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Inject (javax.inject.Inject)1