diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2023-09-13 10:52:21 +0200 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2023-10-05 16:33:00 +0200 |
commit | fc2b4b145fd6d15344fd692395d41bd11bb0d457 (patch) | |
tree | db3e986e60204a3c471cc62d5f703a22946aa63c /src | |
parent | 1e92aa42628f87756a3ead40054c612b0c6741c2 (diff) |
ogClient: add supported events to live modemore_events
Live mode supports poweroff, reboot and boot events. This events serve
to send out-of-band requests to ogClient in order to run any of the
supported processes.
Live mode does not support any event datagram related to user session
notification.
XXX: Check if client is busy before processing the event.
Diffstat (limited to 'src')
-rw-r--r-- | src/ogClient.py | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/ogClient.py b/src/ogClient.py index c4dcd7e..9f914c4 100644 --- a/src/ogClient.py +++ b/src/ogClient.py @@ -60,21 +60,47 @@ class ogClient: def send_event_hint(self, message): try: - event, action, user = message.split(" ") - logging.debug('Sending event: %s, %s, %s', event, action, user) + event = message.split(' ', 1)[0] except: - logging.warning('Error parsing session datagram') + logging.exception('Error parsing event from datagram') return - if (event != "session" or - action not in ['start', 'stop'] or - not user): - logging.warning('Invalid value in session datagram: %s', message) + if (self.mode == 'live' and + event not in ['boot', 'poweroff', 'reboot']): + logging.warning('Unsupported event for live mode') + logging.warning(f'Parsed event: {event}') + logging.warning(f'Received message: {message}') + return + elif (self.mode in ['windows', 'linux'] and + event != 'session'): + logging.warning('Unsupported event for windows/linux mode') + logging.warning(f'Received event: {message}') + return - payload = jsonBody({'event': event, 'action': action, 'user': user}) - response = restResponse(ogResponses.EARLY_HINTS, payload) - self.send(response.get()) - logging.debug('Sending event OK') + payload = jsonBody({'event': event}) + + if event == 'session': + try: + _, action, user = message.split(' ') + except: + logging.exception('Error parsing rest of session event datagram') + return + payload = jsonBody({'event': event, 'action': action, 'user': user}) + response = restResponse(ogResponses.EARLY_HINTS, payload) + self.send(response.get()) + elif event == 'boot': + request = restRequest() + try: + _, disk, partition = message.split(' ') + request.disk = disk + request.partition = partition + self.ogrest.operations.session(request, self.ogrest) + except: + logging.exception('Error parsing rest of boot event datagram') + elif event == 'poweroff': + self.ogrest.operations.poweroff() + elif event == 'reboot': + self.ogrest.operations.reboot() def cleanup(self): self.data = "" |