#750: Simple REST route to get the list of running commands.
parent
dfd2c05275
commit
dcc3b83968
|
@ -388,38 +388,70 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
# Returning configuration data and count of warnings
|
# Returning configuration data and count of warnings
|
||||||
return {'serialno': serialno, 'storage': storage, 'warnings': 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
|
Task to execute a command
|
||||||
:param code: Code to execute
|
: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)
|
(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):
|
def process_command(self, path, get_params, post_params, server):
|
||||||
"""
|
"""
|
||||||
Launches a thread to executing a command
|
Launches a thread to executing a command
|
||||||
:param path: ignored
|
:param path: ignored
|
||||||
:param get_params: ignored
|
:param get_params: ignored
|
||||||
:param post_params: object with format {"id": OperationId, "code": "Code", url: "ReturnURL"}
|
:param post_params: object with format:
|
||||||
:param server: ignored
|
id: operation id.
|
||||||
|
code: command code
|
||||||
|
route: callback URL
|
||||||
|
:param server: headers data
|
||||||
:rtype: object with launching status
|
: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)
|
self.checkSecret(server)
|
||||||
# Processing data
|
# Processing data
|
||||||
try:
|
try:
|
||||||
code = post_params.get('code')
|
code = post_params.get('code')
|
||||||
cmd_id = post_params.get('id')
|
op_id = post_params.get('id')
|
||||||
route = '{}?id={}'.format(post_params.get('route'), cmd_id)
|
route = post_params.get('route')
|
||||||
# Launching new thread
|
# Checking if the thread id. exists
|
||||||
threading.Thread(target=self.task_command, args=(code, route)).start()
|
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:
|
except Exception as e:
|
||||||
logger.error('Got exception {}'.format(e))
|
logger.error('Got exception {}'.format(e))
|
||||||
return {'error': e}
|
return {'error': e}
|
||||||
return {'op': 'launched'}
|
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):
|
def process_hardware(self, path, get_params, post_params, server):
|
||||||
"""
|
"""
|
||||||
Returns client's hardware profile
|
Returns client's hardware profile
|
||||||
|
|
|
@ -49,7 +49,7 @@ else:
|
||||||
if os.path.exists('/scripts/oginit'):
|
if os.path.exists('/scripts/oginit'):
|
||||||
from .oglive.operations import * # @UnusedWildImport
|
from .oglive.operations import * # @UnusedWildImport
|
||||||
os_type = 'ogLive'
|
os_type = 'ogLive'
|
||||||
os_version = get_oglive_version()
|
os_version = get_oglive_version().replace(',', '')
|
||||||
else:
|
else:
|
||||||
from .linux.operations import * # @UnusedWildImport
|
from .linux.operations import * # @UnusedWildImport
|
||||||
os_type = 'Linux'
|
os_type = 'Linux'
|
||||||
|
|
Loading…
Reference in New Issue