Repository: libcloud
Updated Branches:
  refs/heads/cloudflare_dns_driver 0e3e03760 -> d38e745fa


Throw RecordDoesNotExist exception if an invalid record is referenced.


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

Branch: refs/heads/cloudflare_dns_driver
Commit: 7a5f86d7e12798cd75ca5869166faa7bc0895341
Parents: 0e3e037
Author: Tomaz Muraus <[email protected]>
Authored: Sun Nov 22 22:50:02 2015 +0100
Committer: Tomaz Muraus <[email protected]>
Committed: Sun Nov 22 22:50:02 2015 +0100

----------------------------------------------------------------------
 libcloud/dns/drivers/cloudflare.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/7a5f86d7/libcloud/dns/drivers/cloudflare.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/cloudflare.py 
b/libcloud/dns/drivers/cloudflare.py
index 751674a..bdd6726 100644
--- a/libcloud/dns/drivers/cloudflare.py
+++ b/libcloud/dns/drivers/cloudflare.py
@@ -67,9 +67,20 @@ class CloudFlareDNSResponse(JsonResponse):
 
     def parse_body(self):
         body = super(CloudFlareDNSResponse, self).parse_body()
+
         result = body.get('result', None)
         error_code = body.get('err_code', None)
         msg = body.get('msg', None)
+        is_error_result = result == 'error'
+
+        context= self.connection.context or {}
+        context_record_id = context.get('record_id', None)
+
+        if (is_error_result and 'invalid record id' in msg.lower()
+            and context_record_id):
+            raise RecordDoesNotExistError(value=msg,
+                                          driver=self.connection.driver,
+                                          record_id=context_record_id)
 
         if error_code == 'E_UNAUTH':
             raise InvalidCredsError(msg)
@@ -162,12 +173,14 @@ class CloudFlareDNSDriver(DNSDriver):
         params['content'] = data or record.data
         params['ttl'] = extra.get('ttl', None) or record.extra['ttl']
 
+        self.connection.set_context({'record_id': record.id})
         result = self.connection.request(action='rec_edit', 
params=params).object
         record = self._to_record(zone=record.zone, 
item=result['response']['rec']['obj'])
         return record
 
     def delete_record(self, record):
         params = {'z': record.zone.domain, 'id': record.id}
+        self.connection.set_context({'record_id': record.id})
         result = self.connection.request(action='rec_delete', 
params=params).object
         return result.get('result', None) == 'success'
 

Reply via email to