3 HomeCU tool for interacting with schedulers for stacks 9 from .
import s3, base, cloudformation
13 '''Manage stack scheduler''' 15 allowed_states = {
'active'}
17 def setup_args(self, parser):
18 self.add_subcommand(ReloadCommand)
22 """ Reload Scheduler of an Odyssey stack""" 26 allowed_states = {
'active'}
28 def setup_args(self, parser):
30 self.add_argument(
'--verbose',
'-v', action=
'store_true')
31 self.add_argument(
'--passphrase', env=
'ODYSSEY_STACK_PASSPHRASE',
32 help=
'To avoid being prompted for a passphrase on ' 33 'protected stacks, you can set it on the command ' 34 'line or via the env.')
39 raise SystemExit(
'Stack not found: %s' % args.stack)
40 stack.check_passphrase(args.passphrase)
43 shellish.vtmlprint(
"restarting scheduler for %s..." % stack.name)
45 shellish.vtmlprint(
"done.")
46 except Exception
as ex:
49 stack.update_state(
'partial_deploy')
50 stack._save(
'Restart of scheduler resulted in errors')
53 stack.update_state(
'active')
54 stack._save(
'Restarted scheduler service')
57 '''Restart scheduler service for stack''' 58 client = boto3.client(
'ecs', region_name=stack.region)
59 cluster = stack.cluster
60 cfn_stack = cloudformation.describe_stack(stack)
61 services = [x[
'OutputValue']
for x
in cfn_stack[
'Outputs']
62 if 'Service' in x[
'OutputKey']]
63 sched_service = [x
for x
in services
if 'sched' in x.lower()][-1]
68 reason=
'Restarting scheduler, reloading crontab' 72 '''return task arns for service''' 73 response = client.list_tasks(cluster=cluster, serviceName=service)
74 if response[
'ResponseMetadata'][
'HTTPStatusCode'] != 200:
75 shellish.vtmlprint(
"<red>Error while getting tasks</red>")
77 return response[
'taskArns']
80 def cmd(*args, verbose=False):
81 cmd =
' '.join(map(str, args))
82 shellish.vtmlprint(
"<b>Running:</b> <blue>%s</blue>" % cmd)
85 subprocess.check_call(cmd, shell=
True)
def get_service_task_arns(self, client, cluster, service)
def restart_scheduler(self, args, stack)
def add_stack_argument(self, *args, env=DEFAULT_STACK_ENV, help=None, metavar='STACK_NAME', **kwargs)
def get_stack(self, name)
def check_requirements(self, stack)