summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2012-05-10 15:47:59 -0500
committerDean Troyer <dtroyer@gmail.com>2012-05-10 15:52:15 -0500
commit712a8c7f9c5c89071f7f3d87a8d4484921581cf6 (patch)
tree956d2609e54436b72e02cda56918d55aae111f46 /openstackclient
parent9d224b3bf811c9c0b41246b7bfe937dd172ed95e (diff)
downloadpython-openstackclient-712a8c7f9c5c89071f7f3d87a8d4484921581cf6.tar.gz
Add API versioning support
* Specific versions supported are managed in XXXXXX.client.py with a mapping from version to client class. This is based on the scheme that is included in novaclient; none of the other client libs have that capability. Change-Id: I930b197f1189e7f52c3b0096e73e0773cf925542
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/common/clientmanager.py8
-rw-r--r--openstackclient/common/exceptions.py6
-rw-r--r--openstackclient/common/utils.py8
-rw-r--r--openstackclient/compute/client.py2
-rw-r--r--openstackclient/identity/client.py25
-rw-r--r--openstackclient/shell.py4
6 files changed, 40 insertions, 13 deletions
diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py
index e3f8588a..0a9f9102 100644
--- a/openstackclient/common/clientmanager.py
+++ b/openstackclient/common/clientmanager.py
@@ -54,9 +54,7 @@ class ClientManager(object):
tenant_name=None, tenant_id=None,
username=None, password=None,
region_name=None,
- identity_api_version=None,
- compute_api_version=None,
- image_api_version=None,
+ api_version=None,
):
self._token = token
self._url = url
@@ -66,9 +64,7 @@ class ClientManager(object):
self._username = username
self._password = password
self._region_name = region_name
- self._identity_api_version = identity_api_version
- self._compute_api_version = compute_api_version
- self._image_api_version = image_api_version
+ self._api_version = api_version
self._service_catalog = None
if not self._url:
diff --git a/openstackclient/common/exceptions.py b/openstackclient/common/exceptions.py
index 4b4a0fb4..aa070b37 100644
--- a/openstackclient/common/exceptions.py
+++ b/openstackclient/common/exceptions.py
@@ -39,6 +39,12 @@ class EndpointNotFound(Exception):
pass
+class UnsupportedVersion(Exception):
+ """Indicates that the user is trying to use an unsupported
+ version of the API"""
+ pass
+
+
class ClientException(Exception):
"""
The base exception class for all exceptions this library raises.
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py
index fe0e5bcb..e0f35ad4 100644
--- a/openstackclient/common/utils.py
+++ b/openstackclient/common/utils.py
@@ -20,6 +20,7 @@ Common client utilities
"""
import os
+import sys
import uuid
import prettytable
@@ -67,3 +68,10 @@ def env(*vars, **kwargs):
if value:
return value
return kwargs.get('default', '')
+
+
+def import_class(import_str):
+ """Returns a class from a string including module and class."""
+ mod_str, _sep, class_str = import_str.rpartition('.')
+ __import__(mod_str)
+ return getattr(sys.modules[mod_str], class_str)
diff --git a/openstackclient/compute/client.py b/openstackclient/compute/client.py
index d37bdfb6..fa37ff55 100644
--- a/openstackclient/compute/client.py
+++ b/openstackclient/compute/client.py
@@ -27,7 +27,7 @@ def make_client(instance):
"""
LOG.debug('instantiating compute client')
client = nova_client.Client(
- version=instance._compute_api_version,
+ version=instance._api_version['compute'],
username=instance._username,
api_key=instance._password,
project_id=instance._tenant_name,
diff --git a/openstackclient/identity/client.py b/openstackclient/identity/client.py
index a19050fa..318bfe32 100644
--- a/openstackclient/identity/client.py
+++ b/openstackclient/identity/client.py
@@ -17,23 +17,42 @@
import logging
-from keystoneclient.v2_0 import client as identity_client
+from openstackclient.common import exceptions as exc
+from openstackclient.common import utils
LOG = logging.getLogger(__name__)
+API_VERSIONS = {
+ '2.0': 'keystoneclient.v2_0.client.Client',
+}
+
+
+def get_client_class(version):
+ """Returns the client class for the requested API version
+ """
+ try:
+ client_path = API_VERSIONS[str(version)]
+ except (KeyError, ValueError):
+ msg = "Invalid client version '%s'. must be one of: %s" % (
+ (version, ', '.join(API_VERSIONS.keys())))
+ raise exc.UnsupportedVersion(msg)
+
+ return utils.import_class(client_path)
+
def make_client(instance):
"""Returns an identity service client.
"""
+ identity_client = get_client_class(instance._api_version['identity'])
if instance._url:
LOG.debug('instantiating identity client: token flow')
- client = identity_client.Client(
+ client = identity_client(
endpoint=instance._url,
token=instance._token,
)
else:
LOG.debug('instantiating identity client: password flow')
- client = identity_client.Client(
+ client = identity_client(
username=instance._username,
password=instance._password,
tenant_name=instance._tenant_name,
diff --git a/openstackclient/shell.py b/openstackclient/shell.py
index 8ffe81fd..94d7c496 100644
--- a/openstackclient/shell.py
+++ b/openstackclient/shell.py
@@ -172,9 +172,7 @@ class OpenStackShell(App):
username=self.options.os_username,
password=self.options.os_password,
region_name=self.options.os_region_name,
- identity_api_version=self.options.os_identity_api_version,
- compute_api_version=self.options.os_compute_api_version,
- image_api_version=self.options.os_image_api_version,
+ api_version=self.api_version,
)
return