From 23893088f1220bc73cfcc4f6844d9bab189a308b Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Mon, 30 Jun 2014 17:08:56 +1200 Subject: [PATCH] Implement marconi client plugin This moves the client creation code out of a Clients subclass into its own client plugin. The base package has been renamed to heat_marconi since stevedore is used for client plugin loading and the base package will be installed by setuptools, the package marconi might clash with the actual marconi project. Change-Id: Ie824d961fcfa9dafd72cc40ccf207d1c1e0501ad --- contrib/{marconi => heat_marconi}/README.md | 0 .../heat_marconi}/__init__.py | 0 .../heat_marconi/client.py} | 17 +++++++++-------- .../heat_marconi}/resources/__init__.py | 0 .../heat_marconi}/resources/queue.py | 19 ++++++------------- .../heat_marconi}/tests/__init__.py | 0 .../heat_marconi}/tests/test_queue.py | 0 .../requirements.txt | 0 contrib/{marconi => heat_marconi}/setup.cfg | 5 ++++- contrib/{marconi => heat_marconi}/setup.py | 0 10 files changed, 19 insertions(+), 22 deletions(-) rename contrib/{marconi => heat_marconi}/README.md (100%) rename contrib/{marconi/marconi => heat_marconi/heat_marconi}/__init__.py (100%) rename contrib/{marconi/marconi/clients.py => heat_marconi/heat_marconi/client.py} (78%) rename contrib/{marconi/marconi => heat_marconi/heat_marconi}/resources/__init__.py (100%) rename contrib/{marconi/marconi => heat_marconi/heat_marconi}/resources/queue.py (91%) rename contrib/{marconi/marconi => heat_marconi/heat_marconi}/tests/__init__.py (100%) rename contrib/{marconi/marconi => heat_marconi/heat_marconi}/tests/test_queue.py (100%) rename contrib/{marconi => heat_marconi}/requirements.txt (100%) rename contrib/{marconi => heat_marconi}/setup.cfg (90%) rename contrib/{marconi => heat_marconi}/setup.py (100%) diff --git a/contrib/marconi/README.md b/contrib/heat_marconi/README.md similarity index 100% rename from contrib/marconi/README.md rename to contrib/heat_marconi/README.md diff --git a/contrib/marconi/marconi/__init__.py b/contrib/heat_marconi/heat_marconi/__init__.py similarity index 100% rename from contrib/marconi/marconi/__init__.py rename to contrib/heat_marconi/heat_marconi/__init__.py diff --git a/contrib/marconi/marconi/clients.py b/contrib/heat_marconi/heat_marconi/client.py similarity index 78% rename from contrib/marconi/marconi/clients.py rename to contrib/heat_marconi/heat_marconi/client.py index 2ecc700d6..64cad5842 100644 --- a/contrib/marconi/marconi/clients.py +++ b/contrib/heat_marconi/heat_marconi/client.py @@ -11,9 +11,6 @@ # License for the specific language governing permissions and limitations # under the License. -"""Client Library for Marconi Resources.""" - -from heat.engine import clients from heat.openstack.common import log as logging LOG = logging.getLogger(__name__) @@ -23,10 +20,12 @@ try: except ImportError: marconiclient = None +from heat.engine.clients import client_plugin -class Clients(clients.OpenStackClients): - def _marconi(self, service_type="queuing"): +class MarconiClientPlugin(client_plugin.ClientPlugin): + + def _create(self): con = self.context if self.auth_token is None: @@ -37,11 +36,13 @@ class Clients(clients.OpenStackClients): 'os_auth_token': con.auth_token, 'os_auth_url': con.auth_url, 'os_project_id': con.tenant, - 'os_service_type': service_type, + 'os_service_type': 'queuing', } auth_opts = {'backend': 'keystone', 'options': opts} conf = {'auth_opts': auth_opts} - endpoint = self.url_for(service_type=service_type) + endpoint = self.url_for(service_type='queuing') - return marconiclient.Client(url=endpoint, conf=conf) + client = marconiclient.Client(url=endpoint, conf=conf) + + return client diff --git a/contrib/marconi/marconi/resources/__init__.py b/contrib/heat_marconi/heat_marconi/resources/__init__.py similarity index 100% rename from contrib/marconi/marconi/resources/__init__.py rename to contrib/heat_marconi/heat_marconi/resources/__init__.py diff --git a/contrib/marconi/marconi/resources/queue.py b/contrib/heat_marconi/heat_marconi/resources/queue.py similarity index 91% rename from contrib/marconi/marconi/resources/queue.py rename to contrib/heat_marconi/heat_marconi/resources/queue.py index 285d44ebc..93881a138 100644 --- a/contrib/marconi/marconi/resources/queue.py +++ b/contrib/heat_marconi/heat_marconi/resources/queue.py @@ -13,20 +13,17 @@ from heat.common import exception from heat.engine import attributes +from heat.engine import clients from heat.engine import properties from heat.engine import resource -from .. import clients # noqa - -if clients.marconiclient is None: - def resource_mapping(): +def resource_mapping(): + if not clients.has_client('marconi'): return {} -else: - def resource_mapping(): - return { - 'OS::Marconi::Queue': MarconiQueue, - } + return { + 'OS::Marconi::Queue': MarconiQueue, + } class MarconiQueue(resource.Resource): @@ -65,10 +62,6 @@ class MarconiQueue(resource.Resource): ), } - def __init__(self, name, json_snippet, stack): - super(MarconiQueue, self).__init__(name, json_snippet, stack) - self.clients = clients.Clients(self.context) - def marconi(self): return self.clients.client('marconi') diff --git a/contrib/marconi/marconi/tests/__init__.py b/contrib/heat_marconi/heat_marconi/tests/__init__.py similarity index 100% rename from contrib/marconi/marconi/tests/__init__.py rename to contrib/heat_marconi/heat_marconi/tests/__init__.py diff --git a/contrib/marconi/marconi/tests/test_queue.py b/contrib/heat_marconi/heat_marconi/tests/test_queue.py similarity index 100% rename from contrib/marconi/marconi/tests/test_queue.py rename to contrib/heat_marconi/heat_marconi/tests/test_queue.py diff --git a/contrib/marconi/requirements.txt b/contrib/heat_marconi/requirements.txt similarity index 100% rename from contrib/marconi/requirements.txt rename to contrib/heat_marconi/requirements.txt diff --git a/contrib/marconi/setup.cfg b/contrib/heat_marconi/setup.cfg similarity index 90% rename from contrib/marconi/setup.cfg rename to contrib/heat_marconi/setup.cfg index 0ddc5ffe4..82a81591a 100644 --- a/contrib/marconi/setup.cfg +++ b/contrib/heat_marconi/setup.cfg @@ -17,10 +17,13 @@ classifier = Programming Language :: Python :: 2.7 Programming Language :: Python :: 2.6 +packages = + heat_marconi + [files] # Copy to /usr/lib/heat for plugin loading data_files = - lib/heat/marconi = marconi/resources/* + lib/heat/marconi = heat_marconi/resources/* [global] setup-hooks = diff --git a/contrib/marconi/setup.py b/contrib/heat_marconi/setup.py similarity index 100% rename from contrib/marconi/setup.py rename to contrib/heat_marconi/setup.py