From 9062811d10f2ab660ce38f9bd20be9c52daa9479 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 20 Nov 2013 18:02:09 -0600 Subject: 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 --- openstackclient/common/clientmanager.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'openstackclient/common/clientmanager.py') 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 -- cgit v1.2.1