This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit e7c20290ccbada84afaecd6ddf29f30c892d0dbd
Author: Tomaz Muraus <[email protected]>
AuthorDate: Sun Dec 27 17:52:15 2020 +0100

    Update CloudFlare DNS driver to correctly throws "RecordAlreadyExists"
    error on various error responses.
---
 CHANGES.rst                        | 5 +++++
 libcloud/dns/drivers/cloudflare.py | 9 +++++++++
 2 files changed, 14 insertions(+)

diff --git a/CHANGES.rst b/CHANGES.rst
index 394439a..c2b4ca3 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -192,6 +192,11 @@ DNS
   (GITHUB-1504)
   [Dimitris Galanis - @dimgal1]
 
+- [CloudFlare] Update driver so it correctly throws
+  ``RecordAlreadyExists`` error on various error responses which represent
+  this error.
+  [Tomaz Muraus - @Kami]
+
 Changes in Apache Libcloud 3.2.0
 --------------------------------
 
diff --git a/libcloud/dns/drivers/cloudflare.py 
b/libcloud/dns/drivers/cloudflare.py
index 607135b..d13e98e 100644
--- a/libcloud/dns/drivers/cloudflare.py
+++ b/libcloud/dns/drivers/cloudflare.py
@@ -96,6 +96,10 @@ class CloudFlareDNSResponse(JsonResponse):
         1061: (ZoneAlreadyExistsError, ['zone_id']),
         1002: (RecordDoesNotExistError, ['record_id']),
         81053: (RecordAlreadyExistsError, ['record_id']),
+        # 81057: The record already exists.
+        81057: (RecordAlreadyExistsError, []),
+        # 81058: A record with those settings already exists.
+        81058: (RecordAlreadyExistsError, ['record_id']),
     }
 
     def success(self):
@@ -132,6 +136,11 @@ class CloudFlareDNSResponse(JsonResponse):
                 'driver': self.connection.driver,
             }
 
+            if error['code'] == 81057:
+                # Record id is not available when creating a record and not 
updating
+                # it
+                kwargs["record_id"] = "unknown"
+
             merge_valid_keys(kwargs, context, self.connection.context)
 
             raise exception_class(**kwargs)

Reply via email to