From 8d427bb0d0d4a99a4ed9c288078e7998fa9a918b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20M=2E=20G=C3=B3mez?= Date: Wed, 20 Jun 2018 20:25:30 +0200 Subject: [PATCH] #750: New route {{{GET /hardware}}}. --- .../modules/server/OpenGnSys/__init__.py | 15 ++++++++++++++- src/opengnsys/oglive/operations.py | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/opengnsys/modules/server/OpenGnSys/__init__.py b/src/opengnsys/modules/server/OpenGnSys/__init__.py index 2112160..25ca43f 100644 --- a/src/opengnsys/modules/server/OpenGnSys/__init__.py +++ b/src/opengnsys/modules/server/OpenGnSys/__init__.py @@ -353,7 +353,7 @@ class OpenGnSysWorker(ServerWorker): logger.debug('Recieved getconfig operation') self.checkSecret(server) # Processing data - for row in operations.get_disk_config().strip().split(';'): + for row in operations.get_configuration().split(';'): cols = row.split(':') if len(cols) == 1: if cols[0] != '': @@ -382,3 +382,16 @@ class OpenGnSysWorker(ServerWorker): warnings += 1 # Returning configuration data and count of warnings return {'serialno': serialno, 'storage': storage, 'warnings': warnings} + + def process_hardware(self, path, get_params, post_params, server): + """ + Returns client's hardware profile + :param path: + :param get_params: + :param post_params: + :param server: + """ + logger.debug('Recieved {} operation'.format(path)) + self.checkSecret(server) + # Returning raw data + return operations.get_hardware() diff --git a/src/opengnsys/oglive/operations.py b/src/opengnsys/oglive/operations.py index e24e0b9..b22a607 100644 --- a/src/opengnsys/oglive/operations.py +++ b/src/opengnsys/oglive/operations.py @@ -174,9 +174,9 @@ def poweroff(): _exec_ogcommand('/opt/opengnsys/scripts/poweroff') -def get_disk_config(): +def get_configuration(): """ - Returns disk configuration + Returns client's configuration Warning: this operation may take some time """ try: @@ -186,3 +186,17 @@ def get_disk_config(): except IOError: cfgdata = '' return cfgdata + + +def get_hardware(): + """ + Returns client's hardware list + """ + try: + filepath = _exec_ogcommand('/opt/opengnsys/scripts/listHardwareInfo').strip() + # Returns content of configuration file, skipping the header line and newline characters + with open(filepath, 'r') as f: + harddata = map(str.strip, f.readlines()[1:]) + except IOError: + harddata = '' + return harddata