2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-06-02 00:08:35 +00:00

Add expression support to the nodeconsole automation

This commit is contained in:
Jarrod Johnson
2026-05-11 16:51:01 -04:00
parent a537a7ba5c
commit eebc4ed3c7
+14 -4
View File
@@ -867,7 +867,7 @@ automation_map = {
'<tab>': '\t',
}
def parse_automation_script(script):
def parse_automation_script(script, session_node):
global current_automation_directive
for line in script.splitlines():
line = line.strip()
@@ -896,6 +896,14 @@ def parse_automation_script(script):
for key, value in automation_map.items():
arg = arg.replace(key, value)
arg = re.sub(r'<env:(\w+)>', lambda m: os.environ[m.group(1)], arg)
if '{' in arg: # support confluent expressions
for res in session.create('/nodes/{0}/attributes/expression'.format(session_node),
{'expression': arg}):
if 'error' in res:
sys.stderr.write(res['error'] + '\n')
sys.exit(1)
if 'value' in res:
arg = res['value']
automation_directives.append((directive, arg))
if automation_directives:
current_automation_directive = automation_directives.pop(0)
@@ -916,9 +924,7 @@ parser.add_option(
'terminal from closing quickly on error)')
opts, shellargs = parser.parse_args()
if opts.automation:
with open(opts.automation) as f:
parse_automation_script(f.read())
username = None
@@ -973,6 +979,7 @@ def main():
# sys.stdout.write('\x1b[H\x1b[J')
# sys.stdout.flush()
global powerstate, powertime, clearpowermessage
if sys.stdout.isatty():
@@ -989,6 +996,9 @@ def main():
targ, session_node = get_session_node(shellargs)
if session_node is not None:
consoleonly = True
if opts.automation:
with open(opts.automation) as f:
parse_automation_script(f.read(), session_node)
do_command("start %s" % targ, netserver)
doexit = True
elif shellargs: