Search in sources :

Example 1 with Nic

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

the class BackendLinkLayerDiscoveryProtocolResourceTest method getNic.

public static Nic getNic() {
    Nic nic = new Nic();
    nic.setId(NIC_ID);
    return nic;
}
Also used : Nic(org.ovirt.engine.core.common.businessentities.network.Nic)

Example 2 with Nic

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

the class VdsBrokerObjectsBuilder method addHostNetworkInterfaces.

/**
 * Updates the host network interfaces with the collected data from the host
 *
 * @param vds
 *            The host to update its interfaces
 * @param struct
 *            A nested map contains network interfaces data
 */
private static void addHostNetworkInterfaces(VDS vds, Map<String, Object> struct) {
    Map<String, Map<String, Object>> nics = (Map<String, Map<String, Object>>) struct.get(VdsProperties.NETWORK_NICS);
    if (nics != null) {
        for (Entry<String, Map<String, Object>> entry : nics.entrySet()) {
            VdsNetworkInterface nic = new Nic();
            updateCommonInterfaceData(nic, vds, entry);
            Map<String, Object> nicProperties = entry.getValue();
            if (nicProperties != null) {
                nic.setMacAddress((String) nicProperties.get("hwaddr"));
                // if we get "permhwaddr", we are a part of a bond and we use that as the mac address
                String mac = (String) nicProperties.get("permhwaddr");
                if (mac != null) {
                    // TODO remove when the minimal supported vdsm version is >=3.6
                    // in older VDSM version, slave's Mac is in upper case
                    nic.setMacAddress(mac.toLowerCase());
                }
            }
            vds.getInterfaces().add(nic);
        }
    }
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Nic(org.ovirt.engine.core.common.businessentities.network.Nic) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with Nic

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

the class HostInterfaceListModel method updateItems.

private void updateItems(Iterable<VdsNetworkInterface> source) {
    ArrayList<HostInterfaceLineModel> items = new ArrayList<>();
    setOriginalItems((ArrayList<VdsNetworkInterface>) source);
    List<Bond> nonEmptyBonds = new ArrayList<>();
    List<Nic> independentNics = new ArrayList<>();
    Map<String, List<Nic>> bondToNics = new HashMap<>();
    Map<String, List<Vlan>> nicToVlans = new HashMap<>();
    sortNics();
    classifyNics(nonEmptyBonds, independentNics, bondToNics, nicToVlans);
    // create all bond models
    for (Bond bond : nonEmptyBonds) {
        HostInterfaceLineModel model = lineModelFromBond(bond);
        items.add(model);
        // add contained interface models - should exist, but check just in case
        if (bondToNics.containsKey(bond.getName())) {
            for (Nic nic : bondToNics.get(bond.getName())) {
                model.getInterfaces().add(hostInterfaceFromNic(nic));
            }
        }
        // add any corresponding VLAN bridge models
        model.getVLans().addAll(gatherVlans(bond, nicToVlans));
    }
    // create all independent NIC models
    for (Nic nic : independentNics) {
        HostInterfaceLineModel model = lineModelFromInterface(nic);
        model.getInterfaces().add(hostInterfaceFromNic(nic));
        items.add(model);
        // add any corresponding VLAN bridge models
        model.getVLans().addAll(gatherVlans(nic, nicToVlans));
    }
    setItems(items);
    updateActionAvailability();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Nic(org.ovirt.engine.core.common.businessentities.network.Nic) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ArrayList(java.util.ArrayList) List(java.util.List) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Example 4 with Nic

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

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

Aggregations

Nic (org.ovirt.engine.core.common.businessentities.network.Nic)13 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)9 Test (org.junit.Test)4 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)4 List (java.util.List)3 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)2 Vlan (org.ovirt.engine.core.common.businessentities.network.Vlan)2 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