2 Run cumanage operations in an AWS hosted stack. 12 """ Run cumanage operations in an AWS hosted stack. """ 16 def setup_args(self, parser):
18 self.add_argument(
'proxyargs', nargs=argparse.REMAINDER)
20 '--passphrase', env=
'ODYSSEY_STACK_PASSPHRASE',
21 help=
'To avoid being prompted for a passphrase on protected' 22 'stacks, you can set it on the command line or via ' 23 'environment variables.')
27 help=
'Block and wait for the exit status of the cumanage task')
32 raise SystemExit(
'Stack not found: %s' % args.stack)
33 passphrase = stack.check_passphrase(args.passphrase)
34 wait_until_complete = args.check_exit_code
45 '''Check tasks exit codes on `cluster`''' 46 response = client.describe_tasks(cluster=cluster, tasks=task_arns)
47 tasks = response[
'tasks']
48 containers = [container
for containers
in (x[
'containers']
for x
in tasks)
49 for container
in containers]
50 exit_codes = [x.get(
'exitCode', -1)
for x
in containers]
51 for code
in exit_codes:
59 wait_until_complete=False,
61 '''Submit and run cumanage''' 62 if passphrase
is None:
64 client = boto3.client(
'ecs', region_name=stack.region)
65 taskdef =
'odyssey-%s-cumanage-tool' % stack.name
66 shellish.vtmlprint(
"<b>Submitting:</b> <blue>%s</blue>" %
69 "containerOverrides": [{
74 response = client.run_task(cluster=stack.cluster,
75 taskDefinition=taskdef,
77 stack.save(
'Ran cumanage: %s' %
' '.join(proxyargs), passphrase)
78 if wait_until_complete:
79 task_arns = [x[
'taskArn']
for x
in response[
'tasks']]
80 waiter = client.get_waiter(
'tasks_stopped')
81 if waiter.wait(cluster=stack.cluster, tasks=task_arns):
82 raise SystemExit(
'Task waiter timed out!')
def run_cumanage_task(stack, proxyargs, wait_until_complete=False, passphrase=None)
def task_exit_code(client, cluster, task_arns)
def add_stack_argument(self, *args, env=DEFAULT_STACK_ENV, help=None, metavar='STACK_NAME', **kwargs)
def get_stack(self, name)