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;
}
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);
}
}
}
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();
}
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);
}
}
}
}
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;
}
Aggregations