aboutsummaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorPeter Mikus <peter.mikus@protonmail.ch>2024-12-05 08:04:24 +0100
committerPeter Mikus <peter.mikus@protonmail.ch>2024-12-05 08:04:24 +0100
commitd8341ba278e8e0ea4960306f43e7fd7c871dc1d1 (patch)
tree227542355b5df81c92b71885c6eb0690877561e4 /resources
parent2e9ac3fbc6f781040a85d112d2541a473be76720 (diff)
fix(core): remove lshw dependency
Signed-off-by: Peter Mikus <peter.mikus@protonmail.ch> Change-Id: I14143394ed6637db183a2fcc9b91e3c7fc8e0037
Diffstat (limited to 'resources')
-rw-r--r--resources/libraries/python/IPUtil.py23
1 files changed, 7 insertions, 16 deletions
diff --git a/resources/libraries/python/IPUtil.py b/resources/libraries/python/IPUtil.py
index 504bc3eb69..d7996ccf79 100644
--- a/resources/libraries/python/IPUtil.py
+++ b/resources/libraries/python/IPUtil.py
@@ -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):