Unique SSM parameter for ASGs update status

Application name needed to be worked out separately from the update_asg and update_targetgroups classes because of the difference in available information provided to those two.
parent e2ebbfbf
......@@ -20,19 +20,13 @@ class ASG():
self.target_group = target_group
self.scale_to = scale_to if scale_to else 1
def return_application_name(self):
def get_application_name(self):
Uses the classes self.targetgroup or self.loadbalancer arguments (whichever is available)
to return a string denoting the application attached to that argument
Returns the application name that we're deploying, worked out from the target group
(via the load balancer if applicable)
if self.loadbalancer:
target_group_arn = self.get_lb_target_group_arn()
elif self.target_group:
target_group_arn = self.get_target_group_arn(self.target_group)
raise exceptions.AkinakaCriticalException("Couldn't get name of the application we're updating")
target_group_arn = self.get_target_group_arn()
active_asg = self.get_active_asg(target_group_arn)
asg_split = active_asg.split('-')[0:-1]
......@@ -42,13 +36,8 @@ class ASG():
if self.asg is not None:
logging.info("We've been given the ASG name as an argument")
return self.asg
elif self.loadbalancer is not None and self.target_group is None:
target_group_arn = self.get_lb_target_group_arn()
elif self.loadbalancer is None and self.target_group is not None:
target_group_arn = self.get_target_group_arn(self.target_group)
raise exceptions.AkinakaCriticalException("Pass either --lb, --asg, or --lt")
target_group_arn = self.get_target_group_arn()
active_asg = self.get_active_asg(target_group_arn)
new_asg = self.get_inactive_asg(active_asg)
......@@ -133,14 +122,15 @@ class ASG():
except Exception as e:
raise exceptions.AkinakaCriticalException("{}: Likely couldn't find the ASG you're trying to update".format(e))
def get_lb_target_group_arn(self):
def get_target_group_arn(self):
Returns the ARN of the target group attached to this loadbalancer. This method is only
safe to use if your loadbalancer is attached to a single target group, so it therefore
complains if that's not the case
Returns a string containing the ARN of the target group supplied by --targetgroup or worked
out by stepping through some logic from the loadbalancer from --lb
alb_client = aws_client.create_client('elbv2', self.region, self.role_arn)
if self.target_group is not None:
return alb_client.describe_target_groups(Names=[self.target_group])['TargetGroups'][0]['TargetGroupArn']
loadbalancer_raw_info = alb_client.describe_load_balancers(Names=[self.loadbalancer])
loadbalancer_arn = loadbalancer_raw_info['LoadBalancers'][0]['LoadBalancerArn']
......@@ -162,11 +152,6 @@ class ASG():
raise exceptions.AkinakaCriticalException(error_message)
def get_target_group_arn(self, target_group):
"""Returns a string containing the ARN of the target group"""
alb_client = aws_client.create_client('elbv2', self.region, self.role_arn)
return alb_client.describe_target_groups(Names=[target_group])['TargetGroups'][0]['TargetGroupArn']
def get_target_groups_instances(self, target_group_arn):
"""Returns an array of instance IDs belonging to the target group specified"""
alb_client = aws_client.create_client('elbv2', self.region, self.role_arn)
......@@ -67,9 +67,7 @@ def asg(ctx, ami, lb, asg_name, target_group, scale_to, skip_status_check):
from .asg import update_asg
asg = update_asg.ASG(ami, region, role_arn, lb, asg_name, target_group, scale_to)
# TODO: WIP, since we still need to figure out how best to do this in a sharable way with update_targetgroup
# application = asg.return_application_name()
application = "wip"
application = asg.get_application_name()
if lb or target_group:
if not skip_status_check:
......@@ -86,16 +84,13 @@ def targetgroup(ctx, new_asg_target):
region = ctx.obj.get('region')
role_arn = ctx.obj.get('role_arn')
# TODO: See update_asg for the same thing above
application = "wip"
from .targetgroup import update_targetgroup
from .targetgroup import update_targetgroup
target_groups = update_targetgroup.TargetGroup(region, role_arn, new_asg_target)
# We've successfully deployed, so set the status of deploy to "false"
set_deploy_status("stop", region, role_arn, application)
set_deploy_status("stop", region, role_arn, target_groups.get_application_name())
except Exception as e:
......@@ -12,6 +12,11 @@ class TargetGroup():
self.role_arn = role_arn
self.new_asg = new_asg
def get_application_name(self):
asg_split = self.new_asg.split('-')[0:-1]
return '-'.join(asg_split)
def filter_out_unwanted_asgs(self, asgs, wanted_asg):
Takes a list of ASG objects (dicts), the ones you want to keep, and filters out everything else
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