summaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorRamón M. Gómez <ramongomez@us.es>2019-05-20 14:21:48 +0200
committerRamón M. Gómez <ramongomez@us.es>2019-05-20 14:21:48 +0200
commit4ec0dd160a0f0c3f9b718193f94d66d9f0e79eaa (patch)
treeae579358a4a957249d22d9abe272376d09fb1e96 /admin
parentaf25f93792a18a65a6b7832a8e33b287de92d6b5 (diff)
#913: Adding loop to connect to the server when OGAgent is activated.
Diffstat (limited to 'admin')
-rw-r--r--admin/Sources/Clients/ogagent/src/opengnsys/modules/server/OpenGnSys/__init__.py19
1 files changed, 15 insertions, 4 deletions
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 1438e469..721343a9 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
@@ -80,6 +80,8 @@ class OpenGnSysWorker(ServerWorker):
Sends OGAgent activation notification to OpenGnsys server
'''
self.cmd = None
+ # 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
self.REST = REST(self.service.config.get('opengnsys', 'remote'))
# Get network interfaces until they are active or timeout (5 minutes)
@@ -98,16 +100,25 @@ 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:
+ self.REST.sendMessage('ogagent/started', {'mac': self.interface.mac, 'ip': self.interface.ip,
+ 'secret': self.random, 'ostype': operations.osType,
+ 'osversion': operations.osVersion})
+ 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:
os.remove(os.sep + f)
except OSError:
pass
- # Generate random secret to send on activation
- self.random = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(self.length))
- # Send initalization message
- self.REST.sendMessage('ogagent/started', {'mac': self.interface.mac, 'ip': self.interface.ip, 'secret': self.random, 'ostype': operations.osType, 'osversion': operations.osVersion})
def onDeactivation(self):
'''