diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/live/ogOperations.py | 29 | ||||
-rw-r--r-- | src/ogRest.py | 14 | ||||
-rw-r--r-- | src/virtual/ogOperations.py | 3 |
3 files changed, 41 insertions, 5 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} diff --git a/src/ogRest.py b/src/ogRest.py index bd9b65c..32519fc 100644 --- a/src/ogRest.py +++ b/src/ogRest.py @@ -373,16 +373,20 @@ class ogRest(): threading.Thread(target=ogThread.poweroff, args=(self,)).start() def process_probe(self, client): + try: + status = self.operations.probe(self) + except: + response = restResponse(ogResponses.INTERNAL_ERR) + client.send(response.get()) + return + json_body = jsonBody() + for k, v in status.items(): + json_body.add_element(k, v) if self.state != ThreadState.BUSY: - if self.mode == 'live': - json_body.add_element('status', 'OPG') - elif self.mode == 'virtual': - json_body.add_element('status', 'VDI') response = restResponse(ogResponses.OK, json_body) else: - json_body.add_element('status', 'BSY') response = restResponse(ogResponses.IN_PROGRESS, json_body) client.send(response.get()) diff --git a/src/virtual/ogOperations.py b/src/virtual/ogOperations.py index 60370cb..94f3e1b 100644 --- a/src/virtual/ogOperations.py +++ b/src/virtual/ogOperations.py @@ -600,3 +600,6 @@ class OgVirtualOperations: for k, v in device_names.items(): f.write(f'{k}={v}\n') f.truncate() + + def probe(self, ogRest): + return {'status': 'VDI' if ogRest.state != ThreadState.BUSY else 'BSY'} |