From 712a8c7f9c5c89071f7f3d87a8d4484921581cf6 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 10 May 2012 15:47:59 -0500 Subject: 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 --- openstackclient/identity/client.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'openstackclient/identity') 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, -- cgit v1.2.1