Adding method comments

parent 873cfaf4
......@@ -9,10 +9,20 @@ import logging
@click.option("--role-arn", required=True, help="Role ARN which contains necessary assume permissions")
@click.pass_context
def update(ctx, region, role_arn):
"""
Update subcommand. Does nothing by itself except pass the global options through to it's
subcommands via ctx
"""
ctx.obj = {'region': region, 'role_arn': role_arn, 'log_level': ctx.obj.get('log_level')}
pass
def set_deploy_status(verb, region, role_arn, application, reset=None):
"""
Set the status of this deploy to started by setting a timestamp in the application's
deploying-status-APPLICATION_NAME SSM parameter
"""
aws_client = AWS_Client()
ssm_client = aws_client.create_client('ssm', region, role_arn)
ssm_parameter_name = "deploying-status-{}".format(application)
......@@ -43,6 +53,8 @@ def set_deploy_status(verb, region, role_arn, application, reset=None):
@click.pass_context
@click.option("--application-name", required=True, help="The application name (target group) to reset unlock for re-running the 'asg' subcommand on")
def reset(ctx, application_name):
""" Reset the deploy status of an application. Use with caution """
region = ctx.obj.get('region')
role_arn = ctx.obj.get('role_arn')
set_deploy_status("stop", region, role_arn, application_name, True)
......@@ -56,6 +68,18 @@ def reset(ctx, application_name):
@click.option("--scale-to", "scale_to", help="Optionally set the number for the ASG to scale back up to. Must in the form 'MIN_INT,MAX_INT,DESIRED_INT'")
@click.option("--skip-status-check", "skip_status_check", is_flag=True, default=False, help="When passed, skips checking if we're already in the middle of a deploy")
def asg(ctx, ami, lb, asg_name, target_group, scale_to, skip_status_check):
"""
Update an ASG by scaling it down and up again with the new launch template configuration. Can be
used in three different modes, the first two being geared towards blue/green deploys:
--lb: launch template will be worked out by querying the load balancer. Only applicable for load
balancers with a single ASG
--target-group: launch template will be worked out by querying the target group (then the load balancer).
Used when the load balancer is attached to more than one ASG
--asg: For when you already know which ASG you want to update. Used for non-blue/green deploys,
such as ASGs for workers
"""
if [lb, asg_name, target_group].count(None) < 2:
logging.error("--lb, --asg, and --target-group are mutually exclusive. Please use only one")
......@@ -81,25 +105,15 @@ def asg(ctx, ami, lb, asg_name, target_group, scale_to, skip_status_check):
asg.do_update()
exit(0)
@update.command()
@click.pass_context
@click.option("--active-asg", "active_asg", help="ASG we're updating -- mutually exclusive with --lb and --target-group")
@click.option("--skip-status-check", "skip_status_check", is_flag=True, default=False, help="When passed, skips checking if we're already in the middle of a deploy")
def scale_down_inactive(ctx, active_asg, skip_status_check):
region = ctx.obj.get('region')
role_arn = ctx.obj.get('role_arn')
from .asg import update_asg
asg = update_asg.ASG(ami=None, region=region, role_arn=role_arn, asg=active_asg)
asg.scale_down_inactive()
exit(0)
@update.command()
@click.pass_context
@click.option("--new", "new_asg_target", help="The ASG we're switching the LB to (attaching this ASG to the LB's targetgroup)")
def targetgroup(ctx, new_asg_target):
"""
Switch the load balancer to serve from a different ASG by attaching the new one and detaching the
old one, from the target group
"""
region = ctx.obj.get('region')
role_arn = ctx.obj.get('role_arn')
log_level = ctx.obj.get('log_level')
......@@ -115,3 +129,20 @@ def targetgroup(ctx, new_asg_target):
except Exception as e:
logging.error("{}".format(e))
exit(1)
@update.command()
@click.pass_context
@click.option("--active-asg", "active_asg", help="Name of the currently active ASG")
@click.option("--skip-status-check", "skip_status_check", is_flag=True, default=False, help="When passed, skips checking if we're already in the middle of a deploy")
def scale_down_inactive(ctx, active_asg, skip_status_check):
"""Given an active ASG, scale down the inactive one. Only useful for blue/green deploys"""
region = ctx.obj.get('region')
role_arn = ctx.obj.get('role_arn')
from .asg import update_asg
asg = update_asg.ASG(ami=None, region=region, role_arn=role_arn, asg=active_asg)
asg.scale_down_inactive()
exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment