Search in sources :

Example 1 with Vlan

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

the class VdsBrokerObjectsBuilder method addHostVlanDevices.

/**
 * Updates the host interfaces list with vlan devices
 *
 * @param vds
 *            The host to update
 * @param struct
 *            a map contains pairs of vlan device name and vlan data
 */
private static void addHostVlanDevices(VDS vds, Map<String, Object> struct) {
    // vlans
    Map<String, Map<String, Object>> vlans = (Map<String, Map<String, Object>>) struct.get(VdsProperties.NETWORK_VLANS);
    if (vlans != null) {
        for (Entry<String, Map<String, Object>> entry : vlans.entrySet()) {
            VdsNetworkInterface vlan = new Vlan();
            updateCommonInterfaceData(vlan, vds, entry);
            String vlanDeviceName = entry.getKey();
            Map<String, Object> vlanProperties = entry.getValue();
            if (vlanProperties.get(VdsProperties.VLAN_ID) != null && vlanProperties.get(VdsProperties.BASE_INTERFACE) != null) {
                vlan.setVlanId((Integer) vlanProperties.get(VdsProperties.VLAN_ID));
                vlan.setBaseInterface((String) vlanProperties.get(VdsProperties.BASE_INTERFACE));
            } else if (vlanDeviceName.contains(".")) {
                String[] names = vlanDeviceName.split("[.]", -1);
                String vlanId = names[1];
                vlan.setVlanId(Integer.parseInt(vlanId));
                vlan.setBaseInterface(names[0]);
            }
            vds.getInterfaces().add(vlan);
        }
    }
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Vlan(org.ovirt.engine.core.common.businessentities.network.Vlan) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Vlan

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

the class HostInterfaceListModel method classifyNics.

private void classifyNics(List<Bond> nonEmptyBonds, List<Nic> independentNics, Map<String, List<Nic>> bondToNics, Map<String, List<Vlan>> nicToVlans) {
    for (VdsNetworkInterface nic : getOriginalItems()) {
        if (nic instanceof Bond) {
            nonEmptyBonds.add((Bond) nic);
        } else if (nic instanceof Nic) {
            if (nic.getBondName() == null) {
                independentNics.add((Nic) nic);
            } else {
                if (bondToNics.containsKey(nic.getBondName())) {
                    bondToNics.get(nic.getBondName()).add((Nic) nic);
                } else {
                    List<Nic> nicList = new ArrayList<>();
                    nicList.add((Nic) nic);
                    bondToNics.put(nic.getBondName(), nicList);
                }
            }
        } else if (nic instanceof Vlan) {
            String nameWithoutVlan = nic.getBaseInterface();
            if (nicToVlans.containsKey(nameWithoutVlan)) {
                nicToVlans.get(nameWithoutVlan).add((Vlan) nic);
            } else {
                List<Vlan> vlanList = new ArrayList<>();
                vlanList.add((Vlan) nic);
                nicToVlans.put(nameWithoutVlan, vlanList);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Nic(org.ovirt.engine.core.common.businessentities.network.Nic) ArrayList(java.util.ArrayList) List(java.util.List) Vlan(org.ovirt.engine.core.common.businessentities.network.Vlan) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Example 3 with Vlan

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

the class HostNicMapper method map.

@Mapping(from = HostNic.class, to = VdsNetworkInterface.class)
public static VdsNetworkInterface map(HostNic model, VdsNetworkInterface template) {
    VdsNetworkInterface entity;
    if (template != null) {
        entity = template;
    } else if (model.isSetBonding()) {
        entity = new Bond();
    } else if (model.isSetVlan()) {
        entity = new Vlan();
    } else {
        entity = new Nic();
    }
    if (model.isSetId()) {
        entity.setId(GuidUtils.asGuid(model.getId()));
    }
    if (model.isSetNetwork() && model.getNetwork().isSetName()) {
        entity.setNetworkName(model.getNetwork().getName());
    }
    if (model.isSetName()) {
        entity.setName(model.getName());
    }
    if (model.isSetBaseInterface()) {
        entity.setBaseInterface(model.getBaseInterface());
    }
    mapIpv4FromModel(model, entity);
    mapIpv6FromModel(model, entity);
    if (model.isSetMac() && model.getMac().isSetAddress()) {
        entity.setMacAddress(model.getMac().getAddress());
    }
    if (model.isSetBonding()) {
        entity.setBonded(true);
        if (model.getBonding().isSetOptions()) {
            List<Option> bondingOptions = model.getBonding().getOptions().getOptions();
            String optionsString = bondingOptions.stream().filter(Option::isSetName).map(x -> x.getName() + "=" + x.getValue()).collect(joining(" "));
            entity.setBondOptions(optionsString);
        }
    }
    if (model.isSetQos()) {
        entity.setQos((HostNetworkQos) QosMapper.map(model.getQos(), null));
    }
    return entity;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) InterfaceStatus(org.ovirt.engine.core.common.businessentities.network.InterfaceStatus) HostNic(org.ovirt.engine.api.model.HostNic) GuidUtils(org.ovirt.engine.api.restapi.utils.GuidUtils) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Ipv6BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv6BootProtocol) Option(org.ovirt.engine.api.model.Option) Network(org.ovirt.engine.api.model.Network) Mac(org.ovirt.engine.api.model.Mac) BootProtocol(org.ovirt.engine.api.model.BootProtocol) Bonding(org.ovirt.engine.api.model.Bonding) IpVersion(org.ovirt.engine.api.model.IpVersion) HostNetworkQos(org.ovirt.engine.core.common.businessentities.network.HostNetworkQos) Vlan(org.ovirt.engine.core.common.businessentities.network.Vlan) Nic(org.ovirt.engine.core.common.businessentities.network.Nic) Ipv4BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol) Collectors.joining(java.util.stream.Collectors.joining) NicStatus(org.ovirt.engine.api.model.NicStatus) UpdateHostNicVfsConfigParameters(org.ovirt.engine.core.common.action.UpdateHostNicVfsConfigParameters) List(java.util.List) HostNicVirtualFunctionsConfiguration(org.ovirt.engine.api.model.HostNicVirtualFunctionsConfiguration) Bond(org.ovirt.engine.core.common.businessentities.network.Bond) Ip(org.ovirt.engine.api.model.Ip) Options(org.ovirt.engine.api.model.Options) HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) HostNic(org.ovirt.engine.api.model.HostNic) Nic(org.ovirt.engine.core.common.businessentities.network.Nic) Option(org.ovirt.engine.api.model.Option) Vlan(org.ovirt.engine.core.common.businessentities.network.Vlan) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Example 4 with Vlan

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

the class NetworkUtilsTest method createVlan.

private VdsNetworkInterface createVlan(String baseIfaceName) {
    VdsNetworkInterface iface = new Vlan();
    iface.setVlanId(RandomUtils.instance().nextInt(100));
    iface.setBaseInterface(baseIfaceName);
    return iface;
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Vlan(org.ovirt.engine.core.common.businessentities.network.Vlan)

Aggregations

VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)4 Vlan (org.ovirt.engine.core.common.businessentities.network.Vlan)4 List (java.util.List)2 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)2 Nic (org.ovirt.engine.core.common.businessentities.network.Nic)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Collectors.joining (java.util.stream.Collectors.joining)1 StringUtils (org.apache.commons.lang.StringUtils)1 Bonding (org.ovirt.engine.api.model.Bonding)1 BootProtocol (org.ovirt.engine.api.model.BootProtocol)1 HostNic (org.ovirt.engine.api.model.HostNic)1 HostNicVirtualFunctionsConfiguration (org.ovirt.engine.api.model.HostNicVirtualFunctionsConfiguration)1 Ip (org.ovirt.engine.api.model.Ip)1 IpVersion (org.ovirt.engine.api.model.IpVersion)1 Mac (org.ovirt.engine.api.model.Mac)1 Network (org.ovirt.engine.api.model.Network)1 NicStatus (org.ovirt.engine.api.model.NicStatus)1 Option (org.ovirt.engine.api.model.Option)1