diff options
author | Jenkins <jenkins@review.openstack.org> | 2017-04-13 17:23:54 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-04-13 17:23:54 +0000 |
commit | 52c59fbb55cba7d9c4b66d2260d27e6c8fa83e9d (patch) | |
tree | e3d9a23c0fb1898fe4cb0f6d323c24fbe21f3968 /os_net_config/utils.py | |
parent | d12f1615cc006a09a232ecd7e3b75000a1af6d21 (diff) | |
parent | b905e0d803e55deee9620a24de4b87c3429b43ab (diff) |
Merge "os_net_config should map nics that are down if nic is in mapping file"
Diffstat (limited to 'os_net_config/utils.py')
-rw-r--r-- | os_net_config/utils.py | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/os_net_config/utils.py b/os_net_config/utils.py index a4dfa4b..b7a54bf 100644 --- a/os_net_config/utils.py +++ b/os_net_config/utils.py @@ -100,20 +100,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 @@ -122,12 +132,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 @@ -144,13 +154,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) |