From bb1ff4dc1d62be5249dd699bbba3c135fc40966c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20M=2E=20G=C3=B3mez?= Date: Wed, 20 Jun 2018 19:48:49 +0200 Subject: [PATCH] #750: OGAgent for ogLive looks for {{{oglive}}} environ variable; route {{{GET /getconfig}}} returns data in JSON format. --- .../modules/server/OpenGnSys/__init__.py | 40 ++++++++++++++++++- src/opengnsys/oglive/operations.py | 5 +-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/opengnsys/modules/server/OpenGnSys/__init__.py b/src/opengnsys/modules/server/OpenGnSys/__init__.py index e175bcf..c6bd951 100644 --- a/src/opengnsys/modules/server/OpenGnSys/__init__.py +++ b/src/opengnsys/modules/server/OpenGnSys/__init__.py @@ -43,6 +43,7 @@ from opengnsys import operations from opengnsys.log import logger from opengnsys.scriptThread import ScriptExecutorThread from opengnsys.workers import ServerWorker +from six.moves.urllib import parse @@ -94,6 +95,10 @@ class OpenGnSysWorker(ServerWorker): 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') + if operations.os_type == 'ogLive' and 'oglive' in os.environ: + # Replacing server IP if its running on ogLive clinet + logger.debug('Activating on ogLive client, new server is {}'.format(os.environ['oglive'])) + url = parse.urlsplit(url)._replace(netloc=os.environ['oglive']).geturl() self.REST = REST(url) # Get network interfaces until they are active or timeout (5 minutes) for t in range(0, 300): @@ -323,7 +328,38 @@ class OpenGnSysWorker(ServerWorker): :param server: :return: object """ + serialno = '' # Serial number + storage = [] # Storage configuration + warnings = 0 # Number of warnings logger.debug('Recieved getconfig operation') self.checkSecret(server) - # Returns raw data - return {'config': operations.get_disk_config()} + # Processing data + for row in operations.get_disk_config().strip().split(';'): + cols = row.split(':') + if len(cols) == 1: + if cols[0] != '': + # Serial number + serialno = cols[0] + else: + # Skip blank rows + pass + elif len(cols) == 7: + disk, npart, tpart, fs, os, size, usage = cols + try: + if int(npart) == 0: + # Disk information + storage.append({'disk': int(disk), 'parttable': int(tpart), 'size': int(size)}) + else: + # Partition information + storage.append({'disk': int(disk), 'partition': int(npart), 'parttype': tpart, + 'filesystem': fs, 'operatingsystem': os, 'size': int(size), + 'usage': int(usage)}) + except ValueError: + logger.warn('Configuration parameter error: {}'.format(cols)) + warnings += 1 + else: + # Logging warnings + logger.warn('Configuration data error: {}'.format(cols)) + warnings += 1 + # Returning configuration data and count of warnings + return {'serialno': serialno, 'storage': storage, 'warnings': warnings} diff --git a/src/opengnsys/oglive/operations.py b/src/opengnsys/oglive/operations.py index 6c67421..e24e0b9 100644 --- a/src/opengnsys/oglive/operations.py +++ b/src/opengnsys/oglive/operations.py @@ -181,9 +181,8 @@ def get_disk_config(): """ try: _exec_ogcommand('/opt/opengnsys/interfaceAdm/getConfiguration') - # Returns content of configuration file. - cfgdata = open('/tmp/getconfig', 'r').read() + # Returns content of configuration file + cfgdata = open('/tmp/getconfig', 'r').read().strip() except IOError: cfgdata = '' return cfgdata -