libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [6/6] git commit: Add ex_create_multi_value_record method to the Route53 driver which allows user to create a record with multiple values with a single call.
Date Fri, 21 Mar 2014 14:35:50 GMT
Add ex_create_multi_value_record method to the Route53 driver which allows
user to create a record with multiple values with a single call.


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

Branch: refs/heads/trunk
Commit: cd680cc760d98560ff7ace1e2ecf5e7aef664d05
Parents: 243e97f
Author: Tomaz Muraus <tomaz@apache.org>
Authored: Fri Mar 21 15:20:01 2014 +0100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Fri Mar 21 15:20:50 2014 +0100

----------------------------------------------------------------------
 CHANGES.rst                     |  4 +++
 libcloud/dns/drivers/route53.py | 47 ++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/cd680cc7/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 95f7ffa..744b7fc 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -87,6 +87,10 @@ DNS
   records with multiple values.
   [Tomaz Muraus]
 
+- Add ex_create_multi_value_record method to the Route53 driver which allows
+  user to create a record with multiple values with a single call.
+  [Tomaz Muraus]
+
 Changes with Apache Libcloud 0.14.1
 -----------------------------------
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cd680cc7/libcloud/dns/drivers/route53.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/route53.py b/libcloud/dns/drivers/route53.py
index 19a5bdf..d07bb6c 100644
--- a/libcloud/dns/drivers/route53.py
+++ b/libcloud/dns/drivers/route53.py
@@ -229,6 +229,53 @@ class Route53DNSDriver(DNSDriver):
                                           record_id=r.id)
         return True
 
+    def ex_create_multi_value_record(self, name, zone, type, data, extra=None):
+        """
+        Create a record with multiple values with a single call.
+
+        :return: A list of created records.
+        :rtype: ``list`` of :class:`libcloud.dns.base.Record`
+        """
+        extra = extra or {}
+
+        attrs = {'xmlns': NAMESPACE}
+        changeset = ET.Element('ChangeResourceRecordSetsRequest', attrs)
+        batch = ET.SubElement(changeset, 'ChangeBatch')
+        changes = ET.SubElement(batch, 'Changes')
+
+        change = ET.SubElement(changes, 'Change')
+        ET.SubElement(change, 'Action').text = 'CREATE'
+
+        rrs = ET.SubElement(change, 'ResourceRecordSet')
+        ET.SubElement(rrs, 'Name').text = name + '.' + zone.domain
+        ET.SubElement(rrs, 'Type').text = self.RECORD_TYPE_MAP[type]
+        ET.SubElement(rrs, 'TTL').text = str(extra.get('ttl', '0'))
+
+        rrecs = ET.SubElement(rrs, 'ResourceRecords')
+
+        # Value is provided as a multi line string
+        values = [value.strip() for value in data.split('\n') if
+                  value.strip()]
+
+        for value in values:
+            rrec = ET.SubElement(rrecs, 'ResourceRecord')
+            ET.SubElement(rrec, 'Value').text = value
+
+        uri = API_ROOT + 'hostedzone/' + zone.id + '/rrset'
+        data = ET.tostring(changeset)
+        self.connection.set_context({'zone_id': zone.id})
+        self.connection.request(uri, method='POST', data=data)
+
+        id = ':'.join((self.RECORD_TYPE_MAP[type], name))
+
+        records = []
+        for value in values:
+            record = Record(id=id, name=name, type=type, data=value, zone=zone,
+                            driver=self, extra=extra)
+            records.append(record)
+
+        return record
+
     def ex_delete_all_records(self, zone):
         """
         Remove all the records for the provided zone.


Mime
View raw message