Change in vdsm[master]: netinfo: make getNicsVlanAndBondingForNetwork more readable, ...

osvoboda at redhat.com osvoboda at redhat.com
Wed Aug 19 14:40:59 UTC 2015


Ondřej Svoboda has uploaded a new change for review.

Change subject: netinfo: make getNicsVlanAndBondingForNetwork more readable, drop asserts
......................................................................

netinfo: make getNicsVlanAndBondingForNetwork more readable, drop asserts

The function serves a complex purpose of reporting constituent devices
of a network (bridged or bridgeless).

Notably, now it determines a VLAN's underlying device and tag from the NetInfo
object instead of reading this wastefully, again.

After the rewrite it still employs a (maybe surprising) shortcut to handle
bridged and bridgeless networks alike and also a fall-through to traverse
from top to bottom of a VLAN-bond-NIC(s) hierarchy (possibly with some of the
virtual devices missing).

It relies on an assumption that there is at most one such hierarchy. If the
network is bridged, attached TUN devices are also reported.

Change-Id: If8535dbd29314c97e4519b160a47c9ea6489b5a3
Signed-off-by: Ondřej Svoboda <osvoboda at redhat.com>
---
M lib/vdsm/netinfo.py
1 file changed, 21 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/95/45095/1

diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py
index b5e62f9..3c1e0f4 100644
--- a/lib/vdsm/netinfo.py
+++ b/lib/vdsm/netinfo.py
@@ -867,33 +867,33 @@
 
     def getNicsVlanAndBondingForNetwork(self, network):
         vlan = None
-        vlanid = None
-        bonding = None
-        lnics = []
+        vlan_id = None
+        bond = None
+        nics = []
 
         if self.networks[network]['bridged']:
             ports = self.networks[network]['ports']
         else:
-            ports = []
-            interface = self.networks[network]['iface']
-            ports.append(interface)
+            ports = [self.networks[network]['iface']]
 
-        for port in ports:
-            if port in self.vlans:
-                assert vlan is None
-                nic = _vlan_device(port)
-                vlanid = getVlanID(port)
-                vlan = port  # vlan devices can have an arbitrary name
-                assert self.vlans[port]['iface'] == nic
-                port = nic
-            if port in self.bondings:
-                assert bonding is None
-                bonding = port
-                lnics += self.bondings[bonding]['slaves']
-            elif port in self.nics:
-                lnics.append(port)
+        # If the network is bridged, it is assumed that at most one of its
+        # ports is connected to physical NIC(s) possibly through a VLAN and/or
+        # bonding device. Other ports (if present) are virtual NICs that belong
+        # to VMs (but they are also reported by the function).
+        for device in ports:
+            vlan_info = self.vlans.get(device)
+            if vlan_info:
+                vlan = device
+                vlan_id = vlan_info['vlanid']
+                device = vlan_info['iface']
+            bond_info = self.bondings.get(device)
+            if bond_info:
+                bond = device
+                nics += bond_info['slaves']
+            elif device in self.nics:
+                nics.append(device)
 
-        return lnics, vlan, vlanid, bonding
+        return nics, vlan, vlan_id, bond
 
     @staticmethod
     def getDefaultMtu():


-- 
To view, visit https://gerrit.ovirt.org/45095
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If8535dbd29314c97e4519b160a47c9ea6489b5a3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <osvoboda at redhat.com>


More information about the vdsm-patches mailing list