Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: third_party/gsutil/20110627/boto/bin/list_instances

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 import sys
4 from operator import attrgetter
5 from optparse import OptionParser
6
7 import boto
8 from boto.ec2 import regions
9
10
11 HEADERS = {
12 'ID': {'get': attrgetter('id'), 'length':15},
13 'Zone': {'get': attrgetter('placement'), 'length':15},
14 'Groups': {'get': attrgetter('groups'), 'length':30},
15 'Hostname': {'get': attrgetter('public_dns_name'), 'length':50},
16 'State': {'get': attrgetter('state'), 'length':15},
17 'Image': {'get': attrgetter('image_id'), 'length':15},
18 'Type': {'get': attrgetter('instance_type'), 'length':15},
19 'IP': {'get': attrgetter('ip_address'), 'length':16},
20 'PrivateIP': {'get': attrgetter('private_ip_address'), 'length':16},
21 'Key': {'get': attrgetter('key_name'), 'length':25},
22 'T:': {'length': 30},
23 }
24
25 def get_column(name, instance=None):
26 if name.startswith('T:'):
27 _, tag = name.split(':', 1)
28 return instance.tags.get(tag, '')
29 return HEADERS[name]['get'](instance)
30
31
32 def main():
33 parser = OptionParser()
34 parser.add_option("-r", "--region", help="Region (default us-east-1)", dest= "region", default="us-east-1")
35 parser.add_option("-H", "--headers", help="Set headers (use 'T:tagname' for including tags)", default=None, action="store", dest="headers", metavar="ID,Zone ,Groups,Hostname,State,T:Name")
36 (options, args) = parser.parse_args()
37
38 # Connect the region
39 for r in regions():
40 if r.name == options.region:
41 region = r
42 break
43 else:
44 print "Region %s not found." % options.region
45 sys.exit(1)
46 ec2 = boto.connect_ec2(region=region)
47
48 # Read headers
49 if options.headers:
50 headers = tuple(options.headers.split(','))
51 else:
52 headers = ("ID", 'Zone', "Groups", "Hostname")
53
54 # Create format string
55 format_string = ""
56 for h in headers:
57 if h.startswith('T:'):
58 format_string += "%%-%ds" % HEADERS['T:']['length']
59 else:
60 format_string += "%%-%ds" % HEADERS[h]['length']
61
62
63 # List and print
64 print format_string % headers
65 print "-" * len(format_string % headers)
66 for r in ec2.get_all_instances():
67 groups = [g.id for g in r.groups]
68 for i in r.instances:
69 i.groups = ','.join(groups)
70 print format_string % tuple(get_column(h, i) for h in headers)
71
72 if __name__ == "__main__":
73 main()
OLDNEW
« no previous file with comments | « third_party/gsutil/20110627/boto/bin/launch_instance ('k') | third_party/gsutil/20110627/boto/bin/lss3 » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698