diff options
| author | Dean Troyer <dtroyer@gmail.com> | 2013-11-20 18:02:09 -0600 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2013-11-21 01:27:10 -0600 |
| commit | 9062811d10f2ab660ce38f9bd20be9c52daa9479 (patch) | |
| tree | d01b271b1ae7c968c1c009cd6f7dada5ef1a3a37 /openstackclient/common | |
| parent | d45187a0c163187649e29931d21c4607379d1e73 (diff) | |
| download | python-openstackclient-9062811d10f2ab660ce38f9bd20be9c52daa9479.tar.gz | |
Expand support for command extensions
Allows client libraries to have complete access to the rest of the
OSC ClientManager. In addition, extension libraries can define
global options (for API version options/env vars) and define
versioned API entry points similar to the in-repo commands.
The changes to ClientManager exposed some issues in the existing
object api tests that needed to be cleaned up.
Change-Id: Ic9662edf34c5dd130a2f1a69d2454adefc1f8a95
Diffstat (limited to 'openstackclient/common')
| -rw-r--r-- | openstackclient/common/clientmanager.py | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py index 85f544e4..a0224064 100644 --- a/openstackclient/common/clientmanager.py +++ b/openstackclient/common/clientmanager.py @@ -16,12 +16,10 @@ """Manage access to the clients, including authenticating when needed.""" import logging +import pkg_resources +import sys -from openstackclient.compute import client as compute_client from openstackclient.identity import client as identity_client -from openstackclient.image import client as image_client -from openstackclient.object import client as object_client -from openstackclient.volume import client as volume_client LOG = logging.getLogger(__name__) @@ -42,11 +40,7 @@ class ClientCache(object): class ClientManager(object): """Manages access to API clients, including authentication.""" - compute = ClientCache(compute_client.make_client) identity = ClientCache(identity_client.make_client) - image = ClientCache(image_client.make_client) - object = ClientCache(object_client.make_client) - volume = ClientCache(volume_client.make_client) def __init__(self, token=None, url=None, auth_url=None, project_name=None, project_id=None, username=None, password=None, @@ -93,3 +87,26 @@ class ClientManager(object): # Hope we were given the correct URL. endpoint = self._url return endpoint + + +def get_extension_modules(group): + """Add extension clients""" + mod_list = [] + for ep in pkg_resources.iter_entry_points(group): + LOG.debug('found extension %r' % ep.name) + + __import__(ep.module_name) + module = sys.modules[ep.module_name] + mod_list.append(module) + init_func = getattr(module, 'Initialize', None) + if init_func: + init_func('x') + + setattr( + ClientManager, + ep.name, + ClientCache( + getattr(sys.modules[ep.module_name], 'make_client', None) + ), + ) + return mod_list |
