Index: bin/route53 |
diff --git a/bin/route53 b/bin/route53 |
index 55f86a5c4e6e28acc45c2f4c6e251046f2e6ac8d..3f6327d90c56b4a09f4ed53851a86ac8b5a6bd54 100755 |
--- a/bin/route53 |
+++ b/bin/route53 |
@@ -35,25 +35,61 @@ def ls(conn): |
def get(conn, hosted_zone_id, type=None, name=None, maxitems=None): |
"""Get all the records for a single zone""" |
response = conn.get_all_rrsets(hosted_zone_id, type, name, maxitems=maxitems) |
- print '%-20s %-20s %-20s %s' % ("Name", "Type", "TTL", "Value(s)") |
+ # If a maximum number of items was set, we limit to that number |
+ # by turning the response into an actual list (copying it) |
+ # instead of allowing it to page |
+ if maxitems: |
+ response = response[:] |
+ print '%-40s %-5s %-20s %s' % ("Name", "Type", "TTL", "Value(s)") |
for record in response: |
- print '%-20s %-20s %-20s %s' % (record.name, record.type, record.ttl, ",".join(record.resource_records)) |
+ print '%-40s %-5s %-20s %s' % (record.name, record.type, record.ttl, record.to_print()) |
-def add_record(conn, hosted_zone_id, name, type, value, ttl=600, comment=""): |
+def add_record(conn, hosted_zone_id, name, type, values, ttl=600, comment=""): |
"""Add a new record to a zone""" |
from boto.route53.record import ResourceRecordSets |
changes = ResourceRecordSets(conn, hosted_zone_id, comment) |
change = changes.add_change("CREATE", name, type, ttl) |
- change.add_value(value) |
+ for value in values.split(','): |
+ change.add_value(value) |
print changes.commit() |
-def del_record(conn, hosted_zone_id, name, type, value, ttl=600, comment=""): |
+def del_record(conn, hosted_zone_id, name, type, values, ttl=600, comment=""): |
"""Delete a record from a zone""" |
from boto.route53.record import ResourceRecordSets |
changes = ResourceRecordSets(conn, hosted_zone_id, comment) |
change = changes.add_change("DELETE", name, type, ttl) |
- change.add_value(value) |
+ for value in values.split(','): |
+ change.add_value(value) |
+ print changes.commit() |
+ |
+def add_alias(conn, hosted_zone_id, name, type, alias_hosted_zone_id, alias_dns_name, comment=""): |
+ """Add a new alias to a zone""" |
+ from boto.route53.record import ResourceRecordSets |
+ changes = ResourceRecordSets(conn, hosted_zone_id, comment) |
+ change = changes.add_change("CREATE", name, type) |
+ change.set_alias(alias_hosted_zone_id, alias_dns_name) |
+ print changes.commit() |
+ |
+def del_alias(conn, hosted_zone_id, name, type, alias_hosted_zone_id, alias_dns_name, comment=""): |
+ """Delete an alias from a zone""" |
+ from boto.route53.record import ResourceRecordSets |
+ changes = ResourceRecordSets(conn, hosted_zone_id, comment) |
+ change = changes.add_change("DELETE", name, type) |
+ change.set_alias(alias_hosted_zone_id, alias_dns_name) |
+ print changes.commit() |
+ |
+def change_record(conn, hosted_zone_id, name, type, values, ttl=600, comment=""): |
+ """Delete and then add a record to a zone""" |
+ from boto.route53.record import ResourceRecordSets |
+ changes = ResourceRecordSets(conn, hosted_zone_id, comment) |
+ response = conn.get_all_rrsets(hosted_zone_id, type, name, maxitems=1)[0] |
+ change1 = changes.add_change("DELETE", name, type, response.ttl) |
+ for old_value in response.resource_records: |
+ change1.add_value(old_value) |
+ change2 = changes.add_change("CREATE", name, type, ttl) |
+ for new_value in values.split(','): |
+ change2.add_value(new_value) |
print changes.commit() |
def help(conn, fnc=None): |
@@ -78,7 +114,7 @@ def help(conn, fnc=None): |
cmd = getattr(self, cname) |
if inspect.isfunction(cmd): |
doc = cmd.__doc__ |
- print "\t%s - %s" % (cname, doc) |
+ print "\t%-20s %s" % (cname, doc) |
sys.exit(1) |