summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJim Browne <jbrowne@jbrowne.com>2012-01-28 19:21:35 -0800
committerJim Browne <jbrowne@jbrowne.com>2012-01-28 19:22:51 -0800
commit603d8a3df71304c3dd4e51497ef3c568afa531be (patch)
treee5363c74d0f72ecf16d3afa2981653d9dbc1c27e /bin
parentdf542e0e8fe331d9288f287f68ad2caa384ed8dc (diff)
downloadboto-603d8a3df71304c3dd4e51497ef3c568afa531be.tar.gz
Re-write support for WRRs so they are just extentions to the
existing commands. Collapse common code from add/delete paths. Loop over RRsets to properly handle the NULL and WRR cases. This script could use a re-write to using options to make its use more clear and to allow catching edge cases.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/route53137
1 files changed, 61 insertions, 76 deletions
diff --git a/bin/route53 b/bin/route53
index d325f665..9975b277 100755
--- a/bin/route53
+++ b/bin/route53
@@ -44,103 +44,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"""
- from boto.route53.record import ResourceRecordSets
- changes = ResourceRecordSets(conn, hosted_zone_id, comment)
- change = changes.add_change("CREATE", name, type, ttl)
- 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"""
- 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_weighted_record(conn, hosted_zone_id, name, type, values,
- identifier, weight, ttl=600, comment=""):
- """Add a new weighted record"""
- from boto.route53.record import ResourceRecordSets
- changes = ResourceRecordSets(conn, hosted_zone_id, comment)
- change = changes.add_change("CREATE", name, type, ttl,
- identifier=identifier, weight=weight)
- for value in values.split(','):
- change.add_value(value)
- print changes.commit()
-
-def del_weighted_record(conn, hosted_zone_id, name, type, values, ttl=600,
- identifier=None, weight=None, comment=""):
- """Delete a weighted record from 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("DELETE", name, type, ttl,
- identifier=identifier, weight=weight)
+ 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 add_alias(conn, hosted_zone_id, name, type, alias_hosted_zone_id, alias_dns_name, comment=""):
- """Add a new alias to 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("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"""
+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 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)
- change = changes.add_change("DELETE", name, type)
- change.set_alias(alias_hosted_zone_id, alias_dns_name)
- print changes.commit()
+ # 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)
-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,
- identifier=identifier, weight=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 values.split(','):
+ 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)
- print changes.commit()
-
-def change_weighted_record(conn, hosted_zone_id, name, type, values, ttl=600,
- identifier=None, weight=None, comment=""):
- """Delete and then add a weighted 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,
- identifier=identifier, weight=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 values.split(','):
- change2.add_value(new_value)
+ # 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):