#930: OGAgent `GET /script` route accepts a new optional `send_config` parameter to send back the client configuration after command execution.
commit
7b07f5c983
|
@ -68,6 +68,4 @@ ifeq ($(DISTRO),rh)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -rf $(LIBDIR)
|
rm -rf $(LIBDIR) $(CFGDIR) $(BINDIR)/ogagent $(INITDIR)/ogagent
|
||||||
# rm -f $(BINDIR)/ogagent
|
|
||||||
rm -rf $(CFGDIR)
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
interface = None # Bound interface for OpenGnsys
|
interface = None # Bound interface for OpenGnsys
|
||||||
REST = None # REST object
|
REST = None # REST object
|
||||||
logged_in = False # User session flag
|
logged_in = False # User session flag
|
||||||
locked = {} # Locked partitions
|
browser = {} # Browser info
|
||||||
commands = [] # Running commands
|
commands = [] # Running commands
|
||||||
random = None # Random string for secure connections
|
random = None # Random string for secure connections
|
||||||
length = 32 # Random string length
|
length = 32 # Random string length
|
||||||
|
@ -141,6 +141,7 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
:param route: server callback REST route to return results
|
:param route: server callback REST route to return results
|
||||||
:param code: code to execute
|
:param code: code to execute
|
||||||
:param op_id: operation id.
|
:param op_id: operation id.
|
||||||
|
:param send_config: indicate if client will send configuration data after command execution
|
||||||
"""
|
"""
|
||||||
menu_url = ''
|
menu_url = ''
|
||||||
# Show execution tacking log, if OGAgent runs on ogLive
|
# Show execution tacking log, if OGAgent runs on ogLive
|
||||||
|
@ -164,7 +165,7 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
if os_type == 'oglive':
|
if os_type == 'oglive':
|
||||||
# Send configuration data, if needed
|
# Send configuration data, if needed
|
||||||
if send_config:
|
if send_config:
|
||||||
self.REST.sendMessage('client/configs', {'mac': self.interface.mac, 'ip': self.interface.ip,
|
self.REST.sendMessage('ogagent/config', {'mac': self.interface.mac, 'ip': self.interface.ip,
|
||||||
'config': operations.get_configuration()})
|
'config': operations.get_configuration()})
|
||||||
self._launch_browser(menu_url)
|
self._launch_browser(menu_url)
|
||||||
|
|
||||||
|
@ -178,7 +179,7 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
# 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:
|
||||||
# Replacing server IP if its running on ogLive clinet
|
# Replacing server IP if it's running on ogLive clinet
|
||||||
logger.debug('Activating on ogLive client, new server is {}'.format(os.environ['oglive']))
|
logger.debug('Activating on ogLive client, new server is {}'.format(os.environ['oglive']))
|
||||||
url = parse.urlsplit(url)._replace(netloc=os.environ['oglive']).geturl()
|
url = parse.urlsplit(url)._replace(netloc=os.environ['oglive']).geturl()
|
||||||
if not url.endswith(os.path.sep):
|
if not url.endswith(os.path.sep):
|
||||||
|
@ -226,7 +227,8 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
# Completing OGAgent initialization process
|
# Completing OGAgent initialization process
|
||||||
os_type = operations.os_type.lower()
|
os_type = operations.os_type.lower()
|
||||||
if os_type == 'oglive':
|
if os_type == 'oglive':
|
||||||
# # Following code may be separated into a different function to launch browser while getting the disk configuration
|
# # Following code may be separated into a different function to launch the browser while getting the disk
|
||||||
|
# # configuration
|
||||||
message = """
|
message = """
|
||||||
<html>
|
<html>
|
||||||
<head></head>
|
<head></head>
|
||||||
|
@ -259,7 +261,7 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
f = open('/tmp/init.html', 'w')
|
f = open('/tmp/init.html', 'w')
|
||||||
f.write(message)
|
f.write(message)
|
||||||
f.close()
|
f.close()
|
||||||
# Launch the Browser
|
# Launching the Browser
|
||||||
self._launch_browser('/tmp/init.html')
|
self._launch_browser('/tmp/init.html')
|
||||||
config = operations.get_configuration()
|
config = operations.get_configuration()
|
||||||
self.REST.sendMessage('ogagent/config', {'mac': self.interface.mac, 'ip': self.interface.ip,
|
self.REST.sendMessage('ogagent/config', {'mac': self.interface.mac, 'ip': self.interface.ip,
|
||||||
|
@ -403,6 +405,7 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
id: operation id.
|
id: operation id.
|
||||||
script: command code
|
script: command code
|
||||||
redirect_url: callback REST route
|
redirect_url: callback REST route
|
||||||
|
send_config: flag to send client's configuration after command execution (optional)
|
||||||
:param server: headers data
|
:param server: headers data
|
||||||
:rtype: JSON object with launching status
|
:rtype: JSON object with launching status
|
||||||
"""
|
"""
|
||||||
|
@ -412,13 +415,14 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
script = urllib.unquote(post_params.get('script').decode('base64')).decode('utf8')
|
script = urllib.unquote(post_params.get('script').decode('base64')).decode('utf8')
|
||||||
op_id = post_params.get('id')
|
op_id = post_params.get('id')
|
||||||
route = post_params.get('redirect_uri')
|
route = post_params.get('redirect_uri')
|
||||||
|
send_config = (post_params.get('send_config', 'false') == 'true')
|
||||||
# Checking if the thread id. exists
|
# Checking if the thread id. exists
|
||||||
for c in self.commands:
|
for c in self.commands:
|
||||||
if c.getName() == str(op_id):
|
if c.getName() == str(op_id):
|
||||||
raise Exception('Task id. already exists: {}'.format(op_id))
|
raise Exception('Task id. already exists: {}'.format(op_id))
|
||||||
if post_params.get('client', 'false') == 'false':
|
if post_params.get('client', 'false') == 'false':
|
||||||
# Launching a new thread
|
# Launching a new thread
|
||||||
thr = threading.Thread(name=op_id, target=self._task_command, args=(route, script, op_id))
|
thr = threading.Thread(name=op_id, target=self._task_command, args=(route, script, op_id, send_config))
|
||||||
thr.start()
|
thr.start()
|
||||||
self.commands.append(thr)
|
self.commands.append(thr)
|
||||||
else:
|
else:
|
||||||
|
@ -517,7 +521,16 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
|
|
||||||
@check_secret
|
@check_secret
|
||||||
def process_stopcmd(self, path, get_params, post_params, server):
|
def process_stopcmd(self, path, get_params, post_params, server):
|
||||||
|
"""
|
||||||
|
Stops a running process identified by its trace id.
|
||||||
|
:param path:
|
||||||
|
:param get_params:
|
||||||
|
:param post_params: JSON object {"trace": trace_id}
|
||||||
|
:param server: authorization header
|
||||||
|
:return: JSON object: {"stopped": trace_id}
|
||||||
|
"""
|
||||||
logger.debug('Received stopcmd operation with params {}:'.format(post_params))
|
logger.debug('Received stopcmd operation with params {}:'.format(post_params))
|
||||||
|
# Find operation id. and stop the thread
|
||||||
op_id = post_params.get('trace')
|
op_id = post_params.get('trace')
|
||||||
for c in self.commands:
|
for c in self.commands:
|
||||||
if c.is_alive() and c.getName() == str(op_id):
|
if c.is_alive() and c.getName() == str(op_id):
|
||||||
|
@ -537,7 +550,6 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
"""
|
"""
|
||||||
data = []
|
data = []
|
||||||
logger.debug('Received hardware operation')
|
logger.debug('Received hardware operation')
|
||||||
self.checkSecret(server)
|
|
||||||
# Processing data
|
# Processing data
|
||||||
try:
|
try:
|
||||||
for comp in operations.get_hardware():
|
for comp in operations.get_hardware():
|
||||||
|
|
Loading…
Reference in New Issue