#750: Adapting route {{GET /command}}} parameters.
parent
3806f120c6
commit
91bdf9040d
|
@ -85,6 +85,7 @@ def check_locked_partition(sync=False):
|
||||||
class OpenGnSysWorker(ServerWorker):
|
class OpenGnSysWorker(ServerWorker):
|
||||||
name = 'opengnsys'
|
name = 'opengnsys'
|
||||||
interface = None # Binded interface for OpenGnsys
|
interface = None # Binded interface for OpenGnsys
|
||||||
|
REST = None # REST object
|
||||||
loggedin = False # User session flag
|
loggedin = False # User session flag
|
||||||
locked = {} # Locked partitions
|
locked = {} # Locked partitions
|
||||||
commands = [] # Running commands
|
commands = [] # Running commands
|
||||||
|
@ -106,7 +107,6 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
"""
|
"""
|
||||||
Sends OGAgent activation notification to OpenGnsys server
|
Sends OGAgent activation notification to OpenGnsys server
|
||||||
"""
|
"""
|
||||||
self.cmd = None
|
|
||||||
# Ensure cfg has required configuration variables or an exception will be thrown
|
# Ensure cfg has required configuration variables or an exception will be thrown
|
||||||
url = self.service.config.get('opengnsys', 'remote')
|
url = self.service.config.get('opengnsys', 'remote')
|
||||||
if operations.os_type == 'ogLive' and 'oglive' in os.environ:
|
if operations.os_type == 'ogLive' and 'oglive' in os.environ:
|
||||||
|
@ -337,10 +337,11 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
(stat, out, err) = operations.exec_command(code)
|
(stat, out, err) = operations.exec_command(code)
|
||||||
# Removing command from the list
|
# Removing command from the list
|
||||||
for c in self.commands:
|
for c in self.commands:
|
||||||
if c.has_key('id') and c['id'] == op_id:
|
if c.getName() == op_id:
|
||||||
self.commands.remove(c)
|
self.commands.remove(c)
|
||||||
# Sending results
|
# Sending results
|
||||||
self.REST.sendMessage(route, {'id': op_id, 'status': stat, 'output': out, 'error': err})
|
self.REST.sendMessage(route, {'client': self.interface.ip, 'trace': 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):
|
||||||
"""
|
"""
|
||||||
|
@ -349,8 +350,8 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
:param get_params: ignored
|
:param get_params: ignored
|
||||||
:param post_params: object with format:
|
:param post_params: object with format:
|
||||||
id: operation id.
|
id: operation id.
|
||||||
code: command code
|
script: command code
|
||||||
route: callback URL
|
redirect_url: callback REST route
|
||||||
:param server: headers data
|
:param server: headers data
|
||||||
:rtype: object with launching status
|
:rtype: object with launching status
|
||||||
"""
|
"""
|
||||||
|
@ -358,17 +359,17 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
self.checkSecret(server)
|
self.checkSecret(server)
|
||||||
# Processing data
|
# Processing data
|
||||||
try:
|
try:
|
||||||
code = post_params.get('code')
|
script = post_params.get('script')
|
||||||
op_id = post_params.get('id')
|
op_id = post_params.get('id')
|
||||||
route = post_params.get('route')
|
route = post_params.get('redirect_url')
|
||||||
# Checking if the thread id. exists
|
# Checking if the thread id. exists
|
||||||
for c in self.commands:
|
for c in self.commands:
|
||||||
if c.has_key('id') and c['id'] == op_id:
|
if c.getName() == op_id:
|
||||||
raise Exception('Task id. already exists: {}'.format(op_id))
|
raise Exception('Task id. already exists: {}'.format(op_id))
|
||||||
# Launching a new thread
|
# Launching a new thread
|
||||||
thr = threading.Thread(name=op_id, target=self.task_command, args=(code, route, op_id))
|
thr = threading.Thread(name=op_id, target=self.task_command, args=(script, route, op_id))
|
||||||
thr.start()
|
thr.start()
|
||||||
self.commands.append({'id': op_id, 'code': code})
|
self.commands.append(thr)
|
||||||
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}
|
||||||
|
@ -383,12 +384,14 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
:param server:
|
:param server:
|
||||||
:return: object
|
:return: object
|
||||||
"""
|
"""
|
||||||
#data = []
|
data = []
|
||||||
#for c in self.commands:
|
logger.debug('Received execinfo operation')
|
||||||
# if c.is_alive():
|
self.checkSecret(server)
|
||||||
# data.append({'name': c.getName(), 'code': c.__dict__['_Thread__args']})
|
# Returning the arguments of all running threads
|
||||||
#return data
|
for c in self.commands:
|
||||||
return self.commands
|
if c.is_alive():
|
||||||
|
data.append(c.__dict__['_Thread__args'])
|
||||||
|
return data
|
||||||
|
|
||||||
def process_hardware(self, path, get_params, post_params, server):
|
def process_hardware(self, path, get_params, post_params, server):
|
||||||
"""
|
"""
|
||||||
|
@ -399,7 +402,7 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
:param server:
|
:param server:
|
||||||
"""
|
"""
|
||||||
data = []
|
data = []
|
||||||
logger.debug('Recieved hardware operation')
|
logger.debug('Received hardware operation')
|
||||||
self.checkSecret(server)
|
self.checkSecret(server)
|
||||||
# Processing data
|
# Processing data
|
||||||
try:
|
try:
|
||||||
|
@ -419,5 +422,5 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
:param server:
|
:param server:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
logger.debug('Recieved software operation with params: {}'.format(post_params))
|
logger.debug('Received software operation with params: {}'.format(post_params))
|
||||||
return operations.get_software(post_params.get('disk'), post_params.get('part'))
|
return operations.get_software(post_params.get('disk'), post_params.get('part'))
|
||||||
|
|
Loading…
Reference in New Issue