Commit 6d7e6634 authored by Nazrul Kamaruddin's avatar Nazrul Kamaruddin

Moved save output to file to a generic function.

parent 9260ca83
......@@ -130,10 +130,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,16 +141,17 @@ 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 save_output_to_file(self, filename, output):
logging.info("Saving to file: {}".format(filename))
return open(filename, "w").write("{}\n".format(output))
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])
......
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