libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject libcloud git commit: Fix parse_body method for zonomi, vultr and liquidweb dns providers
Date Sat, 03 Oct 2015 20:11:55 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 08556656a -> 637ff0353


Fix parse_body method for zonomi, vultr and liquidweb dns providers

Closes #589

Signed-off-by: Tomaz Muraus <tomaz@apache.org>


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

Branch: refs/heads/trunk
Commit: 637ff0353a6c62553f8c34a7552d9efb98a526fb
Parents: 0855665
Author: Alejandro Pereira <alepereira.dev@gmail.com>
Authored: Wed Sep 30 10:22:49 2015 -0300
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Sat Oct 3 21:58:08 2015 +0200

----------------------------------------------------------------------
 libcloud/common/liquidweb.py         | 27 ++++++---------------------
 libcloud/common/vultr.py             | 26 +++++---------------------
 libcloud/common/zonomi.py            | 26 +++++++-------------------
 libcloud/dns/drivers/vultr.py        | 24 +++++++++++-------------
 libcloud/dns/drivers/worldwidedns.py | 15 ++++++++-------
 5 files changed, 37 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/637ff035/libcloud/common/liquidweb.py
----------------------------------------------------------------------
diff --git a/libcloud/common/liquidweb.py b/libcloud/common/liquidweb.py
index fb12e58..123e82f 100644
--- a/libcloud/common/liquidweb.py
+++ b/libcloud/common/liquidweb.py
@@ -18,7 +18,6 @@ import base64
 from libcloud.common.base import JsonResponse
 from libcloud.common.base import ConnectionUserAndKey
 from libcloud.utils.py3 import b
-from libcloud.utils.py3 import PY3
 from libcloud.common.types import ProviderError
 
 
@@ -165,29 +164,15 @@ class LiquidWebResponse(JsonResponse):
     error_dict = {}
 
     def __init__(self, response, connection):
-        self.connection = connection
-
-        self.headers = dict(response.getheaders())
-        self.error = response.reason
-        self.status = response.status
-
-        # This attribute is used when usng LoggingConnection
-        original_data = getattr(response, '_original_data', None)
-
-        if original_data:
-            self.body = response._original_data
-        else:
-            self.body = self._decompress_response(body=response.read(),
-                                                  headers=self.headers)
-
-        if PY3:
-            self.body = b(self.body).decode('utf-8')
-        self.objects, self.errors = self.parse_body()
-        if not self.success():
+        self.errors = []
+        super(LiquidWebResponse, self).__init__(response=response,
+                                                connection=connection)
+        self.objects, self.errors = self.parse_body_and_errors()
+        if self.errors:
             error = self.errors.pop()
             raise self._make_excp(error, self.status)
 
-    def parse_body(self):
+    def parse_body_and_errors(self):
         data = []
         errors = []
         js = super(LiquidWebResponse, self).parse_body()

http://git-wip-us.apache.org/repos/asf/libcloud/blob/637ff035/libcloud/common/vultr.py
----------------------------------------------------------------------
diff --git a/libcloud/common/vultr.py b/libcloud/common/vultr.py
index 37bc76e..aa57105 100644
--- a/libcloud/common/vultr.py
+++ b/libcloud/common/vultr.py
@@ -1,6 +1,4 @@
 from libcloud.common.base import ConnectionKey, JsonResponse
-from libcloud.utils.misc import lowercase_keys
-from libcloud.utils.py3 import PY3, b
 
 
 __all__ = [
@@ -36,28 +34,14 @@ class VultrResponse(JsonResponse):
 
     def __init__(self, response, connection):
 
-        self.connection = connection
-        self.error = response.reason
-        self.status = response.status
-        self.headers = lowercase_keys(dict(response.getheaders()))
-
-        original_data = getattr(response, '_original_data', None)
-
-        if original_data:
-            self.body = response._original_data
-
-        else:
-            self.body = self._decompress_response(body=response.read(),
-                                                  headers=self.headers)
-
-        if PY3:
-            self.body = b(self.body).decode('utf-8')
-
-        self.objects, self.errors = self.parse_body()
+        self.errors = []
+        super(VultrResponse, self).__init__(response=response,
+                                            connection=connection)
+        self.objects, self.errors = self.parse_body_and_errors()
         if not self.success():
             raise self._make_excp(self.errors[0])
 
-    def parse_body(self):
+    def parse_body_and_errors(self):
         """
         Returns JSON data in a python list.
         """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/637ff035/libcloud/common/zonomi.py
----------------------------------------------------------------------
diff --git a/libcloud/common/zonomi.py b/libcloud/common/zonomi.py
index 6619b10..3ef913d 100644
--- a/libcloud/common/zonomi.py
+++ b/libcloud/common/zonomi.py
@@ -14,7 +14,6 @@
 
 from libcloud.common.base import XmlResponse
 from libcloud.common.base import ConnectionKey
-from libcloud.utils.py3 import b, PY3
 
 
 __all__ = [
@@ -51,25 +50,14 @@ class ZonomiResponse(XmlResponse):
     objects = None
 
     def __init__(self, response, connection):
-        self.connection = connection
-        self.headers = dict(response.getheaders())
-        self.error = response.reason
-        self.status = response.status
-
-        # This attribute is used when using LoggingConnection
-        original_data = getattr(response, '_original_data', None)
-        if original_data:
-            self.body = response._original_data
-        else:
-            self.body = self._decompress_response(body=response.read(),
-                                                  headers=self.headers)
-        if PY3:
-            self.body = b(self.body).decode('utf-8')
-        self.objects, self.errors = self.parse_body()
+        self.errors = []
+        super(ZonomiResponse, self).__init__(response=response,
+                                             connection=connection)
+        self.objects, self.errors = self.parse_body_and_errors()
         if self.errors:
             raise self._make_excp(self.errors[0])
 
-    def parse_body(self):
+    def parse_body_and_errors(self):
         error_dict = {}
         actions = None
         result_counts = None
@@ -116,8 +104,8 @@ class ZonomiResponse(XmlResponse):
 
         return (data, errors)
 
-    # def success(self):
-    #     return (len(self.errors) == 0)
+    def success(self):
+        return (len(self.errors) == 0)
 
     def _make_excp(self, error):
         """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/637ff035/libcloud/dns/drivers/vultr.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/vultr.py b/libcloud/dns/drivers/vultr.py
index 04f7604..3b66d9f 100644
--- a/libcloud/dns/drivers/vultr.py
+++ b/libcloud/dns/drivers/vultr.py
@@ -73,9 +73,9 @@ class VultrDNSDriver(DNSDriver):
         """
         action = '/v1/dns/list'
         params = {'api_key': self.key}
-        response, errors = self.connection.request(action=action,
-                                                   params=params).parse_body()
-        zones = self._to_zones(response[0])
+        response = self.connection.request(action=action,
+                                           params=params)
+        zones = self._to_zones(response.objects[0])
 
         return zones
 
@@ -99,9 +99,9 @@ class VultrDNSDriver(DNSDriver):
 
         action = '/v1/dns/records'
         params = {'domain': zone.domain}
-        response, errors = self.connection.request(action=action,
-                                                   params=params).parse_body()
-        records = self._to_records(response[0], zone=zone)
+        response = self.connection.request(action=action,
+                                           params=params)
+        records = self._to_records(response.objects[0], zone=zone)
 
         return records
 
@@ -118,9 +118,9 @@ class VultrDNSDriver(DNSDriver):
 
         action = '/v1/dns/list'
         params = {'api_key': self.key}
-        response, errors = self.connection.request(action=action,
-                                                   params=params).parse_body()
-        zones = self._to_zones(response[0])
+        response = self.connection.request(action=action,
+                                           params=params)
+        zones = self._to_zones(response.objects[0])
 
         if not self.ex_zone_exists(zone_id, zones):
             raise ZoneDoesNotExistError(value=None, zone_id=zone_id,
@@ -247,10 +247,8 @@ class VultrDNSDriver(DNSDriver):
         params = {'api_key': self.key}
         action = '/v1/dns/create_record'
 
-        response, errors = self.connection.request(action=action,
-                                                   params=params,
-                                                   data=encoded_data,
-                                                   method='POST').parse_body()
+        self.connection.request(action=action, params=params,
+                                data=encoded_data, method='POST')
         updated_zone_records = zone.list_records()
 
         for record in updated_zone_records:

http://git-wip-us.apache.org/repos/asf/libcloud/blob/637ff035/libcloud/dns/drivers/worldwidedns.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/worldwidedns.py b/libcloud/dns/drivers/worldwidedns.py
index f387dc5..50022a0 100644
--- a/libcloud/dns/drivers/worldwidedns.py
+++ b/libcloud/dns/drivers/worldwidedns.py
@@ -71,7 +71,7 @@ class WorldWideDNSDriver(DNSDriver):
         :type     reseller_id: ``str``
 
         :param    secure: Weither to use HTTPS or HTTP. Note: Some providers
-                only support HTTPS, and it is on by default.
+                          only support HTTPS, and it is on by default.
         :type     secure: ``bool``
 
         :param    host: Override hostname used for connections.
@@ -180,10 +180,11 @@ class WorldWideDNSDriver(DNSDriver):
         :type  ttl: ``int``
 
         :param extra: Extra attributes (driver specific) (optional). Values not
-        specified such as *SECURE*, *IP*, *FOLDER*, *HOSTMASTER*, *REFRESH*,
-        *RETRY* and *EXPIRE* will be kept as already is. The same will be for
-        *S(1 to 40)*, *T(1 to 40)* and *D(1 to 40)* if not in raw mode and
-        for *ZONENS* and *ZONEDATA* if it is.
+                      specified such as *SECURE*, *IP*, *FOLDER*, *HOSTMASTER*,
+                      *REFRESH*, *RETRY* and *EXPIRE* will be kept as already
+                      is. The same will be for *S(1 to 40)*, *T(1 to 40)* and
+                      *D(1 to 40)* if not in raw mode and for *ZONENS* and
+                      *ZONEDATA* if it is.
         :type  extra: ``dict``
 
         :param ex_raw: Mode we use to do the update using zone file or not.
@@ -283,8 +284,8 @@ class WorldWideDNSDriver(DNSDriver):
         :type  ttl: ``int``
 
         :param extra: Extra attributes (driver specific). (optional). Possible
-        parameter in here should be *DYN* which values should be 1 for standart
-        and 2 for dynamic. Default is 1.
+                      parameter in here should be *DYN* which values should be
+                      1 for standart and 2 for dynamic. Default is 1.
         :type extra: ``dict``
 
         :rtype: :class:`Zone`


Mime
View raw message