libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [07/14] libcloud git commit: Throw RecordDoesNotExist exception if an invalid record is referenced.
Date Sun, 06 Dec 2015 06:32:45 GMT
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/0d7f7f28
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/0d7f7f28
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/0d7f7f28

Branch: refs/heads/trunk
Commit: 0d7f7f28ae0fd988b424c7dece7dcf73b2625ba1
Parents: b513396
Author: Tomaz Muraus <tomaz@tomaz.me>
Authored: Sun Nov 22 22:50:02 2015 +0100
Committer: Tomaz Muraus <tomaz@tomaz.me>
Committed: Sun Dec 6 13:01:24 2015 +0800

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


http://git-wip-us.apache.org/repos/asf/libcloud/blob/0d7f7f28/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'
 


Mime
View raw message