libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/2] git commit: [LIBCLOUD-434] Implement iterate_* methods in the Route53 driver.
Date Thu, 05 Dec 2013 15:31:47 GMT
Updated Branches:
  refs/heads/trunk 12a75c9fe -> a84a01a44


[LIBCLOUD-434] Implement iterate_* methods in the Route53 driver.

This way all the records are returned and not just the ones which fit onto the
first page.

Signed-off-by: Tomaz Muraus <tomaz@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/a2e23040
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/a2e23040
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/a2e23040

Branch: refs/heads/trunk
Commit: a2e23040d8f98335238ab7b793ac316871e1f0c5
Parents: 12a75c9
Author: xofer <chris@parsely.com>
Authored: Thu Dec 5 03:21:23 2013 -0500
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Thu Dec 5 16:24:46 2013 +0100

----------------------------------------------------------------------
 libcloud/dns/drivers/route53.py | 52 +++++++++++++++++++++++++++++-------
 1 file changed, 42 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/a2e23040/libcloud/dns/drivers/route53.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/route53.py b/libcloud/dns/drivers/route53.py
index cb82379..ae128e4 100644
--- a/libcloud/dns/drivers/route53.py
+++ b/libcloud/dns/drivers/route53.py
@@ -111,17 +111,11 @@ class Route53DNSDriver(DNSDriver):
         RecordType.TXT: 'TXT'
     }
 
-    def list_zones(self):
-        data = self.connection.request(API_ROOT + 'hostedzone').object
-        zones = self._to_zones(data=data)
-        return zones
+    def iterate_zones(self):
+        return self._get_more('zones')
 
-    def list_records(self, zone):
-        self.connection.set_context({'zone_id': zone.id})
-        uri = API_ROOT + 'hostedzone/' + zone.id + '/rrset'
-        data = self.connection.request(uri).object
-        records = self._to_records(data=data, zone=zone)
-        return records
+    def iterate_records(self, zone):
+        return self._get_more('records', zone=zone)
 
     def get_zone(self, zone_id):
         self.connection.set_context({'zone_id': zone_id})
@@ -308,3 +302,41 @@ class Route53DNSDriver(DNSDriver):
         record = Record(id=id, name=name, type=type, data=data, zone=zone,
                         driver=self, extra=extra)
         return record
+
+    def _get_more(self, rtype, **kwargs):
+        exhausted = False
+        last_key = None
+        while not exhausted:
+            items, last_key, exhausted = self._get_data(rtype, last_key,
+                                                        **kwargs)
+            for item in items:
+                yield item
+
+    def _get_data(self, rtype, last_key, **kwargs):
+        params = {}
+        if last_key:
+            params['name'] = last_key
+        path = API_ROOT + 'hostedzone'
+
+        if rtype == 'zones':
+            response = self.connection.request(path, params=params)
+            transform_func = self._to_zones
+        elif rtype == 'records':
+            zone = kwargs['zone']
+            path += '/%s/rrset' % (zone.id)
+            self.connection.set_context({'zone_id': zone.id})
+            response = self.connection.request(path, params=params)
+            transform_func = self._to_records
+
+        if response.status == httplib.OK:
+            is_truncated = findtext(element=response.object,
+                                    xpath='IsTruncated',
+                                    namespace=NAMESPACE)
+            exhausted = is_truncated != 'true'
+            last_key = findtext(element=response.object,
+                                xpath='NextRecordName',
+                                namespace=NAMESPACE)
+            items = transform_func(data=response.object, **kwargs)
+            return items, last_key, exhausted
+        else:
+            return [], None, True


Mime
View raw message