Browse files

For instance status events AWS inserts "[Completed]" into the

event description when the event is completed rather than removing
the event from the list.  Add a new option --completed that represents
the window times as "Completed" if the event has been completed.
  • Loading branch information...
1 parent 4dd6568 commit 5e0586acedea92d905b63b6ea54f9a82c1c1c080 @jimbrowne jimbrowne committed Dec 12, 2011
Showing with 9 additions and 3 deletions.
  1. +9 −3 bin/instance_events
View
12 bin/instance_events
@@ -44,9 +44,11 @@ def get_column(name, event=None):
return event[name]
return HEADERS[name]['get'](event)
-def list(region, headers, order):
+def list(region, headers, order, completed):
"""List status events for all instances in a given region"""
+ import re
+
ec2 = boto.connect_ec2(region=region)
reservations = ec2.get_all_instances()
@@ -81,6 +83,9 @@ def list(region, headers, order):
events[stat.id]['description'] = event.description
events[stat.id]['not_before'] = event.not_before
events[stat.id]['not_after'] = event.not_after
+ if completed and re.match('^\[Completed\]',event.description):
+ events[stat.id]['not_before'] = 'Completed'
+ events[stat.id]['not_after'] = 'Completed'
# Create format string
format_string = ""
@@ -109,6 +114,7 @@ if __name__ == "__main__":
parser.add_option("-r", "--region", help="region to check (default us-east-1)", dest="region", default="us-east-1")
parser.add_option("-H", "--headers", help="Set headers (use 'T:tagname' for including tags)", default=None, action="store", dest="headers", metavar="ID,Zone,Hostname,Code,Description,NotBefore,NotAfter,T:Name")
parser.add_option("-S", "--sort", help="Header for sort order", default=None, action="store", dest="order",metavar="HeaderName")
+ parser.add_option("-c", "--completed", help="List time fields as \"Completed\" for completed events (Default: false)", default=False, action="store_true", dest="completed")
(options, args) = parser.parse_args()
@@ -125,7 +131,7 @@ if __name__ == "__main__":
if options.all:
for r in regions():
print "Region %s" % r.name
- list(r, headers, order)
+ list(r, headers, order, options.completed)
else:
# Connect the region
for r in regions():
@@ -136,4 +142,4 @@ if __name__ == "__main__":
print "Region %s not found." % options.region
sys.exit(1)
- list(r, headers, order)
+ list(r, headers, order, options.completed)

0 comments on commit 5e0586a

Please sign in to comment.