libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [2/9] git commit: Changing the flow for processing records with multiple values such as MX records to be broken out into separate Record objects.
Date Wed, 05 Feb 2014 19:44:58 GMT
Changing the flow for processing records with multiple values such as MX records to be broken
out into separate Record objects.

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/c1cab594
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/c1cab594
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/c1cab594

Branch: refs/heads/trunk
Commit: c1cab59487b7def9ac15e1a856da19e94a6b6f9e
Parents: 8fb0473
Author: Chris DeRamus <chris@divvycloud.com>
Authored: Sun Feb 2 13:22:30 2014 -0500
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Wed Feb 5 14:33:12 2014 +0100

----------------------------------------------------------------------
 libcloud/dns/drivers/route53.py   | 30 ++++++++++++++++--------------
 libcloud/test/dns/test_route53.py |  9 +++------
 2 files changed, 19 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/c1cab594/libcloud/dns/drivers/route53.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/route53.py b/libcloud/dns/drivers/route53.py
index 8046bbb..1df6643 100644
--- a/libcloud/dns/drivers/route53.py
+++ b/libcloud/dns/drivers/route53.py
@@ -276,11 +276,14 @@ class Route53DNSDriver(DNSDriver):
             fixxpath(xpath='ResourceRecordSets/ResourceRecordSet',
                      namespace=NAMESPACE))
         for elem in elems:
-            records.append(self._to_record(elem, zone))
-
+            record_set = elem.findall(fixxpath(
+                                      xpath='ResourceRecords/ResourceRecord',
+                                      namespace=NAMESPACE))
+            for index, record in enumerate(record_set):
+                records.append(self._to_record(elem, zone, index))
         return records
 
-    def _to_record(self, elem, zone):
+    def _to_record(self, elem, zone, index=0):
         name = findtext(element=elem, xpath='Name',
                         namespace=NAMESPACE)
         name = name[:-len(zone.domain) - 1]
@@ -289,20 +292,19 @@ class Route53DNSDriver(DNSDriver):
                                                     namespace=NAMESPACE))
         ttl = findtext(element=elem, xpath='TTL', namespace=NAMESPACE)
 
-        data = ''
-        for record_elem in elem.findall(fixxpath(
-                                        xpath='ResourceRecords/ResourceRecord',
-                                        namespace=NAMESPACE)):
-
-            data += findtext(element=(record_elem),
-                             xpath='Value',
-                             namespace=NAMESPACE) + ' '
-
-        # Strip off the trailing space
-        data = data.rstrip(' ')
+        value_elem = elem.findall(
+            fixxpath(xpath='ResourceRecords/ResourceRecord',
+                     namespace=NAMESPACE))[index]
+        data = findtext(element=(value_elem), xpath='Value',
+                        namespace=NAMESPACE)
 
         extra = {'ttl': ttl}
 
+        if type == 'MX':
+            priority = int(data.split()[0])
+            data = data.split()[1]
+            extra['priority'] = priority
+
         id = ':'.join((self.RECORD_TYPE_MAP[type], name))
         record = Record(id=id, name=name, type=type, data=data, zone=zone,
                         driver=self, extra=extra)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c1cab594/libcloud/test/dns/test_route53.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_route53.py b/libcloud/test/dns/test_route53.py
index b5c1cdf..5e41dd7 100644
--- a/libcloud/test/dns/test_route53.py
+++ b/libcloud/test/dns/test_route53.py
@@ -50,7 +50,7 @@ class Route53Tests(unittest.TestCase):
     def test_list_records(self):
         zone = self.driver.list_zones()[0]
         records = self.driver.list_records(zone=zone)
-        self.assertEqual(len(records), 4)
+        self.assertEqual(len(records), 8)
 
         record = records[1]
         self.assertEqual(record.name, 'www')
@@ -60,11 +60,8 @@ class Route53Tests(unittest.TestCase):
 
         mx_record = records[3]
         self.assertEqual(mx_record.type, RecordType.MX)
-        self.assertEqual(mx_record.data, '1 ASPMX.L.GOOGLE.COM. '
-                         '5 ALT1.ASPMX.L.GOOGLE.COM. '
-                         '5 ALT2.ASPMX.L.GOOGLE.COM. '
-                         '10 ASPMX2.GOOGLEMAIL.COM. '
-                         '10 ASPMX3.GOOGLEMAIL.COM.')
+        self.assertEqual(mx_record.data, 'ASPMX.L.GOOGLE.COM.')
+        self.assertEqual(mx_record.extra['priority'], 1)
 
     def test_get_zone(self):
         zone = self.driver.get_zone(zone_id='47234')


Mime
View raw message