summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2022-04-18 15:58:22 +0200
committerJose M. Guisado <jguisado@soleta.eu>2022-04-21 09:47:31 +0200
commitd3f9788aab9580a7c4d58b1e95c8bd3a4320f0a2 (patch)
treed54b15faea550d4378232f96fd118507b55a26a6 /src
parenta9bc953f6302384e23babdf7d2299f111ddf5608 (diff)
live: use utils.py for probe operation
Import ethtool function from utils.py
Diffstat (limited to 'src')
-rw-r--r--src/live/ogOperations.py26
1 files changed, 4 insertions, 22 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index b5ddaeb..2aa42bd 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -9,10 +9,11 @@
import os
import json
import subprocess
-import fcntl, socket, array, struct
from src.ogClient import ogClient
from src.ogRest import ThreadState
+from src.utils.net import ethtool
+
OG_SHELL = '/bin/bash'
class OgLiveOperations:
@@ -281,27 +282,8 @@ class OgLiveOperations:
return self.parseGetConf(output.decode('utf-8'))
def probe(self, ogRest):
- def ethtool(interface):
- try:
- ETHTOOL_GSET = 0x00000001
- SIOCETHTOOL = 0x8946
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sockfd = sock.fileno()
- ecmd = array.array(
- "B", struct.pack("I39s", ETHTOOL_GSET, b"\x00" * 39)
- )
- interface = interface.encode("utf-8")
- ifreq = struct.pack("16sP", interface, ecmd.buffer_info()[0])
- fcntl.ioctl(sockfd, SIOCETHTOOL, ifreq)
- res = ecmd.tobytes()
- speed = struct.unpack("12xH29x", res)[0]
- except IOError:
- speed = 0
- finally:
- sock.close()
- return speed
-
- interface = os.environ['DEVICE']
+
+ interface = os.getenv('DEVICE')
speed = ethtool(interface)
return {'status': 'OPG' if ogRest.state != ThreadState.BUSY else 'BSY',