Refactor Adding service_types to client_plugins

As part of the review https://review.openstack.org/#/c/192529
service_types was added to client_plugins to support the
conditional resource plugin availability.

I found its good to organize this code better by adding
str_key for each key defined in the service_types
so that we no longer have to depend on the index when
multiple service_types are available for a client plugin.

implements blueprint: keystone-based-resource-availability

Change-Id: I352525cce991f664abb28df9569d498cd44baf18
This commit is contained in:
ubuntu 2015-06-19 02:23:21 +05:30 committed by Divakar Padiyar Nandavar
parent 2eafc71af8
commit c9fddd41cb
16 changed files with 55 additions and 43 deletions

View File

@ -19,11 +19,11 @@ from barbicanclient import client as barbican_client
class BarbicanClientPlugin(client_plugin.ClientPlugin): class BarbicanClientPlugin(client_plugin.ClientPlugin):
service_types = ['key-manager'] service_types = [KEY_MANAGER] = ['key-manager']
def _create(self): def _create(self):
endpoint_type = self._get_client_option('barbican', 'endpoint_type') endpoint_type = self._get_client_option('barbican', 'endpoint_type')
endpoint = self.url_for(service_type=self.service_types[0], endpoint = self.url_for(service_type=self.KEY_MANAGER,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
self._keystone_session.auth = self.context.auth_plugin self._keystone_session.auth = self.context.auth_plugin
client = barbican_client.Client( client = barbican_client.Client(

View File

@ -21,17 +21,18 @@ from heat.engine.clients import client_plugin
class CeilometerClientPlugin(client_plugin.ClientPlugin): class CeilometerClientPlugin(client_plugin.ClientPlugin):
exceptions_module = [exc, api_exc] exceptions_module = [exc, api_exc]
service_types = ['metering']
service_types = [METERING] = ['metering']
def _create(self): def _create(self):
con = self.context con = self.context
endpoint_type = self._get_client_option('ceilometer', 'endpoint_type') endpoint_type = self._get_client_option('ceilometer', 'endpoint_type')
endpoint = self.url_for(service_type=self.service_types[0], endpoint = self.url_for(service_type=self.METERING,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
args = { args = {
'auth_url': con.auth_url, 'auth_url': con.auth_url,
'service_type': self.service_types[0], 'service_type': self.METERING,
'project_id': con.tenant, 'project_id': con.tenant,
'token': lambda: self.auth_token, 'token': lambda: self.auth_token,
'endpoint_type': endpoint_type, 'endpoint_type': endpoint_type,

View File

@ -31,19 +31,20 @@ LOG = logging.getLogger(__name__)
class CinderClientPlugin(client_plugin.ClientPlugin): class CinderClientPlugin(client_plugin.ClientPlugin):
exceptions_module = exceptions exceptions_module = exceptions
service_types = ['volume', 'volumev2']
service_types = [VOLUME, VOLUME_V2] = ['volume', 'volumev2']
def get_volume_api_version(self): def get_volume_api_version(self):
'''Returns the most recent API version.''' '''Returns the most recent API version.'''
endpoint_type = self._get_client_option('cinder', 'endpoint_type') endpoint_type = self._get_client_option('cinder', 'endpoint_type')
try: try:
self.url_for(service_type=self.service_types[1], self.url_for(service_type=self.VOLUME_V2,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
return 2 return 2
except ks_exceptions.EndpointNotFound: except ks_exceptions.EndpointNotFound:
try: try:
self.url_for(service_type=self.service_types[0], self.url_for(service_type=self.VOLUME,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
return 1 return 1
except ks_exceptions.EndpointNotFound: except ks_exceptions.EndpointNotFound:
@ -55,10 +56,10 @@ class CinderClientPlugin(client_plugin.ClientPlugin):
volume_api_version = self.get_volume_api_version() volume_api_version = self.get_volume_api_version()
if volume_api_version == 1: if volume_api_version == 1:
service_type = self.service_types[0] service_type = self.VOLUME
client_version = '1' client_version = '1'
elif volume_api_version == 2: elif volume_api_version == 2:
service_type = self.service_types[1] service_type = self.VOLUME_V2
client_version = '2' client_version = '2'
else: else:
raise exception.Error(_('No volume service available.')) raise exception.Error(_('No volume service available.'))

View File

@ -23,11 +23,11 @@ class DesignateClientPlugin(client_plugin.ClientPlugin):
exceptions_module = [exceptions] exceptions_module = [exceptions]
service_types = ['dns'] service_types = [DNS] = ['dns']
def _create(self): def _create(self):
args = self._get_client_args(service_name='designate', args = self._get_client_args(service_name='designate',
service_type=self.service_types[0]) service_type=self.DNS)
return client.Client(auth_url=args['auth_url'], return client.Client(auth_url=args['auth_url'],
project_id=args['project_id'], project_id=args['project_id'],

View File

@ -28,17 +28,18 @@ LOG = logging.getLogger(__name__)
class GlanceClientPlugin(client_plugin.ClientPlugin): class GlanceClientPlugin(client_plugin.ClientPlugin):
exceptions_module = exc exceptions_module = exc
service_types = ['image']
service_types = [IMAGE] = ['image']
def _create(self): def _create(self):
con = self.context con = self.context
endpoint_type = self._get_client_option('glance', 'endpoint_type') endpoint_type = self._get_client_option('glance', 'endpoint_type')
endpoint = self.url_for(service_type=self.service_types[0], endpoint = self.url_for(service_type=self.IMAGE,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
args = { args = {
'auth_url': con.auth_url, 'auth_url': con.auth_url,
'service_type': self.service_types[0], 'service_type': self.IMAGE,
'project_id': con.tenant, 'project_id': con.tenant,
'token': self.auth_token, 'token': self.auth_token,
'endpoint_type': endpoint_type, 'endpoint_type': endpoint_type,

View File

@ -20,8 +20,9 @@ from heat.engine.clients import client_plugin
class HeatClientPlugin(client_plugin.ClientPlugin): class HeatClientPlugin(client_plugin.ClientPlugin):
exceptions_module = exc exceptions_module = exc
service_types = ['orchestration',
'cloudformation'] service_types = [ORCHESTRATION,
CLOUDFORMATION] = ['orchestration', 'cloudformation']
def _create(self): def _create(self):
args = { args = {
@ -62,13 +63,13 @@ class HeatClientPlugin(client_plugin.ClientPlugin):
heat_url = heat_url % {'tenant_id': tenant_id} heat_url = heat_url % {'tenant_id': tenant_id}
else: else:
endpoint_type = self._get_client_option('heat', 'endpoint_type') endpoint_type = self._get_client_option('heat', 'endpoint_type')
heat_url = self.url_for(service_type=self.service_types[0], heat_url = self.url_for(service_type=self.ORCHESTRATION,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
return heat_url return heat_url
def get_heat_cfn_url(self): def get_heat_cfn_url(self):
endpoint_type = self._get_client_option('heat', endpoint_type = self._get_client_option('heat',
'endpoint_type') 'endpoint_type')
heat_cfn_url = self.url_for(service_type=self.service_types[1], heat_cfn_url = self.url_for(service_type=self.CLOUDFORMATION,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
return heat_cfn_url return heat_cfn_url

View File

@ -22,7 +22,8 @@ from heat.engine import constraints
class KeystoneClientPlugin(client_plugin.ClientPlugin): class KeystoneClientPlugin(client_plugin.ClientPlugin):
exceptions_module = exceptions exceptions_module = exceptions
service_types = ['identity']
service_types = [IDENTITY] = ['identity']
def _create(self): def _create(self):
return hkc.KeystoneClient(self.context) return hkc.KeystoneClient(self.context)

View File

@ -22,7 +22,7 @@ magnum_client = importutils.try_import('magnumclient.v1.client')
class MagnumClientPlugin(client_plugin.ClientPlugin): class MagnumClientPlugin(client_plugin.ClientPlugin):
service_types = ['container'] service_types = [CONTAINER] = ['container']
@staticmethod @staticmethod
def is_available(): def is_available():
@ -30,7 +30,7 @@ class MagnumClientPlugin(client_plugin.ClientPlugin):
def _create(self): def _create(self):
endpoint_type = self._get_client_option('magnum', 'endpoint_type') endpoint_type = self._get_client_option('magnum', 'endpoint_type')
endpoint = self.url_for(service_type=self.service_types[0], endpoint = self.url_for(service_type=self.CONTAINER,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
args = { args = {

View File

@ -22,11 +22,12 @@ MANILACLIENT_VERSION = "1"
class ManilaClientPlugin(client_plugin.ClientPlugin): class ManilaClientPlugin(client_plugin.ClientPlugin):
exceptions_module = exceptions exceptions_module = exceptions
service_types = ['share']
service_types = [SHARE] = ['share']
def _create(self): def _create(self):
endpoint_type = self._get_client_option('manila', 'endpoint_type') endpoint_type = self._get_client_option('manila', 'endpoint_type')
endpoint = self.url_for(service_type=self.service_types[0], endpoint = self.url_for(service_type=self.SHARE,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
args = { args = {

View File

@ -21,7 +21,7 @@ mistral_client = importutils.try_import('mistralclient.api.client')
class MistralClientPlugin(client_plugin.ClientPlugin): class MistralClientPlugin(client_plugin.ClientPlugin):
service_types = ['workflowv2'] service_types = [WORKFLOW_V2] = ['workflowv2']
@staticmethod @staticmethod
def is_available(): def is_available():
@ -29,7 +29,7 @@ class MistralClientPlugin(client_plugin.ClientPlugin):
def _create(self): def _create(self):
endpoint_type = self._get_client_option('mistral', 'endpoint_type') endpoint_type = self._get_client_option('mistral', 'endpoint_type')
endpoint = self.url_for(service_type=self.service_types[0], endpoint = self.url_for(service_type=self.WORKFLOW_V2,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
args = { args = {

View File

@ -28,19 +28,20 @@ from heat.engine import constraints
class NeutronClientPlugin(client_plugin.ClientPlugin): class NeutronClientPlugin(client_plugin.ClientPlugin):
exceptions_module = exceptions exceptions_module = exceptions
service_types = ['network']
service_types = [NETWORK] = ['network']
def _create(self): def _create(self):
con = self.context con = self.context
endpoint_type = self._get_client_option('neutron', 'endpoint_type') endpoint_type = self._get_client_option('neutron', 'endpoint_type')
endpoint = self.url_for(service_type=self.service_types[0], endpoint = self.url_for(service_type=self.NETWORK,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
args = { args = {
'auth_url': con.auth_url, 'auth_url': con.auth_url,
'service_type': self.service_types[0], 'service_type': self.NETWORK,
'token': self.auth_token, 'token': self.auth_token,
'endpoint_url': endpoint, 'endpoint_url': endpoint,
'endpoint_type': endpoint_type, 'endpoint_type': endpoint_type,

View File

@ -57,11 +57,12 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
'VERIFY_RESIZE'] 'VERIFY_RESIZE']
exceptions_module = exceptions exceptions_module = exceptions
service_types = ['compute']
service_types = [COMPUTE] = ['compute']
def _create(self): def _create(self):
endpoint_type = self._get_client_option('nova', 'endpoint_type') endpoint_type = self._get_client_option('nova', 'endpoint_type')
management_url = self.url_for(service_type=self.service_types[0], management_url = self.url_for(service_type=self.COMPUTE,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
if hasattr(nc, 'discover_extensions'): if hasattr(nc, 'discover_extensions'):
@ -78,7 +79,7 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
args = { args = {
'project_id': self.context.tenant, 'project_id': self.context.tenant,
'auth_url': self.context.auth_url, 'auth_url': self.context.auth_url,
'service_type': self.service_types[0], 'service_type': self.COMPUTE,
'username': None, 'username': None,
'api_key': None, 'api_key': None,
'extensions': extensions, 'extensions': extensions,

View File

@ -32,15 +32,16 @@ LOG = logging.getLogger(__name__)
class SaharaClientPlugin(client_plugin.ClientPlugin): class SaharaClientPlugin(client_plugin.ClientPlugin):
exceptions_module = sahara_base exceptions_module = sahara_base
service_types = ['data-processing']
service_types = [DATA_PROCESSING] = ['data-processing']
def _create(self): def _create(self):
con = self.context con = self.context
endpoint_type = self._get_client_option('sahara', 'endpoint_type') endpoint_type = self._get_client_option('sahara', 'endpoint_type')
endpoint = self.url_for(service_type=self.service_types[0], endpoint = self.url_for(service_type=self.DATA_PROCESSING,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
args = { args = {
'service_type': self.service_types[0], 'service_type': self.DATA_PROCESSING,
'input_auth_token': self.auth_token, 'input_auth_token': self.auth_token,
'auth_url': con.auth_url, 'auth_url': con.auth_url,
'project_name': con.tenant, 'project_name': con.tenant,

View File

@ -32,7 +32,8 @@ MAX_EPOCH = 2147483647
class SwiftClientPlugin(client_plugin.ClientPlugin): class SwiftClientPlugin(client_plugin.ClientPlugin):
exceptions_module = exceptions exceptions_module = exceptions
service_types = ['object-store']
service_types = [OBJECT_STORE] = ['object-store']
def _create(self): def _create(self):
@ -45,7 +46,7 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
'key': None, 'key': None,
'authurl': None, 'authurl': None,
'preauthtoken': self.auth_token, 'preauthtoken': self.auth_token,
'preauthurl': self.url_for(service_type=self.service_types[0], 'preauthurl': self.url_for(service_type=self.OBJECT_STORE,
endpoint_type=endpoint_type), endpoint_type=endpoint_type),
'os_options': {'endpoint_type': endpoint_type}, 'os_options': {'endpoint_type': endpoint_type},
'cacert': self._get_client_option('swift', 'ca_file'), 'cacert': self._get_client_option('swift', 'ca_file'),

View File

@ -23,14 +23,15 @@ from heat.engine import constraints
class TroveClientPlugin(client_plugin.ClientPlugin): class TroveClientPlugin(client_plugin.ClientPlugin):
exceptions_module = exceptions exceptions_module = exceptions
service_types = ['database']
service_types = [DATABASE] = ['database']
def _create(self): def _create(self):
con = self.context con = self.context
endpoint_type = self._get_client_option('trove', 'endpoint_type') endpoint_type = self._get_client_option('trove', 'endpoint_type')
args = { args = {
'service_type': self.service_types[0], 'service_type': self.DATABASE,
'auth_url': con.auth_url or '', 'auth_url': con.auth_url or '',
'proxy_token': con.auth_token, 'proxy_token': con.auth_token,
'username': None, 'username': None,
@ -41,7 +42,7 @@ class TroveClientPlugin(client_plugin.ClientPlugin):
} }
client = tc.Client('1.0', **args) client = tc.Client('1.0', **args)
management_url = self.url_for(service_type=self.service_types[0], management_url = self.url_for(service_type=self.DATABASE,
endpoint_type=endpoint_type) endpoint_type=endpoint_type)
client.client.auth_token = con.auth_token client.client.auth_token = con.auth_token
client.client.management_url = management_url client.client.management_url = management_url

View File

@ -26,7 +26,8 @@ from heat.engine.clients import client_plugin
class ZaqarClientPlugin(client_plugin.ClientPlugin): class ZaqarClientPlugin(client_plugin.ClientPlugin):
exceptions_module = zaqar_errors exceptions_module = zaqar_errors
service_types = ['messaging']
service_types = [MESSAGING] = ['messaging']
DEFAULT_TTL = 3600 DEFAULT_TTL = 3600
@ -43,12 +44,12 @@ class ZaqarClientPlugin(client_plugin.ClientPlugin):
'os_auth_token': con.auth_token, 'os_auth_token': con.auth_token,
'os_auth_url': con.auth_url, 'os_auth_url': con.auth_url,
'os_project_id': tenant_id, 'os_project_id': tenant_id,
'os_service_type': self.service_types[0], 'os_service_type': self.MESSAGING,
} }
auth_opts = {'backend': 'keystone', auth_opts = {'backend': 'keystone',
'options': opts} 'options': opts}
conf = {'auth_opts': auth_opts} conf = {'auth_opts': auth_opts}
endpoint = self.url_for(service_type=self.service_types[0]) endpoint = self.url_for(service_type=self.MESSAGING)
client = zaqarclient.Client(url=endpoint, conf=conf, version=1.1) client = zaqarclient.Client(url=endpoint, conf=conf, version=1.1)