From fc2b4b145fd6d15344fd692395d41bd11bb0d457 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Wed, 13 Sep 2023 10:52:21 +0200 Subject: ogClient: add supported events to live mode 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. --- src/ogClient.py | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'src/ogClient.py') 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 = "" -- cgit v1.2.3-18-g5258