Created
April 3, 2012 02:50
-
-
Save duggan/2288942 to your computer and use it in GitHub Desktop.
Print degraded instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from boto.ec2.connection import EC2Connection | |
from boto.exception import BotoServerError | |
AMZN_ACCESS_KEY = "" | |
AMZN_SECRET_KEY = "" | |
maintenance_instances = [] | |
""" Get EC2 connection """ | |
try: | |
ec2 = EC2Connection(AMZN_ACCESS_KEY, AMZN_SECRET_KEY) | |
""" Get list of instances which require maintenance """ | |
statuses = ec2.get_all_instance_status() | |
except BotoServerError: | |
print "Failed to communicate with EC2 (%s)" % BotoServerError | |
for status in statuses: | |
if status.events: | |
event = status.events[0] | |
if "[Completed]" not in event.description: | |
maintenance_instances.append({"Event":event.code, | |
"Description":event.description, "Instance ID":status.id}) | |
print maintenance_instances |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment