diff options
| author | Dean Troyer <dtroyer@gmail.com> | 2012-05-10 15:47:59 -0500 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2012-05-10 15:52:15 -0500 |
| commit | 712a8c7f9c5c89071f7f3d87a8d4484921581cf6 (patch) | |
| tree | 956d2609e54436b72e02cda56918d55aae111f46 /openstackclient/identity/client.py | |
| parent | 9d224b3bf811c9c0b41246b7bfe937dd172ed95e (diff) | |
| download | python-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/identity/client.py')
| -rw-r--r-- | openstackclient/identity/client.py | 25 |
1 files changed, 22 insertions, 3 deletions
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, |
