From f0c847c35fed20f47d45bb12b0944176fd21e054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20M=2E=20G=C3=B3mez?= Date: Thu, 21 Jun 2018 19:23:10 +0200 Subject: [PATCH] #750: Route {{{GET /getconfig}}} renamed as {{{GET /config}}}; route {{{GET /hardware}}} returns data in JSON format; new basic route {{{GET /software?disk=NDisk&part=NPart}}} --- .../modules/server/OpenGnSys/__init__.py | 27 ++++++++++++++++--- src/opengnsys/oglive/operations.py | 21 ++++++++++++++- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/opengnsys/modules/server/OpenGnSys/__init__.py b/src/opengnsys/modules/server/OpenGnSys/__init__.py index 9e8d8ef..45b0c6a 100644 --- a/src/opengnsys/modules/server/OpenGnSys/__init__.py +++ b/src/opengnsys/modules/server/OpenGnSys/__init__.py @@ -319,7 +319,7 @@ class OpenGnSysWorker(ServerWorker): def process_client_popup(self, params): self.REST.sendMessage('popup_done', params) - def process_getconfig(self, path, get_params, post_params, server): + def process_config(self, path, get_params, post_params, server): """ Returns client configuration :param path: @@ -372,7 +372,26 @@ class OpenGnSysWorker(ServerWorker): :param post_params: :param server: """ - logger.debug('Recieved {} operation'.format(path)) + data = [] + logger.debug('Recieved hardware operation') self.checkSecret(server) - # Returning raw data - return operations.get_hardware() + # Processing data + try: + for comp in operations.get_hardware(): + data.append({'component': comp.split('=')[0], 'value': comp.split('=')[1]}) + except: + pass + # Return list of hardware components + return data + + def process_software(self, path, get_params, post_params, server): + """ + Returns software profile installed on an operating system + :param path: + :param get_params: + :param post_params: + :param server: + :return: + """ + logger.debug('Recieved software operation with params: {}'.format(post_params)) + return operations.get_software(post_params['disk'], post_params['part']) diff --git a/src/opengnsys/oglive/operations.py b/src/opengnsys/oglive/operations.py index b22a607..5541780 100644 --- a/src/opengnsys/oglive/operations.py +++ b/src/opengnsys/oglive/operations.py @@ -164,7 +164,7 @@ def reboot(): def poweroff(): """ - Simple poweroff using OpenGnsys script + Simple power off using OpenGnsys script """ # Workaround for dummy thread if six.PY3 is False: @@ -178,6 +178,7 @@ def get_configuration(): """ Returns client's configuration Warning: this operation may take some time + :return: """ try: _exec_ogcommand('/opt/opengnsys/interfaceAdm/getConfiguration') @@ -191,6 +192,7 @@ def get_configuration(): def get_hardware(): """ Returns client's hardware list + :return: """ try: filepath = _exec_ogcommand('/opt/opengnsys/scripts/listHardwareInfo').strip() @@ -200,3 +202,20 @@ def get_hardware(): except IOError: harddata = '' return harddata + + +def get_software(disk, part): + """ + Returns software list installed on an operating system + :param disk: + :param part: + :return: + """ + try: + filepath = _exec_ogcommand('/opt/opengnsys/scripts/listSoftwareInfo {} {}'.format(disk, part)).strip() + # Returns content of configuration file, skipping the header line and newline characters + with open(filepath, 'r') as f: + softdata = map(str.strip, f.readlines()) + except IOError: + softdata = '' + return softdata