Commit 3b572227 authored by Florian Valery's avatar Florian Valery

Moved the asg_template_version function to commands

parent 197cbb3a
Pipeline #2628 failed with stage
in 20 seconds
......@@ -68,6 +68,7 @@ class ASG():
asg_liveness_info = self.asgs_by_liveness(asg=asg, loadbalancer=loadbalancer, target_group=target_group)
inactive_asg = asg_liveness_info['inactive_asg']
cx.obj = {'inactive_asg':inactive_asg}
active_asg = asg_liveness_info['active_asg']
new_ami = ami
current_lt_info = self.get_launch_template_info(self.get_lt_name(inactive_asg))
......@@ -82,13 +83,8 @@ class ASG():
lt_version=current_lt_info["version"],
)
# Update the lt and set the soon to be new ASG to the new launch template version
updated_lt = self.update_launch_template(new_ami, self.get_lt_name(inactive_asg))
self.set_asg_launch_template_version(
asg=inactive_asg,
lt_id=updated_lt["id"],
lt_version=updated_lt["version"]
)
scale_to = self.get_current_scale(active_asg)
......
......@@ -79,6 +79,10 @@ def asg(ctx, ami, lb, asg_name, target_group, skip_status_check):
such as ASGs for workers
"""
# Set ami as global
ctx.obj = {'ami':ami}
if [lb, asg_name, target_group].count(None) < 2:
logging.error("--lb, --asg, and --target-group are mutually exclusive. Please use only one")
......@@ -109,12 +113,22 @@ def targetgroup(ctx, new_asg_target):
region = ctx.obj.get('region')
role_arn = ctx.obj.get('role_arn')
log_level = ctx.obj.get('log_level')
ami = ctx.obj.get('ami')
inactive_asg = ctx.obj.get('inactive_asg')
from .targetgroup import update_targetgroup
try:
target_groups = update_targetgroup.TargetGroup(region, role_arn, new_asg_target, log_level)
target_groups.switch_asg()
# Update the lt
updated_lt = asg.update_launch_template(ami, asg.get_lt_name(inactive_asg))
# Set the soon to be new ASG to the new launch template version
asg.set_asg_launch_template_version(
asg=inactive_asg,
lt_id=updated_lt["id"],
lt_version=updated_lt["version"]
)
# We've successfully deployed, so set the status of deploy to "false"
set_deploy_status("stop", region, role_arn, target_groups.get_application_name())
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