Ready for different SSM parameters for update_asg

parent e3052e7d
......@@ -18,6 +18,19 @@ class ASG():
self.target_group = target_group
self.scale_to = scale_to if scale_to else 1
def return_application_name(self):
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")
active_asg = self.get_active_asg(target_group_arn)
asg_split = active_asg.split('-')[0:-1]
return '-'.join(asg_split)
def work_out_new_asg(self):
if self.asg is not None:"We've been given the ASG name as an argument")
......@@ -85,7 +98,6 @@ class ASG():"ASG fully healthy. Logging new ASG name to \"new_asg.txt\"")
open("new_asg.txt", "w").write(new_asg)
def get_first_new_instance(self, new_asg):
asg_instances = self.get_auto_scaling_group_instances(new_asg)
if len(asg_instances) < 1: raise exceptions.AkinakaLoggingError
......@@ -112,6 +124,12 @@ class ASG():
return lt_info['AutoScalingGroups'][0]['LaunchTemplate']['LaunchTemplateName']
def get_lb_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
alb_client = aws_client.create_client('elbv2', self.region, self.role_arn)
loadbalancer_raw_info = alb_client.describe_load_balancers(Names=[self.loadbalancer])
......@@ -134,7 +152,6 @@ class ASG():
# If we get this far, then we ran into one of the errors above
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)
......@@ -179,7 +196,6 @@ class ASG():
return next(iter(instances_with_asg.values()))
def get_inactive_asg(self, active_asg):
asg_parts = active_asg.split('-')
active_colour = asg_parts[-1]
......@@ -15,18 +15,18 @@ def update(ctx, region, role_arn, save_deploy_status):
ctx.obj = {'region': region, 'role_arn': role_arn, 'save_deploy_status': save_deploy_status}
def set_deploy_status(verb, region, role_arn, reset=None):"Checking deployment status...")
def set_deploy_status(verb, region, role_arn, application, reset=None):
aws_client = AWS_Client()
ssm_client = aws_client.create_client('ssm', region, role_arn)
ssm_parameter_name = "deploying-status-{}".format(application)
deploying_state = ssm_client.get_parameter(Name="deploying-status")['Parameter']['Value']
deploying_state = ssm_client.get_parameter(Name=ssm_parameter_name)['Parameter']['Value']
except ssm_client.exceptions.ParameterNotFound:
deploying_state = "false"
if verb == "start" and deploying_state != "false" and reset != True:
logging.error("Abort! Looks like that we have deployed at this timestamp: {}".format(deploying_state))
logging.error("Refusing to deploy, since it looks like we're already deploying at this timestamp: {}".format(deploying_state))
elif verb == "stop":
new_state = "false"
......@@ -34,13 +34,13 @@ def set_deploy_status(verb, region, role_arn, reset=None):
new_state = strftime("%Y%m%d%H%M%S", gmtime())
Description="Whether we're deploying right now",
)"Deployment status updated!")"Deployment status for {} updated".format(application))
......@@ -50,7 +50,7 @@ def reset(ctx):
role_arn = ctx.obj.get('role_arn')
save_deploy_status = ctx.obj.get('save_deploy_status')
if save_deploy_status == 'true':
set_deploy_status("stop", region, role_arn, True)
set_deploy_status("stop", region, role_arn, "reset", True)
......@@ -70,14 +70,15 @@ def asg(ctx, ami, lb, asg_name, target_group, scale_to):
from .asg import update_asg
# We set the deploy status to a timestamp (meaning in progress) if this is an update based on
# working out the ASG to update from the load balancer, so as not to allow interruption to the
# processs until we've also updated the targetgroup
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"
if lb or target_group:
if save_deploy_status == 'true':
set_deploy_status("start", region, role_arn)
set_deploy_status("start", region, application, role_arn)
asg = update_asg.ASG(ami, region, role_arn, lb, asg_name, target_group, scale_to)
......@@ -89,13 +90,16 @@ 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
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)
set_deploy_status("stop", region, application, role_arn)
except Exception as e:
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