diff --git a/src/opengnsys/modules/server/OpenGnSys/__init__.py b/src/opengnsys/modules/server/OpenGnSys/__init__.py index 8132acd..cb82cec 100644 --- a/src/opengnsys/modules/server/OpenGnSys/__init__.py +++ b/src/opengnsys/modules/server/OpenGnSys/__init__.py @@ -348,7 +348,7 @@ class OpenGnSysWorker(ServerWorker): serialno = '' # Serial number storage = [] # Storage configuration warnings = 0 # Number of warnings - logger.debug('Recieved getconfig operation') + logger.debug('Received getconfig operation') self.checkSecret(server) # Processing data for row in operations.get_configuration().split(';'): @@ -381,38 +381,70 @@ class OpenGnSysWorker(ServerWorker): # Returning configuration data and count of warnings return {'serialno': serialno, 'storage': storage, 'warnings': warnings} - def task_command(self, code, route): + def task_command(self, code, route, op_id): """ Task to execute a command :param code: Code to execute - :param route: server REST route to return results (including its parameters) + :param route: server callback REST route to return results + :param op_id: operation id. """ + # Executing command (stat, out, err) = operations.exec_command(code) - self.REST.sendMessage(route, {'status': stat, 'output': out, 'error': err}) + # Removing command from the list + for c in self.commands: + if c.has_key('id') and c['id'] == op_id: + self.commands.remove(c) + # Sending results + self.REST.sendMessage(route, {'id': op_id, 'status': stat, 'output': out, 'error': err}) def process_command(self, path, get_params, post_params, server): """ Launches a thread to executing a command :param path: ignored :param get_params: ignored - :param post_params: object with format {"id": OperationId, "code": "Code", url: "ReturnURL"} - :param server: ignored + :param post_params: object with format: + id: operation id. + code: command code + route: callback URL + :param server: headers data :rtype: object with launching status """ - logger.debug('Recieved command operation with params: {}'.format(post_params)) + logger.debug('Received command operation with params: {}'.format(post_params)) self.checkSecret(server) # Processing data try: code = post_params.get('code') - cmd_id = post_params.get('id') - route = '{}?id={}'.format(post_params.get('route'), cmd_id) - # Launching new thread - threading.Thread(target=self.task_command, args=(code, route)).start() + op_id = post_params.get('id') + route = post_params.get('route') + # Checking if the thread id. exists + for c in self.commands: + if c.has_key('id') and c['id'] == op_id: + raise Exception('Task id. already exists: {}'.format(op_id)) + # Launching a new thread + thr = threading.Thread(name=op_id, target=self.task_command, args=(code, route, op_id)) + thr.start() + self.commands.append({'id': op_id, 'code': code}) except Exception as e: logger.error('Got exception {}'.format(e)) return {'error': e} return {'op': 'launched'} + def process_execinfo(self, path, get_params, post_params, server): + """ + Returns running commands information + :param path: + :param get_params: + :param post_params: + :param server: + :return: object + """ + #data = [] + #for c in self.commands: + # if c.is_alive(): + # data.append({'name': c.getName(), 'code': c.__dict__['_Thread__args']}) + #return data + return self.commands + def process_hardware(self, path, get_params, post_params, server): """ Returns client's hardware profile diff --git a/src/opengnsys/operations.py b/src/opengnsys/operations.py index 2798cb1..4bba806 100644 --- a/src/opengnsys/operations.py +++ b/src/opengnsys/operations.py @@ -49,7 +49,7 @@ else: if os.path.exists('/scripts/oginit'): from .oglive.operations import * # @UnusedWildImport os_type = 'ogLive' - os_version = get_oglive_version() + os_version = get_oglive_version().replace(',', '') else: from .linux.operations import * # @UnusedWildImport os_type = 'Linux'