summaryrefslogtreecommitdiffstats
path: root/src/live/ogOperations.py
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2021-05-04 15:42:44 +0000
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-05-04 18:30:40 +0200
commitbd98dd1da0fb1fed0066bb9477c78a2569bd547b (patch)
tree9c5b254910421f6a6b6b18754f37854b10be3eec /src/live/ogOperations.py
parent8b959c8be9639ac481be528ba8bc5a98f1cf51b2 (diff)
#995 Add link speed in probe responses
Separates probe method into separate ogclient modes (virtual, vdi) so future supported OS can easily have a tailored probe responses. Link speed is retrieved using a minimal ethtool command sent using fcntl module from python.
Diffstat (limited to 'src/live/ogOperations.py')
-rw-r--r--src/live/ogOperations.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index 6904164..7f5e2e4 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -9,7 +9,9 @@
import os
import json
import subprocess
+import fcntl, socket, array, struct
from src.ogClient import ogClient
+from src.ogRest import ThreadState
OG_SHELL = '/bin/bash'
@@ -276,3 +278,30 @@ class OgLiveOperations:
self._restartBrowser(self._url)
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']
+ speed = ethtool(interface)
+
+ return {'status': 'OPG' if ogRest.state != ThreadState.BUSY else 'BSY',
+ 'speed': speed}