libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] 07/14: [ovh] Refactor ex_datacenter to region for compatibility
Date Sun, 04 Oct 2020 15:39:26 GMT
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 fcfc133113dec8eb07480f7a7e1807a80c8e4bce
Author: Dan Hunsaker <danhunsaker@gmail.com>
AuthorDate: Sun Sep 27 15:25:19 2020 -0600

    [ovh] Refactor ex_datacenter to region for compatibility
    
    Also provide a test mock for a query string generated in reverse order.
---
 libcloud/common/ovh.py            |  2 +-
 libcloud/compute/drivers/ovh.py   | 16 ++++++++++------
 libcloud/test/compute/test_ovh.py |  3 +++
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/libcloud/common/ovh.py b/libcloud/common/ovh.py
index 5c2f9ae..2e1ba76 100644
--- a/libcloud/common/ovh.py
+++ b/libcloud/common/ovh.py
@@ -109,7 +109,7 @@ class OvhConnection(ConnectionUserAndKey):
     allow_insecure = True
 
     def __init__(self, user_id, *args, **kwargs):
-        self.host = ('%s.%s' % (kwargs.pop('ex_datacenter', ''),
+        self.host = ('%s.%s' % (kwargs.pop('region', ''),
                                 API_HOST)).lstrip('.')
         self.consumer_key = kwargs.pop('ex_consumer_key', None)
         if self.consumer_key is None:
diff --git a/libcloud/compute/drivers/ovh.py b/libcloud/compute/drivers/ovh.py
index d59890e..00a05e0 100644
--- a/libcloud/compute/drivers/ovh.py
+++ b/libcloud/compute/drivers/ovh.py
@@ -45,7 +45,7 @@ class OvhNodeDriver(NodeDriver):
     SNAPSHOT_STATE_MAP = OpenStackNodeDriver.SNAPSHOT_STATE_MAP
 
     def __init__(self, key, secret, ex_project_id, ex_consumer_key=None,
-                 ex_datacenter=None):
+                 region=None):
         """
         Instantiate the driver with the given API credentials.
 
@@ -61,21 +61,25 @@ class OvhNodeDriver(NodeDriver):
         :param ex_consumer_key: Your consumer key (required)
         :type ex_consumer_key: ``str``
 
-        :param ex_datacenter: The datacenter to connect to (optional)
-        :type ex_datacenter: ``str``
+        :param region: The datacenter to connect to (optional)
+        :type region: ``str``
 
         :rtype: ``None``
         """
-        self.datacenter = ex_datacenter
+        self.region = region
         self.project_id = ex_project_id
         self.consumer_key = ex_consumer_key
         NodeDriver.__init__(self, key, secret, ex_consumer_key=ex_consumer_key,
-                            ex_datacenter=ex_datacenter)
+                            region=region)
 
     def _get_project_action(self, suffix):
         base_url = '%s/cloud/project/%s/' % (API_ROOT, self.project_id)
         return base_url + suffix
 
+    @classmethod
+    def list_regions(cls):
+        return ['eu', 'ca']
+
     def list_nodes(self, location=None):
         """
         List all nodes.
@@ -547,4 +551,4 @@ class OvhNodeDriver(NodeDriver):
 
     def _ex_connection_class_kwargs(self):
         return {'ex_consumer_key': self.consumer_key,
-                'ex_datacenter': self.datacenter}
+                'region': self.region}
diff --git a/libcloud/test/compute/test_ovh.py b/libcloud/test/compute/test_ovh.py
index 4e8b1e5..ea8303a 100644
--- a/libcloud/test/compute/test_ovh.py
+++ b/libcloud/test/compute/test_ovh.py
@@ -126,6 +126,9 @@ class OvhMockHttp(BaseOvhMockHttp):
         body = self.fixtures.load('volume_snapshot_get_details.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _json_1_0_cloud_subsidiaryPrice_ovhSubsidiary_US_flavorId_foo_id_get(self, method,
url, body, headers):
+        return self._json_1_0_cloud_subsidiaryPrice_flavorId_foo_id_ovhSubsidiary_US_get(method,
url, body, headers)
+
     def _json_1_0_cloud_subsidiaryPrice_flavorId_foo_id_ovhSubsidiary_US_get(self, method,
url, body, headers):
         body = self.fixtures.load('pricing_get.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])


Mime
View raw message