libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [02/14] libcloud git commit: Implement create_record, delete_record in CloudFlare DNS driver.
Date Sun, 06 Dec 2015 06:32:40 GMT
Implement create_record, delete_record in CloudFlare DNS driver.


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

Branch: refs/heads/trunk
Commit: 91ada1ef3a97fd3d62b3fc7ff035a292a0c57fde
Parents: d3a3a4a
Author: Tomaz Muraus <tomaz@tomaz.me>
Authored: Sun Nov 22 16:26:27 2015 +0100
Committer: Tomaz Muraus <tomaz@tomaz.me>
Committed: Sun Dec 6 13:00:29 2015 +0800

----------------------------------------------------------------------
 libcloud/dns/drivers/cloudflare.py | 35 +++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/91ada1ef/libcloud/dns/drivers/cloudflare.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/cloudflare.py b/libcloud/dns/drivers/cloudflare.py
index 4bf2f66..44ed160 100644
--- a/libcloud/dns/drivers/cloudflare.py
+++ b/libcloud/dns/drivers/cloudflare.py
@@ -23,7 +23,7 @@ from libcloud.common.base import JsonResponse, ConnectionUserAndKey
 from libcloud.common.types import InvalidCredsError, LibcloudError
 from libcloud.utils.py3 import httplib
 from libcloud.dns.base import DNSDriver, Zone, Record
-from libcloud.dns.types import Provider
+from libcloud.dns.types import Provider, RecordType
 from libcloud.dns.types import ZoneDoesNotExistError, RecordDoesNotExistError
 
 API_URL = 'https://www.cloudflare.com/api_json.html'
@@ -85,6 +85,18 @@ class CloudFlareDNSConnection(ConnectionUserAndKey):
     secure = True
     responseCls = CloudFlareDNSResponse
 
+    RECORD_TYPE_MAP = {
+        RecordType.A: 'A',
+        RecordType.AAAA: 'AAAA',
+        RecordType.CNAME: 'CNAME',
+        RecordType.MX: 'MX',
+        RecordType.TXT: 'TXT',
+        RecordType.SPF: 'SPF',
+        RecordType.NS: 'NS',
+        RecordType.SRV: 'SRV',
+        RecordType.URL: 'LOC'
+    }
+
     def request(self, action, params=None, data=None, headers=None,
                 method='GET'):
         params = params or {}
@@ -125,6 +137,26 @@ class CloudFlareDNSDriver(DNSDriver):
         records = self._to_records(zone=zone, data=result['response']['recs']['objs'])
         return records
 
+    def create_record(self, name, zone, type, data, extra=None):
+        extra = extra or {}
+        params = {'name': name, 'z': zone.domain, 'type': type,
+                  'content': data}
+
+        params['ttl'] = extra.get('ttl', 120)
+
+        if 'priority' in extra:
+            # For MX and SRV records
+            params['prio'] = extra['priority']
+
+        result = self.connection.request(action='rec_new', params=params).object
+        record = self._to_record(zone=zone, item=result['response']['rec']['obj'])
+        return record
+
+    def delete_record(self, record):
+        params = {'z': record.zone.domain, 'id': record.id}
+        result = self.connection.request(action='rec_delete', params=params).object
+        return result.get('result', None) == 'success'
+
     def ex_get_zone_stats(self, zone, interval=30):
         params = {'z': zone.domain, 'interval': interval}
         result = self.connection.request(action='stats', params=params).object
@@ -259,7 +291,6 @@ class CloudFlareDNSDriver(DNSDriver):
         result = self.connection.request(action='ipv46', params=params).object
         return result.get('result', None) == 'success'
 
-
     def _to_zones(self, data):
         zones = []
 


Mime
View raw message