summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Kacur <jkacur@redhat.com>2022-09-27 12:59:54 -0400
committerJohn Kacur <jkacur@redhat.com>2022-09-30 12:15:02 -0400
commitf2a28b05264fa9557192b73a1b888756748930ac (patch)
tree6411db607153af0b1cb2166b128aac112916cff3
parent87f6d9e29bab615b03b26210e3ead493fd08fe1f (diff)
downloadtuna-f2a28b05264fa9557192b73a1b888756748930ac.tar.gz
tuna: Replace python_ethtool with builtin funtionality
This patch replaces the dependency on python_ethtool with some simplified functions to achieve the same result. Reviewed-by: Federico Pellegrin <fede@evolware.org> - return 'tun' only if tun_flags exists Signed-off-by: John Kacur <jkacur@redhat.com>
-rwxr-xr-xtuna-cmd.py2
-rwxr-xr-xtuna/gui/irqview.py2
-rwxr-xr-xtuna/new_eth.py37
-rwxr-xr-xtuna/tuna.py2
4 files changed, 40 insertions, 3 deletions
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 9a3d3f3..b13b25b 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -26,7 +26,7 @@ import fnmatch
import gettext
import locale
from functools import reduce
-import ethtool
+import tuna.new_eth as ethtool
import tuna.tuna_sched as tuna_sched
import procfs
from tuna import tuna, sysfs
diff --git a/tuna/gui/irqview.py b/tuna/gui/irqview.py
index 35fc3fd..5143d6d 100755
--- a/tuna/gui/irqview.py
+++ b/tuna/gui/irqview.py
@@ -7,7 +7,7 @@ from gi.repository import Gtk
from gi.repository import GObject
import os
from functools import reduce
-import ethtool
+import tuna.new_eth as ethtool
import tuna.tuna_sched as tuna_sched
import gi
diff --git a/tuna/new_eth.py b/tuna/new_eth.py
new file mode 100755
index 0000000..98f9179
--- /dev/null
+++ b/tuna/new_eth.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2022 John Kacur
+""" A few functions similar to ethtool """
+import os
+import socket
+
+def get_active_devices():
+ """ return a list of network devices """
+ ret = []
+
+ for device in socket.if_nameindex():
+ ret.append(device[1])
+
+ return ret
+
+def get_module(intf):
+ """ return the kernel module for the given network interface """
+ if intf == 'lo':
+ return ""
+ myp = f'/sys/class/net/{intf}/device/driver'
+ if os.path.exists(myp):
+ return os.path.basename(os.readlink(myp))
+ if os.path.exists(f'/sys/class/net/{intf}/bridge'):
+ return 'bridge'
+ if os.path.exists(f'/sys/class/net/{intf}/tun_flags'):
+ return 'tun'
+ return ""
+
+if __name__ == "__main__":
+ nics = get_active_devices()
+ print(f'nics = {nics}')
+
+ for intf in nics:
+ driver = get_module(intf)
+ if driver:
+ print(f'{intf}, {driver}')
+ else:
+ print(f'{intf}')
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 30a5a57..43adb84 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -9,7 +9,7 @@ import sys
import shlex
import fnmatch
import platform
-import ethtool
+import tuna.new_eth as ethtool
import procfs
from procfs import utilist
from tuna import help