From bc8bdd426cc791388c6829649d1de5bea4d4c7f2 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam Date: Wed, 17 Jun 2015 10:16:34 +0530 Subject: [PATCH] Adds service_types to client_plugins service_types is added to client_plugins to support the conditional resource plugin availability. implements blueprint: keystone-based-resource-availability Change-Id: I28d606416acd1d47a09f3c62b5236b5f53583f60 --- contrib/heat_magnum/heat_magnum/client.py | 4 +++- heat/engine/clients/client_plugin.py | 4 ++++ heat/engine/clients/os/barbican.py | 4 +++- heat/engine/clients/os/ceilometer.py | 5 +++-- heat/engine/clients/os/cinder.py | 10 ++++++---- heat/engine/clients/os/glance.py | 5 +++-- heat/engine/clients/os/heat_plugin.py | 6 ++++-- heat/engine/clients/os/keystone.py | 1 + heat/engine/clients/os/manila.py | 3 ++- heat/engine/clients/os/mistral.py | 4 +++- heat/engine/clients/os/neutron.py | 5 +++-- heat/engine/clients/os/nova.py | 5 +++-- heat/engine/clients/os/sahara.py | 5 +++-- heat/engine/clients/os/swift.py | 3 ++- heat/engine/clients/os/trove.py | 5 +++-- heat/engine/clients/os/zaqar.py | 5 +++-- heat/tests/test_clients.py | 3 +++ 17 files changed, 52 insertions(+), 25 deletions(-) diff --git a/contrib/heat_magnum/heat_magnum/client.py b/contrib/heat_magnum/heat_magnum/client.py index dc12ce0c29..da458e6b89 100644 --- a/contrib/heat_magnum/heat_magnum/client.py +++ b/contrib/heat_magnum/heat_magnum/client.py @@ -22,9 +22,11 @@ magnum_client = importutils.try_import('magnumclient.v1.client') class MagnumClientPlugin(client_plugin.ClientPlugin): + service_types = ['container'] + def _create(self): endpoint_type = self._get_client_option('magnum', 'endpoint_type') - endpoint = self.url_for(service_type='container', + endpoint = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) args = { diff --git a/heat/engine/clients/client_plugin.py b/heat/engine/clients/client_plugin.py index a5d93963ca..9dc8b8b283 100644 --- a/heat/engine/clients/client_plugin.py +++ b/heat/engine/clients/client_plugin.py @@ -32,6 +32,10 @@ class ClientPlugin(object): # may emit exceptions_module = None + # supported service types, service like cinder support multiple service + # types, so its used in list format + service_types = [] + def __init__(self, context): self.context = context self.clients = context.clients diff --git a/heat/engine/clients/os/barbican.py b/heat/engine/clients/os/barbican.py index bb2a31bb09..a504def675 100644 --- a/heat/engine/clients/os/barbican.py +++ b/heat/engine/clients/os/barbican.py @@ -19,9 +19,11 @@ from barbicanclient import client as barbican_client class BarbicanClientPlugin(client_plugin.ClientPlugin): + service_types = ['key-manager'] + def _create(self): endpoint_type = self._get_client_option('barbican', 'endpoint_type') - endpoint = self.url_for(service_type='key-manager', + endpoint = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) self._keystone_session.auth = self.context.auth_plugin client = barbican_client.Client( diff --git a/heat/engine/clients/os/ceilometer.py b/heat/engine/clients/os/ceilometer.py index 53d948b09d..de467624d5 100644 --- a/heat/engine/clients/os/ceilometer.py +++ b/heat/engine/clients/os/ceilometer.py @@ -21,16 +21,17 @@ from heat.engine.clients import client_plugin class CeilometerClientPlugin(client_plugin.ClientPlugin): exceptions_module = [exc, api_exc] + service_types = ['metering'] def _create(self): con = self.context endpoint_type = self._get_client_option('ceilometer', 'endpoint_type') - endpoint = self.url_for(service_type='metering', + endpoint = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) args = { 'auth_url': con.auth_url, - 'service_type': 'metering', + 'service_type': self.service_types[0], 'project_id': con.tenant, 'token': lambda: self.auth_token, 'endpoint_type': endpoint_type, diff --git a/heat/engine/clients/os/cinder.py b/heat/engine/clients/os/cinder.py index 735f18244c..6822df6c3f 100644 --- a/heat/engine/clients/os/cinder.py +++ b/heat/engine/clients/os/cinder.py @@ -31,17 +31,19 @@ LOG = logging.getLogger(__name__) class CinderClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions + service_types = ['volume', 'volumev2'] def get_volume_api_version(self): '''Returns the most recent API version.''' endpoint_type = self._get_client_option('cinder', 'endpoint_type') try: - self.url_for(service_type='volumev2', endpoint_type=endpoint_type) + self.url_for(service_type=self.service_types[1], + endpoint_type=endpoint_type) return 2 except ks_exceptions.EndpointNotFound: try: - self.url_for(service_type='volume', + self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) return 1 except ks_exceptions.EndpointNotFound: @@ -53,10 +55,10 @@ class CinderClientPlugin(client_plugin.ClientPlugin): volume_api_version = self.get_volume_api_version() if volume_api_version == 1: - service_type = 'volume' + service_type = self.service_types[0] client_version = '1' elif volume_api_version == 2: - service_type = 'volumev2' + service_type = self.service_types[1] client_version = '2' else: raise exception.Error(_('No volume service available.')) diff --git a/heat/engine/clients/os/glance.py b/heat/engine/clients/os/glance.py index e02f120030..552399fea4 100644 --- a/heat/engine/clients/os/glance.py +++ b/heat/engine/clients/os/glance.py @@ -28,16 +28,17 @@ LOG = logging.getLogger(__name__) class GlanceClientPlugin(client_plugin.ClientPlugin): exceptions_module = exc + service_types = ['image'] def _create(self): con = self.context endpoint_type = self._get_client_option('glance', 'endpoint_type') - endpoint = self.url_for(service_type='image', + endpoint = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) args = { 'auth_url': con.auth_url, - 'service_type': 'image', + 'service_type': self.service_types[0], 'project_id': con.tenant, 'token': self.auth_token, 'endpoint_type': endpoint_type, diff --git a/heat/engine/clients/os/heat_plugin.py b/heat/engine/clients/os/heat_plugin.py index 7517774296..153982364a 100644 --- a/heat/engine/clients/os/heat_plugin.py +++ b/heat/engine/clients/os/heat_plugin.py @@ -20,6 +20,8 @@ from heat.engine.clients import client_plugin class HeatClientPlugin(client_plugin.ClientPlugin): exceptions_module = exc + service_types = ['orchestration', + 'cloudformation'] def _create(self): args = { @@ -60,13 +62,13 @@ class HeatClientPlugin(client_plugin.ClientPlugin): heat_url = heat_url % {'tenant_id': tenant_id} else: endpoint_type = self._get_client_option('heat', 'endpoint_type') - heat_url = self.url_for(service_type='orchestration', + heat_url = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) return heat_url def get_heat_cfn_url(self): endpoint_type = self._get_client_option('heat', 'endpoint_type') - heat_cfn_url = self.url_for(service_type='cloudformation', + heat_cfn_url = self.url_for(service_type=self.service_types[1], endpoint_type=endpoint_type) return heat_cfn_url diff --git a/heat/engine/clients/os/keystone.py b/heat/engine/clients/os/keystone.py index 3c749c43fe..8bb49e3cb8 100644 --- a/heat/engine/clients/os/keystone.py +++ b/heat/engine/clients/os/keystone.py @@ -22,6 +22,7 @@ from heat.engine import constraints class KeystoneClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions + service_types = ['identity'] def _create(self): return hkc.KeystoneClient(self.context) diff --git a/heat/engine/clients/os/manila.py b/heat/engine/clients/os/manila.py index 83b44f99e9..0a15d2422e 100644 --- a/heat/engine/clients/os/manila.py +++ b/heat/engine/clients/os/manila.py @@ -21,6 +21,7 @@ MANILACLIENT_VERSION = "1" class ManilaClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions + service_types = ['share'] @staticmethod def is_available(): @@ -28,7 +29,7 @@ class ManilaClientPlugin(client_plugin.ClientPlugin): def _create(self): endpoint_type = self._get_client_option('manila', 'endpoint_type') - endpoint = self.url_for(service_type='share', + endpoint = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) args = { diff --git a/heat/engine/clients/os/mistral.py b/heat/engine/clients/os/mistral.py index f754d40519..2a85a539d2 100644 --- a/heat/engine/clients/os/mistral.py +++ b/heat/engine/clients/os/mistral.py @@ -21,13 +21,15 @@ mistral_client = importutils.try_import('mistralclient.api.client') class MistralClientPlugin(client_plugin.ClientPlugin): + service_types = ['workflowv2'] + @staticmethod def is_available(): return mistral_base is not None def _create(self): endpoint_type = self._get_client_option('mistral', 'endpoint_type') - endpoint = self.url_for(service_type='workflowv2', + endpoint = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) args = { diff --git a/heat/engine/clients/os/neutron.py b/heat/engine/clients/os/neutron.py index 399801e32b..04ddd8c443 100644 --- a/heat/engine/clients/os/neutron.py +++ b/heat/engine/clients/os/neutron.py @@ -28,18 +28,19 @@ from heat.engine import constraints class NeutronClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions + service_types = ['network'] def _create(self): con = self.context endpoint_type = self._get_client_option('neutron', 'endpoint_type') - endpoint = self.url_for(service_type='network', + endpoint = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) args = { 'auth_url': con.auth_url, - 'service_type': 'network', + 'service_type': self.service_types[0], 'token': self.auth_token, 'endpoint_url': endpoint, 'endpoint_type': endpoint_type, diff --git a/heat/engine/clients/os/nova.py b/heat/engine/clients/os/nova.py index 97495cf9ed..c17f81e2b6 100644 --- a/heat/engine/clients/os/nova.py +++ b/heat/engine/clients/os/nova.py @@ -58,10 +58,11 @@ class NovaClientPlugin(client_plugin.ClientPlugin): 'VERIFY_RESIZE'] exceptions_module = exceptions + service_types = ['compute'] def _create(self): endpoint_type = self._get_client_option('nova', 'endpoint_type') - management_url = self.url_for(service_type='compute', + management_url = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) computeshell = novashell.OpenStackComputeShell() @@ -70,7 +71,7 @@ class NovaClientPlugin(client_plugin.ClientPlugin): args = { 'project_id': self.context.tenant, 'auth_url': self.context.auth_url, - 'service_type': 'compute', + 'service_type': self.service_types[0], 'username': None, 'api_key': None, 'extensions': extensions, diff --git a/heat/engine/clients/os/sahara.py b/heat/engine/clients/os/sahara.py index 98d72d7248..a47259d030 100644 --- a/heat/engine/clients/os/sahara.py +++ b/heat/engine/clients/os/sahara.py @@ -32,14 +32,15 @@ LOG = logging.getLogger(__name__) class SaharaClientPlugin(client_plugin.ClientPlugin): exceptions_module = sahara_base + service_types = ['data-processing'] def _create(self): con = self.context endpoint_type = self._get_client_option('sahara', 'endpoint_type') - endpoint = self.url_for(service_type='data-processing', + endpoint = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) args = { - 'service_type': 'data-processing', + 'service_type': self.service_types[0], 'input_auth_token': self.auth_token, 'auth_url': con.auth_url, 'project_name': con.tenant, diff --git a/heat/engine/clients/os/swift.py b/heat/engine/clients/os/swift.py index 65a290ad12..8e3f2fef25 100644 --- a/heat/engine/clients/os/swift.py +++ b/heat/engine/clients/os/swift.py @@ -32,6 +32,7 @@ MAX_EPOCH = 2147483647 class SwiftClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions + service_types = ['object-store'] def _create(self): @@ -44,7 +45,7 @@ class SwiftClientPlugin(client_plugin.ClientPlugin): 'key': None, 'authurl': None, 'preauthtoken': self.auth_token, - 'preauthurl': self.url_for(service_type='object-store', + 'preauthurl': self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type), 'os_options': {'endpoint_type': endpoint_type}, 'cacert': self._get_client_option('swift', 'ca_file'), diff --git a/heat/engine/clients/os/trove.py b/heat/engine/clients/os/trove.py index 2d654df7aa..adf6fd513c 100644 --- a/heat/engine/clients/os/trove.py +++ b/heat/engine/clients/os/trove.py @@ -23,13 +23,14 @@ from heat.engine import constraints class TroveClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions + service_types = ['database'] def _create(self): con = self.context endpoint_type = self._get_client_option('trove', 'endpoint_type') args = { - 'service_type': 'database', + 'service_type': self.service_types[0], 'auth_url': con.auth_url or '', 'proxy_token': con.auth_token, 'username': None, @@ -40,7 +41,7 @@ class TroveClientPlugin(client_plugin.ClientPlugin): } client = tc.Client('1.0', **args) - management_url = self.url_for(service_type='database', + management_url = self.url_for(service_type=self.service_types[0], endpoint_type=endpoint_type) client.client.auth_token = con.auth_token client.client.management_url = management_url diff --git a/heat/engine/clients/os/zaqar.py b/heat/engine/clients/os/zaqar.py index 45c110ec2e..3798174f86 100644 --- a/heat/engine/clients/os/zaqar.py +++ b/heat/engine/clients/os/zaqar.py @@ -26,6 +26,7 @@ from heat.engine.clients import client_plugin class ZaqarClientPlugin(client_plugin.ClientPlugin): exceptions_module = zaqar_errors + service_types = ['messaging'] def _create(self): return self.create_for_tenant(self.context.tenant_id) @@ -40,12 +41,12 @@ class ZaqarClientPlugin(client_plugin.ClientPlugin): 'os_auth_token': con.auth_token, 'os_auth_url': con.auth_url, 'os_project_id': tenant_id, - 'os_service_type': 'messaging', + 'os_service_type': self.service_types[0], } auth_opts = {'backend': 'keystone', 'options': opts} conf = {'auth_opts': auth_opts} - endpoint = self.url_for(service_type='messaging') + endpoint = self.url_for(service_type=self.service_types[0]) client = zaqarclient.Client(url=endpoint, conf=conf, version=1.1) diff --git a/heat/tests/test_clients.py b/heat/tests/test_clients.py index 00fefd33fa..a24c4b2641 100644 --- a/heat/tests/test_clients.py +++ b/heat/tests/test_clients.py @@ -348,6 +348,9 @@ class TestClientPluginsInitialise(common.HeatTestCase): self.assertEqual(con, plugin.context) self.assertIsNone(plugin._client) self.assertTrue(clients.has_client(plugin_name)) + self.assertTrue(isinstance(plugin.service_types, list)) + self.assertTrue(len(plugin.service_types) >= 1, + 'service_types is not defined for plugin') class TestIsNotFound(common.HeatTestCase):