From: Radek Pazdera <rpazdera(a)redhat.com>
I separated scan_netdevs method from the class and changed it to
regular function, because it will be useful elsewhere in the code,
but not in the context of the class (so using the class directly
would not be pretty).
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
---
NetConfig/NetConfigDevNames.py | 40 ++++++++++++++++++++--------------------
1 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/NetConfig/NetConfigDevNames.py b/NetConfig/NetConfigDevNames.py
index 7c7f862..3f3e0fd 100644
--- a/NetConfig/NetConfigDevNames.py
+++ b/NetConfig/NetConfigDevNames.py
@@ -15,30 +15,30 @@ import os
from NetConfigCommon import get_option
from Common.NetUtils import normalize_hwaddr
+def scan_netdevs():
+ sys_dir = "/sys/class/net"
+ scan = []
+ for root, dirs, files in os.walk(sys_dir):
+ if "lo" in dirs:
+ dirs.remove("lo")
+ for d in dirs:
+ dev_path = os.path.join(sys_dir, d)
+ addr_path = os.path.join(dev_path, "address")
+ if not os.path.isfile(addr_path):
+ continue
+ handle = open(addr_path, "rb")
+ addr = handle.read()
+ handle.close()
+ addr = normalize_hwaddr(addr)
+ scan.append({"name": d, "hwaddr": addr})
+ return scan
+
class NetConfigDevNames:
def __init__(self):
- self._scan = self._scan_netdevs()
-
- def _scan_netdevs(self):
- sys_dir = "/sys/class/net"
- scan = []
- for root, dirs, files in os.walk(sys_dir):
- if "lo" in dirs:
- dirs.remove("lo")
- for d in dirs:
- dev_path = os.path.join(sys_dir, d)
- addr_path = os.path.join(dev_path, "address")
- if not os.path.isfile(addr_path):
- continue
- handle = open(addr_path, "rb")
- addr = handle.read()
- handle.close()
- addr = normalize_hwaddr(addr)
- scan.append({"name": d, "hwaddr": addr})
- return scan
+ self._scan = scan_netdevs()
def rescan_netdevs(self):
- self._scan = self._scan_netdevs()
+ self._scan = scan_netdevs()
def assign_name_by_scan(self, dev_id, netdev):
if (not "hwaddr" in netdev or
--
1.7.7.6