Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added get_hosted_zone_by_id.

  • Loading branch information...
commit 9d0f7c1a9ce10391d3030b1b5e34bbe3162d1819 1 parent 65595bf
Greg Taylor authored
29 route53/connection.py
@@ -102,6 +102,15 @@ def list_hosted_zones(self, page_chunks=100):
102 102 def create_hosted_zone(self, name, caller_reference=None, comment=None):
103 103 """
104 104 Creates a new hosted zone.
  105 +
  106 + :param str name: The name of the hosted zone to create.
  107 + :keyword str caller_reference: A unique string that identifies the
  108 + request and that allows failed create_hosted_zone requests to be
  109 + retried without the risk of executing the operation twice. If no
  110 + value is given, we'll generate a Type 4 UUID for you.
  111 + :keyword str comment: An optional comment to attach to the zone.
  112 + :rtype: HostedZone
  113 + :returns: The newly created HostedZone instance.
105 114 """
106 115
107 116 body = xml_generators.create_hosted_zone_writer(
@@ -121,3 +130,23 @@ def create_hosted_zone(self, name, caller_reference=None, comment=None):
121 130 root=root,
122 131 connection=self
123 132 )
  133 +
  134 + def get_hosted_zone_by_id(self, id):
  135 + """
  136 + Retrieves a hosted zone, by Hosted Zone ID (not name).
  137 +
  138 + :param str id: The hosted zone's ID (a short hash string).
  139 + :rtype: HostedZone
  140 + :returns: The requested hosted zone.
  141 + """
  142 +
  143 + root = self._send_request(
  144 + path='hostedzone/%s' % id,
  145 + params={},
  146 + method='GET',
  147 + )
  148 +
  149 + return xml_parsers.get_hosted_zone_by_id_parser(
  150 + root=root,
  151 + connection=self,
  152 + )
6 route53/hosted_zone.py
@@ -27,6 +27,12 @@ def __init__(self, connection, id, name, caller_reference,
27 27 self.caller_reference = caller_reference
28 28 self.resource_record_set_count = int(resource_record_set_count)
29 29 self.comment = comment
  30 + self._nameservers = []
  31 +
  32 + @property
  33 + def nameservers(self):
  34 + # TODO: Lazy load these if they aren't set.
  35 + return self._nameservers
30 36
31 37 def __str__(self):
32 38 return '<HostedZone: %s>' % self.name
3  route53/xml_parsers/__init__.py
... ... @@ -1,2 +1,3 @@
1 1 from .list_hosted_zones import list_hosted_zones_parser
2   -from .created_hosted_zone import created_hosted_zone_parser
  2 +from .created_hosted_zone import created_hosted_zone_parser
  3 +from .get_hosted_zone_by_id import get_hosted_zone_by_id_parser
21 route53/xml_parsers/common_hosted_zone.py
@@ -12,7 +12,7 @@
12 12 'Name': 'name',
13 13 'CallerReference': 'caller_reference',
14 14 'ResourceRecordSetCount': 'resource_record_set_count',
15   - }
  15 +}
16 16
17 17 def parse_hosted_zone(zone, connection):
18 18 """
@@ -48,4 +48,21 @@ def parse_hosted_zone(zone, connection):
48 48 # HostedZone instance.
49 49 kwargs[kw_name] = field.text
50 50
51   - return HostedZone(connection, **kwargs)
  51 + return HostedZone(connection, **kwargs)
  52 +
  53 +def parse_delegation_set(zone, e_delegation_set):
  54 + """
  55 + Parses a DelegationSet tag. These often accompany HostedZone tags in
  56 + responses like CreateHostedZone and GetHostedZone.
  57 +
  58 + :param HostedZone zone: An existing HostedZone instance to populate.
  59 + :param lxml.etree._Element e_delegation_set: A DelegationSet element.
  60 + """
  61 +
  62 + e_nameservers = e_delegation_set.find('./{*}NameServers')
  63 +
  64 + nameservers = []
  65 + for e_nameserver in e_nameservers:
  66 + nameservers.append(e_nameserver.text)
  67 +
  68 + zone._nameservers = nameservers
23 route53/xml_parsers/get_hosted_zone_by_id.py
... ... @@ -0,0 +1,23 @@
  1 +from route53.xml_parsers.common_hosted_zone import parse_hosted_zone, parse_delegation_set
  2 +
  3 +def get_hosted_zone_by_id_parser(root, connection):
  4 + """
  5 + Parses the API responses for the
  6 + :py:meth:`route53.connection.Route53Connection.get_hosted_zone_by_id` method.
  7 +
  8 + :param lxml.etree._Element root: The root node of the etree parsed
  9 + response from the API.
  10 + :param Route53Connection connection: The connection instance used to
  11 + query the API.
  12 + :rtype: HostedZone
  13 + :returns: The requested HostedZone.
  14 + """
  15 +
  16 + e_zone = root.find('./{*}HostedZone')
  17 + # This pops out a HostedZone instance.
  18 + hosted_zone = parse_hosted_zone(e_zone, connection)
  19 + # Now we'll fill in the nameservers.
  20 + e_delegation_set = root.find('./{*}DelegationSet')
  21 + # Modifies the HostedZone in place.
  22 + parse_delegation_set(hosted_zone, e_delegation_set)
  23 + return hosted_zone

0 comments on commit 9d0f7c1

Please sign in to comment.
Something went wrong with that request. Please try again.