From 1fdd6405291d737085b59a6677e5e66b71af4224 Mon Sep 17 00:00:00 2001 From: "Ramón M. Gómez" Date: Mon, 20 May 2019 14:21:48 +0200 Subject: Refs #913: Adding loop to connect to the server when OGAgent is activated. --- .../opengnsys/modules/server/OpenGnSys/__init__.py | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/admin/Sources/Clients/ogagent/src/opengnsys/modules/server/OpenGnSys/__init__.py b/admin/Sources/Clients/ogagent/src/opengnsys/modules/server/OpenGnSys/__init__.py index ab31fb39..c55609a5 100644 --- a/admin/Sources/Clients/ogagent/src/opengnsys/modules/server/OpenGnSys/__init__.py +++ b/admin/Sources/Clients/ogagent/src/opengnsys/modules/server/OpenGnSys/__init__.py @@ -174,6 +174,9 @@ class OpenGnSysWorker(ServerWorker): """ Sends OGAgent activation notification to OpenGnsys server """ + t = 0 + # Generate random secret to send on activation + self.random = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(self.length)) # Ensure cfg has required configuration variables or an exception will be thrown url = self.service.config.get('opengnsys', 'remote') server_client = self.service.config.get('opengnsys', 'client') @@ -201,6 +204,28 @@ class OpenGnSysWorker(ServerWorker): # Raise error after timeout if not self.interface: raise e + # Loop to send initialization message + for t in range(0, 100): + try: + try: + self.REST.sendMessage('ogagent/started', {'mac': self.interface.mac, 'ip': self.interface.ip, + 'secret': self.random, 'ostype': operations.os_type, + 'osversion': operations.os_version}) + break + except: + # Trying to initialize on alternative server, if defined + # (used in "exam mode" from the University of Seville) + self.REST = REST(self.service.config.get('opengnsys', 'altremote')) + self.REST.sendMessage('ogagent/started', {'mac': self.interface.mac, 'ip': self.interface.ip, + 'secret': self.random, 'ostype': operations.os_type, + 'osversion': operations.os_version, 'alt_url': True}) + break + except: + time.sleep(3) + if 0 < t < 100: + logger.debug("Successful connection after {} tries".format(t)) + elif t == 100: + raise Exception('Initialization error: Cannot connect to remote server') # Delete marking files for f in ['ogboot.me', 'ogboot.firstboot', 'ogboot.secondboot']: try: -- cgit v1.2.3-18-g5258