Blame SOURCES/0013-Python-3-ethtool-and-indentation-fixes.patch

1070a0
From 4a23a3cc1b9d1ab1238aadbd7945aa93c21f7638 Mon Sep 17 00:00:00 2001
1070a0
From: Tomas Kasparek <tkasparek@redhat.com>
1070a0
Date: Mon, 5 Mar 2018 11:39:34 +0100
1070a0
Subject: [PATCH 13/17] Python 3 ethtool and indentation fixes
1070a0
1070a0
---
1070a0
 koan/utils.py | 98 ++++++++++++++++++++++++++++++++---------------------------
1070a0
 1 file changed, 54 insertions(+), 44 deletions(-)
1070a0
1070a0
diff --git a/koan/utils.py b/koan/utils.py
1070a0
index e202bd5..0cd48ea 100644
1070a0
--- a/koan/utils.py
1070a0
+++ b/koan/utils.py
1070a0
@@ -367,50 +367,60 @@ def uniqify(lst, purge=None):
1070a0
    return list(temp.keys())
1070a0
 
1070a0
 def get_network_info():
1070a0
-   try:
1070a0
-      import ethtool
1070a0
-   except:
1070a0
-      try:
1070a0
-         import rhpl.ethtool
1070a0
-         ethtool = rhpl.ethtool
1070a0
-      except:
1070a0
-           raise InfoException("the rhpl or ethtool module is required to use this feature (is your OS>=EL3?)")
1070a0
-
1070a0
-   interfaces = {}
1070a0
-   # get names
1070a0
-   inames  = ethtool.get_devices()
1070a0
-
1070a0
-   for iname in inames:
1070a0
-      mac = ethtool.get_hwaddr(iname)
1070a0
-
1070a0
-      if mac == "00:00:00:00:00:00":
1070a0
-         mac = "?"
1070a0
-
1070a0
-      try:
1070a0
-         ip  = ethtool.get_ipaddr(iname)
1070a0
-         if ip == "127.0.0.1":
1070a0
-            ip = "?"
1070a0
-      except:
1070a0
-         ip  = "?"
1070a0
-
1070a0
-      bridge = 0
1070a0
-      module = ""
1070a0
-
1070a0
-      try:
1070a0
-         nm  = ethtool.get_netmask(iname)
1070a0
-      except:
1070a0
-         nm  = "?"
1070a0
-
1070a0
-      interfaces[iname] = {
1070a0
-         "ip_address"  : ip,
1070a0
-         "mac_address" : mac,
1070a0
-         "netmask"     : nm,
1070a0
-         "bridge"      : bridge,
1070a0
-         "module"      : module
1070a0
-      }
1070a0
-
1070a0
-   # print(interfaces)
1070a0
-   return interfaces
1070a0
+    try: # python 2
1070a0
+        import ethtool
1070a0
+        ethtool_available = True
1070a0
+    except ImportError:  # python 3
1070a0
+        import netifaces
1070a0
+        ethtool_available = False
1070a0
+
1070a0
+    interfaces = {}
1070a0
+    # get names
1070a0
+    if ethtool_available:
1070a0
+        inames = ethtool.get_devices()
1070a0
+    else:
1070a0
+        inames = netifaces.interfaces()
1070a0
+
1070a0
+    for iname in inames:
1070a0
+        if ethtool_available:
1070a0
+            mac = ethtool.get_hwaddr(iname)
1070a0
+        else:
1070a0
+            mac = netifaces.ifaddresses(iname)[netifaces.AF_LINK][0]['addr']
1070a0
+
1070a0
+        if mac == "00:00:00:00:00:00":
1070a0
+            mac = "?"
1070a0
+
1070a0
+        try:
1070a0
+            if ethtool_available:
1070a0
+                ip = ethtool.get_ipaddr(iname)
1070a0
+            else:
1070a0
+                ip = netifaces.ifaddresses(iname)[netifaces.AF_INET][0]['addr']
1070a0
+            if ip == "127.0.0.1":
1070a0
+                ip = "?"
1070a0
+        except:
1070a0
+            ip  = "?"
1070a0
+
1070a0
+        bridge = 0
1070a0
+        module = ""
1070a0
+
1070a0
+        try:
1070a0
+            if ethtool_available:
1070a0
+                nm  = ethtool.get_netmask(iname)
1070a0
+            else:
1070a0
+                nm = netifaces.ifaddresses(iname)[netifaces.AF_INET][0]['netmask']
1070a0
+        except:
1070a0
+            nm  = "?"
1070a0
+
1070a0
+        interfaces[iname] = {
1070a0
+            "ip_address"  : ip,
1070a0
+            "mac_address" : mac,
1070a0
+            "netmask"     : nm,
1070a0
+            "bridge"      : bridge,
1070a0
+            "module"      : module
1070a0
+        }
1070a0
+
1070a0
+    # print(interfaces)
1070a0
+    return interfaces
1070a0
 
1070a0
 def connect_to_server(server=None,port=None):
1070a0
 
1070a0
-- 
1070a0
2.5.5
1070a0