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

Side by Side Diff: bin/route53

Issue 8386013: Merging in latest boto. (Closed) Base URL: svn://svn.chromium.org/boto
Patch Set: Redoing vendor drop by deleting and then merging. Created 9 years, 1 month 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
« no previous file with comments | « bin/pyami_sendmail ('k') | bin/s3multiput » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Author: Chris Moyer 2 # Author: Chris Moyer
3 # 3 #
4 # route53 is similar to sdbadmin for Route53, it's a simple 4 # route53 is similar to sdbadmin for Route53, it's a simple
5 # console utility to perform the most frequent tasks with Route53 5 # console utility to perform the most frequent tasks with Route53
6 6
7 def _print_zone_info(zoneinfo): 7 def _print_zone_info(zoneinfo):
8 print "="*80 8 print "="*80
9 print "| ID: %s" % zoneinfo['Id'].split("/")[-1] 9 print "| ID: %s" % zoneinfo['Id'].split("/")[-1]
10 print "| Name: %s" % zoneinfo['Name'] 10 print "| Name: %s" % zoneinfo['Name']
(...skipping 17 matching lines...) Expand all
28 28
29 def ls(conn): 29 def ls(conn):
30 """List all hosted zones""" 30 """List all hosted zones"""
31 response = conn.get_all_hosted_zones() 31 response = conn.get_all_hosted_zones()
32 for zoneinfo in response['ListHostedZonesResponse']['HostedZones']: 32 for zoneinfo in response['ListHostedZonesResponse']['HostedZones']:
33 _print_zone_info(zoneinfo) 33 _print_zone_info(zoneinfo)
34 34
35 def get(conn, hosted_zone_id, type=None, name=None, maxitems=None): 35 def get(conn, hosted_zone_id, type=None, name=None, maxitems=None):
36 """Get all the records for a single zone""" 36 """Get all the records for a single zone"""
37 response = conn.get_all_rrsets(hosted_zone_id, type, name, maxitems=maxitems ) 37 response = conn.get_all_rrsets(hosted_zone_id, type, name, maxitems=maxitems )
38 print '%-20s %-20s %-20s %s' % ("Name", "Type", "TTL", "Value(s)") 38 # If a maximum number of items was set, we limit to that number
39 # by turning the response into an actual list (copying it)
40 # instead of allowing it to page
41 if maxitems:
42 response = response[:]
43 print '%-40s %-5s %-20s %s' % ("Name", "Type", "TTL", "Value(s)")
39 for record in response: 44 for record in response:
40 print '%-20s %-20s %-20s %s' % (record.name, record.type, record.ttl, ", ".join(record.resource_records)) 45 print '%-40s %-5s %-20s %s' % (record.name, record.type, record.ttl, rec ord.to_print())
41 46
42 47
43 def add_record(conn, hosted_zone_id, name, type, value, ttl=600, comment=""): 48 def add_record(conn, hosted_zone_id, name, type, values, ttl=600, comment=""):
44 """Add a new record to a zone""" 49 """Add a new record to a zone"""
45 from boto.route53.record import ResourceRecordSets 50 from boto.route53.record import ResourceRecordSets
46 changes = ResourceRecordSets(conn, hosted_zone_id, comment) 51 changes = ResourceRecordSets(conn, hosted_zone_id, comment)
47 change = changes.add_change("CREATE", name, type, ttl) 52 change = changes.add_change("CREATE", name, type, ttl)
48 change.add_value(value) 53 for value in values.split(','):
54 change.add_value(value)
49 print changes.commit() 55 print changes.commit()
50 56
51 def del_record(conn, hosted_zone_id, name, type, value, ttl=600, comment=""): 57 def del_record(conn, hosted_zone_id, name, type, values, ttl=600, comment=""):
52 """Delete a record from a zone""" 58 """Delete a record from a zone"""
53 from boto.route53.record import ResourceRecordSets 59 from boto.route53.record import ResourceRecordSets
54 changes = ResourceRecordSets(conn, hosted_zone_id, comment) 60 changes = ResourceRecordSets(conn, hosted_zone_id, comment)
55 change = changes.add_change("DELETE", name, type, ttl) 61 change = changes.add_change("DELETE", name, type, ttl)
56 change.add_value(value) 62 for value in values.split(','):
63 change.add_value(value)
64 print changes.commit()
65
66 def add_alias(conn, hosted_zone_id, name, type, alias_hosted_zone_id, alias_dns_ name, comment=""):
67 """Add a new alias to a zone"""
68 from boto.route53.record import ResourceRecordSets
69 changes = ResourceRecordSets(conn, hosted_zone_id, comment)
70 change = changes.add_change("CREATE", name, type)
71 change.set_alias(alias_hosted_zone_id, alias_dns_name)
72 print changes.commit()
73
74 def del_alias(conn, hosted_zone_id, name, type, alias_hosted_zone_id, alias_dns_ name, comment=""):
75 """Delete an alias from a zone"""
76 from boto.route53.record import ResourceRecordSets
77 changes = ResourceRecordSets(conn, hosted_zone_id, comment)
78 change = changes.add_change("DELETE", name, type)
79 change.set_alias(alias_hosted_zone_id, alias_dns_name)
80 print changes.commit()
81
82 def change_record(conn, hosted_zone_id, name, type, values, ttl=600, comment="") :
83 """Delete and then add a record to a zone"""
84 from boto.route53.record import ResourceRecordSets
85 changes = ResourceRecordSets(conn, hosted_zone_id, comment)
86 response = conn.get_all_rrsets(hosted_zone_id, type, name, maxitems=1)[0]
87 change1 = changes.add_change("DELETE", name, type, response.ttl)
88 for old_value in response.resource_records:
89 change1.add_value(old_value)
90 change2 = changes.add_change("CREATE", name, type, ttl)
91 for new_value in values.split(','):
92 change2.add_value(new_value)
57 print changes.commit() 93 print changes.commit()
58 94
59 def help(conn, fnc=None): 95 def help(conn, fnc=None):
60 """Prints this help message""" 96 """Prints this help message"""
61 import inspect 97 import inspect
62 self = sys.modules['__main__'] 98 self = sys.modules['__main__']
63 if fnc: 99 if fnc:
64 try: 100 try:
65 cmd = getattr(self, fnc) 101 cmd = getattr(self, fnc)
66 except: 102 except:
67 cmd = None 103 cmd = None
68 if not inspect.isfunction(cmd): 104 if not inspect.isfunction(cmd):
69 print "No function named: %s found" % fnc 105 print "No function named: %s found" % fnc
70 sys.exit(2) 106 sys.exit(2)
71 (args, varargs, varkw, defaults) = inspect.getargspec(cmd) 107 (args, varargs, varkw, defaults) = inspect.getargspec(cmd)
72 print cmd.__doc__ 108 print cmd.__doc__
73 print "Usage: %s %s" % (fnc, " ".join([ "[%s]" % a for a in args[1:]])) 109 print "Usage: %s %s" % (fnc, " ".join([ "[%s]" % a for a in args[1:]]))
74 else: 110 else:
75 print "Usage: route53 [command]" 111 print "Usage: route53 [command]"
76 for cname in dir(self): 112 for cname in dir(self):
77 if not cname.startswith("_"): 113 if not cname.startswith("_"):
78 cmd = getattr(self, cname) 114 cmd = getattr(self, cname)
79 if inspect.isfunction(cmd): 115 if inspect.isfunction(cmd):
80 doc = cmd.__doc__ 116 doc = cmd.__doc__
81 print "\t%s - %s" % (cname, doc) 117 print "\t%-20s %s" % (cname, doc)
82 sys.exit(1) 118 sys.exit(1)
83 119
84 120
85 if __name__ == "__main__": 121 if __name__ == "__main__":
86 import boto 122 import boto
87 import sys 123 import sys
88 conn = boto.connect_route53() 124 conn = boto.connect_route53()
89 self = sys.modules['__main__'] 125 self = sys.modules['__main__']
90 if len(sys.argv) >= 2: 126 if len(sys.argv) >= 2:
91 try: 127 try:
92 cmd = getattr(self, sys.argv[1]) 128 cmd = getattr(self, sys.argv[1])
93 except: 129 except:
94 cmd = None 130 cmd = None
95 args = sys.argv[2:] 131 args = sys.argv[2:]
96 else: 132 else:
97 cmd = help 133 cmd = help
98 args = [] 134 args = []
99 if not cmd: 135 if not cmd:
100 cmd = help 136 cmd = help
101 try: 137 try:
102 cmd(conn, *args) 138 cmd(conn, *args)
103 except TypeError, e: 139 except TypeError, e:
104 print e 140 print e
105 help(conn, cmd.__name__) 141 help(conn, cmd.__name__)
OLDNEW
« no previous file with comments | « bin/pyami_sendmail ('k') | bin/s3multiput » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698