fix(core): remove lshw dependency 62/41962/1
authorPeter Mikus <[email protected]>
Thu, 5 Dec 2024 07:04:24 +0000 (08:04 +0100)
committerPeter Mikus <[email protected]>
Thu, 5 Dec 2024 07:04:24 +0000 (08:04 +0100)
Signed-off-by: Peter Mikus <[email protected]>
Change-Id: I14143394ed6637db183a2fcc9b91e3c7fc8e0037

resources/libraries/python/IPUtil.py

index 504bc3e..d7996cc 100644 (file)
@@ -14,8 +14,6 @@
 
 """Common IP utilities library."""
 
-import re
-
 from enum import IntEnum
 
 from ipaddress import ip_address, ip_network
@@ -395,25 +393,18 @@ class IPUtil:
         :rtype: str
         :raises RuntimeError: If cannot get the information about interfaces.
         """
-        regex_intf_info = \
-            r"pci@([0-9a-f]{4}:[0-9a-f]{2}:[0-9a-f]{2}.[0-9a-f])\s" \
-            r"*([a-zA-Z0-9]*)\s*network"
-
-        cmd = u"lshw -class network -businfo"
-        ret_code, stdout, stderr = exec_cmd(node, cmd, timeout=30, sudo=True)
+        cmd = f"grep '{pci_addr}' /sys/class/net/*/device/uevent"
+        ret_code, stdout, stderr = exec_cmd(node, cmd, timeout=30)
         if ret_code != 0:
+            return None
+
+        try:
+            stdout.split("/")[4]
+        except IndexError:
             raise RuntimeError(
                 f"Could not get information about interfaces:\n{stderr}"
             )
 
-        for line in stdout.splitlines()[2:]:
-            try:
-                if re.search(regex_intf_info, line).group(1) == pci_addr:
-                    return re.search(regex_intf_info, line).group(2)
-            except AttributeError:
-                continue
-        return None
-
     @staticmethod
     def set_linux_interface_up(
             node, interface, namespace=None):