diff options
author | Chris Moyer <kopertop@gmail.com> | 2012-02-02 18:26:05 -0800 |
---|---|---|
committer | Chris Moyer <kopertop@gmail.com> | 2012-02-02 18:26:05 -0800 |
commit | 0901a9dc7c997560c81e39d609e31d60086cc9fe (patch) | |
tree | e88cff8b0e28b5ac26de61876cbaf2842de567be /bin | |
parent | 186ba53985abed148eb7585c2e67b353500ca2df (diff) | |
parent | 3b8718861434a6734192cee8bc87c2af419d343a (diff) | |
download | boto-0901a9dc7c997560c81e39d609e31d60086cc9fe.tar.gz |
Merge pull request #529 from jimbrowne/support_wrr
Support Weighted Resource Records
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/route53 | 131 |
1 files changed, 92 insertions, 39 deletions
diff --git a/bin/route53 b/bin/route53 index c2f2cb4c..488a9ca9 100755 --- a/bin/route53 +++ b/bin/route53 @@ -3,6 +3,34 @@ # # route53 is similar to sdbadmin for Route53, it's a simple # console utility to perform the most frequent tasks with Route53 +# +# Example usage. Use route53 get after each command to see how the +# zone changes. +# +# Add a non-weighted record, change its value, then delete. Default TTL: +# +# route53 add_record ZPO9LGHZ43QB9 rr.example.com A 4.3.2.1 +# route53 change_record ZPO9LGHZ43QB9 rr.example.com A 9.8.7.6 +# route53 del_record ZPO9LGHZ43QB9 rr.example.com A 9.8.7.6 +# +# Add a weighted record with two different weights. Note that the TTL +# must be specified as route53 uses positional parameters rather than +# option flags: +# +# route53 add_record ZPO9LGHZ43QB9 wrr.example.com A 1.2.3.4 600 foo9 10 +# route53 add_record ZPO9LGHZ43QB9 wrr.example.com A 4.3.2.1 600 foo8 10 +# +# route53 change_record ZPO9LGHZ43QB9 wrr.example.com A 9.9.9.9 600 foo8 10 +# +# route53 del_record ZPO9LGHZ43QB9 wrr.example.com A 1.2.3.4 600 foo9 10 +# route53 del_record ZPO9LGHZ43QB9 wrr.example.com A 9.9.9.9 600 foo8 10 +# +# Add a non-weighted alias, change its value, then delete. Alaises inherit +# their TTLs from the backing ELB: +# +# route53 add_alias ZPO9LGHZ43QB9 alias.example.com A Z3DZXE0Q79N41H lb-1218761514.us-east-1.elb.amazonaws.com. +# route53 change_alias ZPO9LGHZ43QB9 alias.example.com. A Z3DZXE0Q79N41H lb2-1218761514.us-east-1.elb.amazonaws.com. +# route53 delete_alias ZPO9LGHZ43QB9 alias.example.com. A Z3DZXE0Q79N41H lb2-1218761514.us-east-1.elb.amazonaws.com. def _print_zone_info(zoneinfo): print "="*80 @@ -12,7 +40,7 @@ def _print_zone_info(zoneinfo): print "="*80 print zoneinfo['Config'] print - + def create(conn, hostname, caller_reference=None, comment=''): """Create a hosted zone, returning the nameservers""" @@ -44,63 +72,88 @@ def get(conn, hosted_zone_id, type=None, name=None, maxitems=None): for record in response: print '%-40s %-5s %-20s %s' % (record.name, record.type, record.ttl, record.to_print()) - -def add_record(conn, hosted_zone_id, name, type, values, ttl=600, comment=""): - """Add a new record to a zone""" +def _add_del(conn, hosted_zone_id, change, name, type, identifier, weight, values, ttl, comment): from boto.route53.record import ResourceRecordSets changes = ResourceRecordSets(conn, hosted_zone_id, comment) - change = changes.add_change("CREATE", name, type, ttl) + change = changes.add_change(change, name, type, ttl, + identifier=identifier, weight=weight) for value in values.split(','): change.add_value(value) print changes.commit() -def del_record(conn, hosted_zone_id, name, type, values, ttl=600, comment=""): - """Delete a record from a zone""" +def _add_del_alias(conn, hosted_zone_id, change, name, type, identifier, weight, alias_hosted_zone_id, alias_dns_name, comment): from boto.route53.record import ResourceRecordSets changes = ResourceRecordSets(conn, hosted_zone_id, comment) - change = changes.add_change("DELETE", name, type, ttl) - 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 = changes.add_change(change, name, type, + identifier=identifier, weight=weight) 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 add_record(conn, hosted_zone_id, name, type, values, ttl=600, + identifier=None, weight=None, comment=""): + """Add a new record to a zone. identifier and weight are optional.""" + _add_del(conn, hosted_zone_id, "CREATE", name, type, identifier, + weight, values, ttl, comment) + +def del_record(conn, hosted_zone_id, name, type, values, ttl=600, + identifier=None, weight=None, comment=""): + """Delete a record from a zone: name, type, ttl, identifier, and weight must match.""" + _add_del(conn, hosted_zone_id, "DELETE", name, type, identifier, + weight, values, ttl, comment) -def change_record(conn, hosted_zone_id, name, type, values, ttl=600, comment=""): - """Delete and then add a record to a zone""" +def add_alias(conn, hosted_zone_id, name, type, alias_hosted_zone_id, + alias_dns_name, identifier=None, weight=None, comment=""): + """Add a new alias to a zone. identifier and weight are optional.""" + _add_del_alias(conn, hosted_zone_id, "CREATE", name, type, identifier, + weight, alias_hosted_zone_id, alias_dns_name, comment) + +def del_alias(conn, hosted_zone_id, name, type, alias_hosted_zone_id, + alias_dns_name, identifier=None, weight=None, comment=""): + """Delete an alias from a zone: name, type, alias_hosted_zone_id, alias_dns_name, weight and identifier must match.""" + _add_del_alias(conn, hosted_zone_id, "DELETE", name, type, identifier, + weight, alias_hosted_zone_id, alias_dns_name, comment) + +def change_record(conn, hosted_zone_id, name, type, newvalues, ttl=600, + identifier=None, weight=None, comment=""): + """Delete and then add a record to a zone. identifier and weight are optional.""" 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(','): + # Assume there are not more than 10 WRRs for a given (name, type) + responses = conn.get_all_rrsets(hosted_zone_id, type, name, maxitems=10) + for response in responses: + if response.name != name or response.type != type: + continue + if response.identifier != identifier or response.weight != weight: + continue + change1 = changes.add_change("DELETE", name, type, response.ttl, + identifier=response.identifier, + weight=response.weight) + for old_value in response.resource_records: + change1.add_value(old_value) + + change2 = changes.add_change("CREATE", name, type, ttl, + identifier=identifier, weight=weight) + for new_value in newvalues.split(','): change2.add_value(new_value) print changes.commit() -def change_alias(conn, hosted_zone_id, name, type, alias_hosted_zone_id, alias_dns_name, comment=""): - """Delete and then add an alias to a zone""" +def change_alias(conn, hosted_zone_id, name, type, new_alias_hosted_zone_id, new_alias_dns_name, identifier=None, weight=None, comment=""): + """Delete and then add an alias to a zone. identifier and weight are optional.""" 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) - change1.set_alias(response.alias_hosted_zone_id, response.alias_dns_name) - change2 = changes.add_change("CREATE", name, type) - change2.set_alias(alias_hosted_zone_id, alias_dns_name) + # Assume there are not more than 10 WRRs for a given (name, type) + responses = conn.get_all_rrsets(hosted_zone_id, type, name, maxitems=10) + for response in responses: + if response.name != name or response.type != type: + continue + if response.identifier != identifier or response.weight != weight: + continue + change1 = changes.add_change("DELETE", name, type, + identifier=response.identifier, + weight=response.weight) + change1.set_alias(response.alias_hosted_zone_id, response.alias_dns_name) + change2 = changes.add_change("CREATE", name, type, identifier=identifier, weight=weight) + change2.set_alias(new_alias_hosted_zone_id, new_alias_dns_name) print changes.commit() def help(conn, fnc=None): |