This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added support for WRR resource sets.

  • Loading branch information...
gtaylor committed Nov 4, 2012
1 parent 5db2c16 commit 8667c4199031d83e625f2103b8fe3dce759e09ba
Showing with 67 additions and 14 deletions.
  1. +23 −1 route53/hosted_zone.py
  2. +22 −4 route53/resource_record_set.py
  3. +22 −9 route53/xml_generators/change_resource_record_set.py
View
@@ -127,13 +127,30 @@ def _halt_if_already_deleted(self):
if self._is_deleted:
raise AlreadyDeletedError("Can't manipulate a deleted zone.")
- def add_a_record(self, name, values, ttl=60):
+ def add_a_record(self, name, values, ttl=60, weight=None, region=None,
+ set_identifier=None, alias_hosted_zone_id=None,
+ alias_dns_name=None):
"""
Adds an A record to the hosted zone.
:param str name: The fully qualified name of the record to add.
:param list values: A list of value strings for the record.
:keyword int ttl: The time-to-live of the record (in seconds).
+ :keyword int weight: For weighted record sets only. Among resource record
+ sets that have the same combination of DNS name and type, a value
+ that determines what portion of traffic for the current resource
+ record set is routed to the associated location. Ranges from 0-255.
+ :keyword str region: For latency-based record sets. The Amazon EC2 region
+ where the resource that is specified in this resource record set
+ resides.
+ :keyword str set_identifier: For weighted and latency resource record
+ sets only. An identifier that differentiates among multiple
+ resource record sets that have the same combination of DNS name
+ and type. 1-128 chars.
+ :keyword str alias_hosted_zone_id: Alias A records have this specified.
+ It appears to be the hosted zone ID for the ELB the Alias points at.
+ :keyword str alias_dns_name: Alias A records have this specified. It is
+ the DNS name for the ELB that the Alias points to.
:rtype: tuple
:returns: A tuple in the form of ``(rrset, change_info)``, where
``rrset`` is the newly created AResourceRecordSet instance.
@@ -142,11 +159,16 @@ def add_a_record(self, name, values, ttl=60):
self._halt_if_already_deleted()
rrset = AResourceRecordSet(
+ alias_hosted_zone_id=alias_hosted_zone_id,
+ alias_dns_name=alias_dns_name,
connection=self.connection,
zone_id=self.id,
name=name,
ttl=ttl,
records=values,
+ weight=weight,
+ region=region,
+ set_identifier=set_identifier,
)
cset = ChangeSet(connection=self.connection, hosted_zone_id=self.id)
@@ -12,7 +12,8 @@ class ResourceRecordSet(object):
# Override this in your sub-class.
rrset_type = None
- def __init__(self, connection, zone_id, name, ttl, records):
+ def __init__(self, connection, zone_id, name, ttl, records, weight, region,
+ set_identifier):
"""
:param Route53Connection connection: The connection instance that
was used to query the Route53 API, leading to this object's
@@ -24,13 +25,27 @@ def __init__(self, connection, zone_id, name, ttl, records):
be None in that case.
:param list records: A list of resource record strings. For some
types (A entries that are Aliases), this is an empty list.
+ :param int weight: For weighted record sets only. Among resource record
+ sets that have the same combination of DNS name and type, a value
+ that determines what portion of traffic for the current resource
+ record set is routed to the associated location. Ranges from 0-255.
+ :param str region: For latency-based record sets. The Amazon EC2 region
+ where the resource that is specified in this resource record set
+ resides.
+ :param str set_identifier: For weighted and latency resource record
+ sets only. An identifier that differentiates among multiple
+ resource record sets that have the same combination of DNS name
+ and type. 1-128 chars.
"""
self.connection = connection
self.zone_id = zone_id
self.name = name
self.ttl = int(ttl) if ttl else None
self.records = records
+ self.region = region
+ self.weight = weight
+ self.set_identifier = set_identifier
# Keep track of the initial values for this record set. We use this
# to detect changes that need saving.
@@ -40,6 +55,9 @@ def __init__(self, connection, zone_id, name, ttl, records):
name=name,
ttl=ttl,
records=records,
+ region=region,
+ weight=weight,
+ set_identifier=set_identifier,
)
def __str__(self):
@@ -128,11 +146,11 @@ class AResourceRecordSet(ResourceRecordSet):
rrset_type = 'A'
- def __init__(self, alias_hosted_zone_id=None, alias_dns_name=None, *args, **kwargs):
+ def __init__(self, alias_hosted_zone_id, alias_dns_name, *args, **kwargs):
"""
- :keyword str alias_hosted_zone_id: Alias A records have this specified.
+ :param str alias_hosted_zone_id: Alias A records have this specified.
It appears to be the hosted zone ID for the ELB the Alias points at.
- :keyword str alias_dns_name: Alias A records have this specified. It is
+ :param str alias_dns_name: Alias A records have this specified. It is
the DNS name for the ELB that the Alias points to.
"""
@@ -19,15 +19,17 @@ def get_change_values(change):
action, rrset = change
if action == 'CREATE':
- # For creations, we want the new values. They don't need to match.
- return dict(
- name=rrset.name,
- ttl=rrset.ttl,
- records=rrset.records,
- )
+ # For creations, we want the current values, since they don't need to
+ # match an existing record set.
+ values = dict()
+ for key, val in rrset._initial_vals.items():
+ # Pull from the record set's attributes, which are the current
+ # values.
+ values[key] = getattr(rrset, key)
+ return values
else:
- # We can just dump the initial values dict for deletions, since we
- # want the original values to match in the deletion request.
+ # We can look at the initial values dict for deletions, since we
+ # have to match against the values currently in Route53.
return rrset._initial_vals
def write_change(change):
@@ -57,10 +59,21 @@ def write_change(change):
e_type = etree.SubElement(e_rrset, "Type")
e_type.text = rrset.rrset_type
+ if 'set_identifier' in change_vals:
+ e_set_id = etree.SubElement(e_rrset, "SetIdentifier")
+ e_set_id.text = change_vals['set_identifer']
+
+ if 'weight' in change_vals:
+ e_weight = etree.SubElement(e_rrset, "Weight")
+ e_weight.text = change_vals['weight']
+
+ if 'region' in change_vals:
+ e_weight = etree.SubElement(e_rrset, "Region")
+ e_weight.text = change_vals['region']
+
e_ttl = etree.SubElement(e_rrset, "TTL")
e_ttl.text = str(change_vals['ttl'])
-
if rrset.is_alias_record_set():
# A record sets in Alias mode don't have any resource records.
return e_change

0 comments on commit 8667c41

Please sign in to comment.