2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-21 17:11:58 +00:00

Wire up client retrieval of remoteconfig

remoteconfig can now watch for completion and return
data to client
This commit is contained in:
Jarrod Johnson 2021-03-17 17:46:27 -04:00
parent 98d14344ce
commit df97e808c6
2 changed files with 41 additions and 3 deletions

View File

@ -21,6 +21,7 @@ except ImportError:
pass
import eventlet
import eventlet.green.subprocess as subprocess
import json
import msgpack
import os
import struct
@ -43,6 +44,34 @@ class PlayRunner(object):
self.results = []
return avail
def dump_text(self):
retinfo = self.dump_dict()
textout = ''
for result in retinfo['results']:
textout += 'TASK [{}] *******************************\n'.format(
result['task_name'])
for warning in result['warnings']:
textout += '[WARNING]: ' + warning + '\n'
if 'errorinfo' in result:
textout += '{} => {}\n'.format(result['state'],
result['errorinfo'])
else:
if result['changed']:
textout += 'changed\n'
else:
textout += result['state'] + '\n'
textout += '\n'
return textout
def dump_json(self):
return json.dumps(self.dump_dict())
def dump_dict(self):
return {
'complete': self.complete,
'results': self.get_available_results()
}
def _really_run_playbooks(self):
with open(os.devnull, 'w+') as devnull:
targnodes = ','.join(self.nodes)
@ -69,7 +98,7 @@ def run_playbooks(playfiles, nodes):
runner._start_playbooks()
def print_result(result, state, collector):
def print_result(result, state, collector=None):
output = {
'task_name': result.task_name,
'changed': result._result['changed'],
@ -104,7 +133,7 @@ if __name__ == '__main__':
print_result(result, 'UNREACHABLE', self)
def v2_runner_on_ok(self, result, *args, **kwargs):
print_result(result, 'ok', self)
print_result(result, 'ok')
def v2_runner_on_failed(self, result, *args, **kwargs):
print_result(result, 'FAILED', self)

View File

@ -282,7 +282,16 @@ def handle_request(env, start_response):
yield ''
return
elif env['PATH_INFO'].startswith('/self/remoteconfig/status'):
scriptcat = env['PATH_INFO'].replace('/self/remoteconfig/', '')
rst = runansible.running_status.get(nodename, None)
if not rst:
start_response('204 Not Running', ())
yield ''
return
start_response('200 OK', ())
if rst.complete:
del runansible.running_status[nodename]
yield rst.dump_text()
return
elif env['PATH_INFO'].startswith('/self/scriptlist/'):
scriptcat = env['PATH_INFO'].replace('/self/scriptlist/', '')
slist, _ = get_scriptlist(