update variable names

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

Branch: refs/heads/trunk
Commit: 75111a446e8323df607c17703bfb4303eb966dde
Parents: 45fea8d
Author: Samuel Chong <samuelcho...@gmail.com>
Authored: Tue Nov 8 15:16:38 2016 +1100
Committer: Samuel Chong <samuelcho...@gmail.com>
Committed: Tue Nov 8 15:16:38 2016 +1100

----------------------------------------------------------------------
 libcloud/common/dimensiondata.py | 39 +++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/75111a44/libcloud/common/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/common/dimensiondata.py b/libcloud/common/dimensiondata.py
index 0a868b8..c58d5dd 100644
--- a/libcloud/common/dimensiondata.py
+++ b/libcloud/common/dimensiondata.py
@@ -372,8 +372,16 @@ class DimensionDataConnection(ConnectionUserAndKey):
 
     api_path_version_1 = '/oec'
     api_path_version_2 = '/caas'
-    api_version_1 = '0.9'
-    api_version_2 = '2.3'
+    api_version_1 = 0.9
+
+    # Earliest version supported
+    oldest_api_version = 2.2
+
+    # Latest version supported
+    latest_api_version = 2.3
+
+    # Default api version
+    active_api_version = 2.3
 
     _orgId = None
     responseCls = DimensionDataResponse
@@ -396,8 +404,27 @@ class DimensionDataConnection(ConnectionUserAndKey):
             self.host = conn_kwargs['region']['host']
 
         if api_version:
-            if api_version.startswith('2'):
-                self.api_version_2 = api_version
+            if float(api_version) < self.oldest_api_version:
+                msg = 'API Version specified is too old. No longer ' \
+                      'supported. Please upgrade to the latest version {}' \
+                    .format(self.active_api_version)
+
+                raise DimensionDataAPIException(code=None,
+                                                msg=msg,
+                                                driver=self.driver)
+            elif float(api_version) > self.latest_api_version:
+                msg = 'Unsupported API Version. The version specified is ' \
+                      'not release yet. Please use the latest supported ' \
+                      'version {}' \
+                    .format(self.active_api_version)
+
+                raise DimensionDataAPIException(code=None,
+                                                msg=msg,
+                                                driver=self.driver)
+
+            else:
+                # Overwrite default version using the version user specified
+                self.active_api_version = api_version
 
     def add_default_headers(self, headers):
         headers['Authorization'] = \
@@ -419,7 +446,7 @@ class DimensionDataConnection(ConnectionUserAndKey):
     def request_api_2(self, path, action, params=None, data='',
                       headers=None, method='GET'):
         action = "%s/%s/%s/%s" % (self.api_path_version_2,
-                                  self.api_version_2, path, action)
+                                  self.active_api_version, path, action)
 
         return super(DimensionDataConnection, self).request(
             action=action,
@@ -520,7 +547,7 @@ class DimensionDataConnection(ConnectionUserAndKey):
         resources that require a full path instead of just an ID, such as
         networks, and customer snapshots.
         """
-        return ("%s/%s/%s" % (self.api_path_version_2, self.api_version_2,
+        return ("%s/%s/%s" % (self.api_path_version_2, self.active_api_version,
                               self._get_orgId()))
 
     def wait_for_state(self, state, func, poll_interval=2, timeout=60, *args,

Reply via email to