--scale-to shouldn't be here

parent 185419c6
......@@ -13,14 +13,12 @@ aws_client = AWS_Client()
class ASG():
"""All the methods needed to perform a blue/green deploy"""
def __init__(self, ami, region, role_arn, loadbalancer=None, asg=None, target_group=None, scale_to=None):
def __init__(self, region, role_arn, loadbalancer=None, asg=None, target_group=None):
self.loadbalancer = loadbalancer
self.ami = ami
self.region = region
self.role_arn = role_arn
self.asg = asg
self.target_group = target_group
self.scale_to = scale_to if scale_to else None
def get_application_name(self):
"""
......@@ -58,17 +56,15 @@ class ASG():
inactive_asg = self.get_inactive_asg(self.asg)
self.scale(inactive_asg, 0, 0, 0)
def do_update(self):
def do_update(self, ami):
inactive_asg = self.asgs_by_liveness()['inactive_asg']
active_asg = self.asgs_by_liveness()['active_asg']
new_ami = self.ami
new_ami = ami
logging.info("New ASG was worked out as {}. Now updating it's Launch Template".format(inactive_asg))
self.update_launch_template(inactive_asg, new_ami, self.get_lt_name(inactive_asg))
# Honour self.scale_to values if present
if not self.scale_to:
self.scale_to = self.get_current_scale(active_asg)
scale_to = self.get_current_scale(active_asg)
logging.info("Scaling ASG down")
self.scale(inactive_asg, 0, 0, 0)
......@@ -79,9 +75,9 @@ class ASG():
logging.info("Scaling ASG back up")
self.scale(
auto_scaling_group_id = inactive_asg,
min_size = self.scale_to['min'],
max_size = self.scale_to['max'],
desired = self.scale_to['capacity']
min_size = scale_to['min'],
max_size = scale_to['max'],
desired = scale_to['capacity']
)
while len(self.get_auto_scaling_group_instances(inactive_asg)) < 1:
......@@ -113,7 +109,7 @@ class ASG():
sleep(10)
# Wait for remaining instances (if any) to come up too
while len(self.asgs_healthy_instances(inactive_asg)) < self.scale_to:
while len(self.asgs_healthy_instances(inactive_asg)) < scale_to:
logging.info("Waiting for all instances to be healthy ...")
logging.info("ASG fully healthy. Logging new ASG name to \"inactive_asg.txt\"")
......
......@@ -65,9 +65,8 @@ def reset(ctx, application_name):
@click.option("--lb", help="Loadbalancer to work out targetgroup from -- mutually exclusive with --asg and --target-group")
@click.option("--target-group", "target_group", help="Target Group to discover the ASG for updating. Mutually exclusive with --asg and --lb")
@click.option("--asg", "asg_name", help="ASG we're updating -- mutually exclusive with --lb and --target-group")
@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):
def asg(ctx, ami, lb, asg_name, target_group, 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:
......@@ -86,23 +85,16 @@ def asg(ctx, ami, lb, asg_name, target_group, scale_to, skip_status_check):
region = ctx.obj.get('region')
role_arn = ctx.obj.get('role_arn')
scale_to = scale_to.replace(" ", "").split(",")
scale_to = {
"min": scale_to[0],
"max": scale_to[1],
"capacity": scale_to[2]
}
from .asg import update_asg
asg = update_asg.ASG(ami, region, role_arn, lb, asg_name, target_group, scale_to)
asg = update_asg.ASG(region, role_arn, lb, asg_name, target_group)
application = asg.get_application_name()
if lb or target_group:
if not skip_status_check:
set_deploy_status("start", region, role_arn, application)
asg.do_update()
asg.do_update(ami)
exit(0)
@update.command()
......@@ -135,14 +127,17 @@ def targetgroup(ctx, new_asg_target):
@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"""
"""
Given an the name of the _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 = update_asg.ASG(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