Skip to content
Snippets Groups Projects
Commit 073d6835 authored by František Dvořák's avatar František Dvořák
Browse files

Orchestrator code cleanup - performing actions

parent 19655366
No related branches found
No related tags found
No related merge requests found
Pipeline #422 passed
...@@ -10,6 +10,20 @@ import time ...@@ -10,6 +10,20 @@ import time
DEFAULT_ACTIONS = ['files', 'ping', 'init', 'wait', 'deployment'] 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 = argparse.ArgumentParser(description='terraform cluster orchestrator')
parser.add_argument('-c', '--config', parser.add_argument('-c', '--config',
help='Terraform output for using by orchestrator (default: config.json)', help='Terraform output for using by orchestrator (default: config.json)',
...@@ -139,42 +153,18 @@ if 'init' in args.actions: ...@@ -139,42 +153,18 @@ if 'init' in args.actions:
commands += [ commands += [
['ansible', '-i', './inventory', '-m', 'copy', '-a', 'src=hosts dest=/etc/hosts', 'nodes'], ['ansible', '-i', './inventory', '-m', 'copy', '-a', 'src=hosts dest=/etc/hosts', 'nodes'],
] ]
if component: perform_action('init', commands)
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')
if 'wait' in args.actions: if 'wait' in args.actions:
print('== wait ==') print('== wait ==')
commands = [ commands = [
['ansible', '-i', './inventory', '-m', 'command', '-a', 'uname -a', 'all'], ['ansible', '-i', './inventory', '-m', 'command', '-a', 'uname -a', 'all'],
['ansible', '-i', './inventory', '-m', 'shell', '-a', ['ansible', '-i', './inventory', '-m', 'shell', '-a',
'while ! test -f /var/lib/cloud/instance/boot-finished; do sleep 2; done', 'all'], 'while ! test -f /var/lib/cloud/instance/boot-finished; do sleep 2; done', 'all'],
] ]
perform_action('wait', commands)
for cmd in commands:
print('-> %s' % ' '.join(cmd))
if not args.dry_run:
subprocess.run(cmd)
if component:
component.action('wait')
if 'deployment' in args.actions: if 'deployment' in args.actions:
print('== deployment ==') print('== deployment ==')
commands = [] commands = []
if component: perform_action('deployment', commands)
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')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment