in eksupdate/src/boto_aws.py [0:0]
def get_old_lt(asg_name,regionName):
"""Get old launc template"""
asg_client = boto3.client("autoscaling",region_name=regionName)
ec2_client = boto3.client("ec2",region_name=regionName)
old_lt_instance_ids = []
instances = []
response = asg_client.describe_auto_scaling_groups(
AutoScalingGroupNames=[
asg_name
]
)
asg_lt_name = ""
# print(response)
''' finding the launch type'''
if 'LaunchTemplate' in response['AutoScalingGroups'][0]:
lt_id = response["AutoScalingGroups"][0]["LaunchTemplate"]["LaunchTemplateId"]
asg_lt_name = response["AutoScalingGroups"][0]['LaunchTemplate']['LaunchTemplateName']
elif 'MixedInstancesPolicy' in response['AutoScalingGroups'][0]:
lt_id = response["AutoScalingGroups"][0]['MixedInstancesPolicy'][
"LaunchTemplate"]['LaunchTemplateSpecification']["LaunchTemplateId"]
asg_lt_name = response['AutoScalingGroups'][0]['MixedInstancesPolicy']['LaunchTemplate']['LaunchTemplateSpecification'][
'LaunchTemplateName']
else:
# logs_pusher("None found","error")
return "error"
# print(latest_lt)
''' checking wethether there are instances with 1!=2 mismatch template version '''
old_lt_instance_ids = [instance["InstanceId"] for instance in response["AutoScalingGroups"][0]
["Instances"] if old_lt_secanarios(instance, asg_lt_name, int(instance["LaunchTemplate"]["Version"]))]
if len(old_lt_instance_ids) == 0:
return []
response = ec2_client.describe_instances(InstanceIds=old_lt_instance_ids)
for reservation in response["Reservations"]:
for instance in reservation["Instances"]:
# logs_pusher(instance,"info")
instances.append(instance)
return instances