...
 
Commits (2)
......@@ -72,7 +72,6 @@ class ASG():
else:
logging.error("No EC2 instances found.")
exit(1)
return new_asg
else:
logging.error("Please specify a target group.")
......@@ -94,7 +93,6 @@ class ASG():
new_color = None
a = name.split('-')
color = a[-1]
# Determine the "new" auto scaling group name
if color == 'blue':
new_color = 'green'
else:
......@@ -130,10 +128,8 @@ class ASG():
# Print EC2 console output
self.get_console_output_from_instance(first_instance)
new_asg_filename = "new_asg.txt"
logging.info("Saving new auto scaling group name to file: {}".format(new_asg_filename))
open(new_asg_filename, "w").write("{}\n".format(new_asg))
# Save new_asg value to a file
self.save_output_to_file("new_asg.txt", new_asg)
logging.info("Update complete!")
def get_console_output_from_instance(self, instance):
......@@ -143,24 +139,16 @@ class ASG():
while first_instance_output is False:
ec2console = ec2_client.get_console_output(InstanceId=instance['InstanceId'])
if 'Output' in ec2console:
# TODO: Support custom file name
console_filename = "console.txt"
logging.info("EC2 instance console output: {}".format(instance['InstanceId']))
logging.info("Saving console output to file: {}".format(console_filename))
open(console_filename, "w").write("{}".format(ec2console['Output']))
self.save_output_to_file("console.txt", ec2console['Output'])
first_instance_output = True
else:
sleep(10)
return
def instance_state(self, instance):
ec2_client = aws_client.create_client('ec2', self.region, self.role_arn)
instance_states = ec2_client.describe_instance_status(IncludeAllInstances=True, InstanceIds=[instance])
while 'InstanceStatuses' not in instance_states:
instance_states = ec2_client.describe_instance_status(InstanceIds=[instance])
return instance_states['InstanceStatuses'][0]['InstanceState']['Name']
def save_output_to_file(self, filename, output):
logging.info("Saving to file: {}".format(filename))
return open(filename, "w").write("{}\n".format(output))
def get_lt_name(self, asg):
asg_client = aws_client.create_client('autoscaling', self.region, self.role_arn)
......