Configure plugins by name
To configure core plugin or service plugins, instead of using class names, simpler names can also be used, ex: service_plugins = router, firewall, lbaas For compatibility with previous versions, the class name of a plugin can be specified instead of its entrypoint name, ex: service_plugins = router, neutron.services.firewall.fwaas_plugin.FirewallPlugin, lbaas DocImpact Implements: blueprint config-plugin-by-name Change-Id: Ia4aaa1d305b160a4d6dab9e227c744727a4c78c2
This commit is contained in:
@@ -25,6 +25,8 @@ from neutron.openstack.common import log as logging
|
||||
from neutron.openstack.common import periodic_task
|
||||
from neutron.plugins.common import constants
|
||||
|
||||
from stevedore import driver
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@@ -108,16 +110,10 @@ class NeutronManager(object):
|
||||
# intentianally to allow v2 plugins to be monitored
|
||||
# for performance metrics.
|
||||
plugin_provider = cfg.CONF.core_plugin
|
||||
LOG.debug(_("Plugin location: %s"), plugin_provider)
|
||||
# If the plugin can't be found let them know gracefully
|
||||
try:
|
||||
LOG.info(_("Loading Plugin: %s"), plugin_provider)
|
||||
plugin_klass = importutils.import_class(plugin_provider)
|
||||
except ImportError:
|
||||
LOG.exception(_("Error loading plugin"))
|
||||
raise Exception(_("Plugin not found. "))
|
||||
LOG.info(_("Loading core plugin: %s"), plugin_provider)
|
||||
self.plugin = self._get_plugin_instance('neutron.core_plugins',
|
||||
plugin_provider)
|
||||
legacy.modernize_quantum_config(cfg.CONF)
|
||||
self.plugin = plugin_klass()
|
||||
|
||||
msg = validate_post_plugin_load()
|
||||
if msg:
|
||||
@@ -131,6 +127,21 @@ class NeutronManager(object):
|
||||
self.service_plugins = {constants.CORE: self.plugin}
|
||||
self._load_service_plugins()
|
||||
|
||||
def _get_plugin_instance(self, namespace, plugin_provider):
|
||||
try:
|
||||
# Try to resolve plugin by name
|
||||
mgr = driver.DriverManager(namespace, plugin_provider)
|
||||
plugin_class = mgr.driver
|
||||
except RuntimeError as e1:
|
||||
# fallback to class name
|
||||
try:
|
||||
plugin_class = importutils.import_class(plugin_provider)
|
||||
except ImportError as e2:
|
||||
LOG.exception(_("Error loading plugin by name, %s"), e1)
|
||||
LOG.exception(_("Error loading plugin by class, %s"), e2)
|
||||
raise ImportError(_("Plugin not found."))
|
||||
return plugin_class()
|
||||
|
||||
def _load_services_from_core_plugin(self):
|
||||
"""Puts core plugin in service_plugins for supported services."""
|
||||
LOG.debug(_("Loading services supported by the core plugin"))
|
||||
@@ -159,13 +170,10 @@ class NeutronManager(object):
|
||||
for provider in plugin_providers:
|
||||
if provider == '':
|
||||
continue
|
||||
try:
|
||||
LOG.info(_("Loading Plugin: %s"), provider)
|
||||
plugin_class = importutils.import_class(provider)
|
||||
except ImportError:
|
||||
LOG.exception(_("Error loading plugin"))
|
||||
raise ImportError(_("Plugin not found."))
|
||||
plugin_inst = plugin_class()
|
||||
|
||||
LOG.info(_("Loading Plugin: %s"), provider)
|
||||
plugin_inst = self._get_plugin_instance('neutron.service_plugins',
|
||||
provider)
|
||||
|
||||
# only one implementation of svc_type allowed
|
||||
# specifying more than one plugin
|
||||
|
||||
Reference in New Issue
Block a user