Merge "Adds service_types to client_plugins"

This commit is contained in:
Jenkins 2015-06-18 10:08:11 +00:00 committed by Gerrit Code Review
commit 96fc9f8123
17 changed files with 52 additions and 25 deletions

View File

@ -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 = {

View File

@ -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

View File

@ -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(

View File

@ -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,

View File

@ -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.'))

View File

@ -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,

View File

@ -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

View File

@ -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)

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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'),

View File

@ -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

View File

@ -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)

View File

@ -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):