|
|
67b120 |
From ff1963daf4d5a23e5f9476710e983ab781210608 Mon Sep 17 00:00:00 2001
|
|
|
67b120 |
From: John Kacur <jkacur@redhat.com>
|
|
|
67b120 |
Date: Tue, 27 Sep 2022 12:59:54 -0400
|
|
|
67b120 |
Subject: [PATCH 1/2] tuna: Replace python_ethtool with builtin funtionality
|
|
|
67b120 |
|
|
|
67b120 |
This patch replaces the dependency on python_ethtool with some
|
|
|
67b120 |
simplified functions to achieve the same result.
|
|
|
67b120 |
|
|
|
67b120 |
Reviewed-by: Federico Pellegrin <fede@evolware.org>
|
|
|
67b120 |
- return 'tun' only if tun_flags exists
|
|
|
67b120 |
Signed-off-by: John Kacur <jkacur@redhat.com>
|
|
|
67b120 |
---
|
|
|
67b120 |
tuna-cmd.py | 2 +-
|
|
|
67b120 |
tuna/gui/irqview.py | 2 +-
|
|
|
67b120 |
tuna/new_eth.py | 37 +++++++++++++++++++++++++++++++++++++
|
|
|
67b120 |
tuna/tuna.py | 2 +-
|
|
|
67b120 |
4 files changed, 40 insertions(+), 3 deletions(-)
|
|
|
67b120 |
create mode 100755 tuna/new_eth.py
|
|
|
67b120 |
|
|
|
67b120 |
diff --git a/tuna-cmd.py b/tuna-cmd.py
|
|
|
67b120 |
index bdaa70ffc156..21a70cf1d37d 100755
|
|
|
67b120 |
--- a/tuna-cmd.py
|
|
|
67b120 |
+++ b/tuna-cmd.py
|
|
|
67b120 |
@@ -25,7 +25,7 @@ import fnmatch
|
|
|
67b120 |
import gettext
|
|
|
67b120 |
import locale
|
|
|
67b120 |
from functools import reduce
|
|
|
67b120 |
-import ethtool
|
|
|
67b120 |
+import tuna.new_eth as ethtool
|
|
|
67b120 |
import tuna.tuna_sched as tuna_sched
|
|
|
67b120 |
import procfs
|
|
|
67b120 |
from tuna import tuna, sysfs
|
|
|
67b120 |
diff --git a/tuna/gui/irqview.py b/tuna/gui/irqview.py
|
|
|
67b120 |
index 35fc3fd0b0ca..5143d6dc0df5 100755
|
|
|
67b120 |
--- a/tuna/gui/irqview.py
|
|
|
67b120 |
+++ b/tuna/gui/irqview.py
|
|
|
67b120 |
@@ -7,7 +7,7 @@ from gi.repository import Gtk
|
|
|
67b120 |
from gi.repository import GObject
|
|
|
67b120 |
import os
|
|
|
67b120 |
from functools import reduce
|
|
|
67b120 |
-import ethtool
|
|
|
67b120 |
+import tuna.new_eth as ethtool
|
|
|
67b120 |
import tuna.tuna_sched as tuna_sched
|
|
|
67b120 |
|
|
|
67b120 |
import gi
|
|
|
67b120 |
diff --git a/tuna/new_eth.py b/tuna/new_eth.py
|
|
|
67b120 |
new file mode 100755
|
|
|
67b120 |
index 000000000000..98f9179d5695
|
|
|
67b120 |
--- /dev/null
|
|
|
67b120 |
+++ b/tuna/new_eth.py
|
|
|
67b120 |
@@ -0,0 +1,37 @@
|
|
|
67b120 |
+# Copyright (C) 2022 John Kacur
|
|
|
67b120 |
+""" A few functions similar to ethtool """
|
|
|
67b120 |
+import os
|
|
|
67b120 |
+import socket
|
|
|
67b120 |
+
|
|
|
67b120 |
+def get_active_devices():
|
|
|
67b120 |
+ """ return a list of network devices """
|
|
|
67b120 |
+ ret = []
|
|
|
67b120 |
+
|
|
|
67b120 |
+ for device in socket.if_nameindex():
|
|
|
67b120 |
+ ret.append(device[1])
|
|
|
67b120 |
+
|
|
|
67b120 |
+ return ret
|
|
|
67b120 |
+
|
|
|
67b120 |
+def get_module(intf):
|
|
|
67b120 |
+ """ return the kernel module for the given network interface """
|
|
|
67b120 |
+ if intf == 'lo':
|
|
|
67b120 |
+ return ""
|
|
|
67b120 |
+ myp = f'/sys/class/net/{intf}/device/driver'
|
|
|
67b120 |
+ if os.path.exists(myp):
|
|
|
67b120 |
+ return os.path.basename(os.readlink(myp))
|
|
|
67b120 |
+ if os.path.exists(f'/sys/class/net/{intf}/bridge'):
|
|
|
67b120 |
+ return 'bridge'
|
|
|
67b120 |
+ if os.path.exists(f'/sys/class/net/{intf}/tun_flags'):
|
|
|
67b120 |
+ return 'tun'
|
|
|
67b120 |
+ return ""
|
|
|
67b120 |
+
|
|
|
67b120 |
+if __name__ == "__main__":
|
|
|
67b120 |
+ nics = get_active_devices()
|
|
|
67b120 |
+ print(f'nics = {nics}')
|
|
|
67b120 |
+
|
|
|
67b120 |
+ for intf in nics:
|
|
|
67b120 |
+ driver = get_module(intf)
|
|
|
67b120 |
+ if driver:
|
|
|
67b120 |
+ print(f'{intf}, {driver}')
|
|
|
67b120 |
+ else:
|
|
|
67b120 |
+ print(f'{intf}')
|
|
|
67b120 |
diff --git a/tuna/tuna.py b/tuna/tuna.py
|
|
|
67b120 |
index 31707c9cb69c..84419c957b1b 100755
|
|
|
67b120 |
--- a/tuna/tuna.py
|
|
|
67b120 |
+++ b/tuna/tuna.py
|
|
|
67b120 |
@@ -9,7 +9,7 @@ import sys
|
|
|
67b120 |
import shlex
|
|
|
67b120 |
import fnmatch
|
|
|
67b120 |
import platform
|
|
|
67b120 |
-import ethtool
|
|
|
67b120 |
+import tuna.new_eth as ethtool
|
|
|
67b120 |
import procfs
|
|
|
67b120 |
from procfs import utilist
|
|
|
67b120 |
from tuna import help
|
|
|
67b120 |
--
|
|
|
67b120 |
2.37.3
|
|
|
67b120 |
|