From 073d68358c4a3fb089631fa83b3d135824108cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= <valtri@civ.zcu.cz> Date: Wed, 23 Dec 2020 23:50:48 +0100 Subject: [PATCH] Orchestrator code cleanup - performing actions --- orchestrate.py | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/orchestrate.py b/orchestrate.py index 7a75d74..08d9820 100755 --- a/orchestrate.py +++ b/orchestrate.py @@ -10,6 +10,20 @@ import time DEFAULT_ACTIONS = ['files', 'ping', 'init', 'wait', 'deployment'] + +def perform_action(action, commands): + if component: + plugin_commands = component.commands(action) + if plugin_commands: + commands += plugin_commands + for cmd in commands: + print('-> %s' % ' '.join(cmd)) + if not args.dry_run: + subprocess.run(cmd) + if component: + component.action(action) + + parser = argparse.ArgumentParser(description='terraform cluster orchestrator') parser.add_argument('-c', '--config', help='Terraform output for using by orchestrator (default: config.json)', @@ -139,42 +153,18 @@ if 'init' in args.actions: commands += [ ['ansible', '-i', './inventory', '-m', 'copy', '-a', 'src=hosts dest=/etc/hosts', 'nodes'], ] - if component: - commands += component.commands('init') - - for cmd in commands: - print('-> %s' % ' '.join(cmd)) - if not args.dry_run: - subprocess.run(cmd) - if component: - component.action('init') + perform_action('init', commands) if 'wait' in args.actions: print('== wait ==') - commands = [ ['ansible', '-i', './inventory', '-m', 'command', '-a', 'uname -a', 'all'], ['ansible', '-i', './inventory', '-m', 'shell', '-a', 'while ! test -f /var/lib/cloud/instance/boot-finished; do sleep 2; done', 'all'], ] - - for cmd in commands: - print('-> %s' % ' '.join(cmd)) - if not args.dry_run: - subprocess.run(cmd) - if component: - component.action('wait') + perform_action('wait', commands) if 'deployment' in args.actions: print('== deployment ==') - commands = [] - if component: - commands += component.commands('deployment') - - for cmd in commands: - print('-> %s' % ' '.join(cmd)) - if not args.dry_run: - subprocess.run(cmd) - if component: - component.action('deployment') + perform_action('deployment', commands) -- GitLab