aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/utils.py
diff options
context:
space:
mode:
authorBob Fournier <bfournie@redhat.com>2017-04-04 13:58:43 -0400
committerBob Fournier <bfournie@redhat.com>2017-04-10 10:05:42 -0400
commitb905e0d803e55deee9620a24de4b87c3429b43ab (patch)
tree74a799122f66f3e072bb9a2c934e60718b58aecd /os_net_config/utils.py
parent1b83afb07ddec59845ea3ca47fb9b20eefba1c5d (diff)
os_net_config should map nics that are down if nic is in mapping file
Currently os-net_config will map nics from a user-supplied mapping file only if the nic is active (operstate = up). This can cause problems if a nic is in a bond and one of the bond's nics has no carrier. This fix will map the nic from the mapping file if the nic is defined on the system, regardless of the operstate status. The fix implements a new function to return a list of available nics (no check of operstate) for use if a mapping file is supplied. The list of active nics must still be used in the default case when numbering nics (no mapping file supplied). There is also some cleanup to check if a user-supplied mac is in the mapping file before attempting to convert the mac to a nic. Change-Id: Ia5d8c8b49b7ac0b51ee42a754f06e5e53587a5f6 Closes-Bug: 1679787
Diffstat (limited to 'os_net_config/utils.py')
-rw-r--r--os_net_config/utils.py30
1 files changed, 24 insertions, 6 deletions
diff --git a/os_net_config/utils.py b/os_net_config/utils.py
index 98bfe99..84e719e 100644
--- a/os_net_config/utils.py
+++ b/os_net_config/utils.py
@@ -92,20 +92,30 @@ def interface_mac(name):
def _is_active_nic(interface_name):
+ return _is_available_nic(interface_name, True)
+
+
+def _is_available_nic(interface_name, check_active=True):
try:
if interface_name == 'lo':
return False
device_dir = _SYS_CLASS_NET + '/%s/device' % interface_name
has_device_dir = os.path.isdir(device_dir)
+ if not has_device_dir:
+ return False
operstate = None
with open(_SYS_CLASS_NET + '/%s/operstate' % interface_name, 'r') as f:
operstate = f.read().rstrip().lower()
+ if check_active and operstate != 'up':
+ return False
address = None
with open(_SYS_CLASS_NET + '/%s/address' % interface_name, 'r') as f:
address = f.read().rstrip()
+ if not address:
+ return False
# If SR-IOV Virtual Functions (VF) are enabled in an interface, there
# will be additional nics created for each VF. It has to be ignored in
@@ -114,12 +124,12 @@ def _is_active_nic(interface_name):
# ignored.
vf_path_check = _SYS_CLASS_NET + '/%s/device/physfn' % interface_name
is_sriov_vf = os.path.isdir(vf_path_check)
-
- if (has_device_dir and operstate == 'up' and address and
- not is_sriov_vf):
- return True
- else:
+ if is_sriov_vf:
return False
+
+ # nic is available
+ return True
+
except IOError:
return False
@@ -136,13 +146,21 @@ def _is_embedded_nic(nic):
return False
+def ordered_available_nics():
+ return _ordered_nics(False)
+
+
def ordered_active_nics():
+ return _ordered_nics(True)
+
+
+def _ordered_nics(check_active):
embedded_nics = []
nics = []
logger.debug("Finding active nics")
for name in glob.iglob(_SYS_CLASS_NET + '/*'):
nic = name[(len(_SYS_CLASS_NET) + 1):]
- if _is_active_nic(nic):
+ if _is_available_nic(nic, check_active):
if _is_embedded_nic(nic):
logger.debug("%s is an embedded active nic" % nic)
embedded_nics.append(nic)