Replace usage of LazyPluggable by stevedore driver
Stevedore lib support lazy loading, so this change replace LazyPluggable class by stevedore extentions and remove it Stevedore support usage of driver property since 0.4 release, some of Openstack projects like glance is already using it. Change-Id: I7d384a73861e18cac04e07f75abd60df7f183aa2
This commit is contained in:
committed by
Jay Pipes
parent
43078b5f7f
commit
77ca9fdd83
+3
-4
@@ -13,8 +13,8 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from stevedore import driver
|
||||
|
||||
from nova import utils
|
||||
|
||||
ipv6_backend_opt = cfg.StrOpt('ipv6_backend',
|
||||
default='rfc2462',
|
||||
@@ -27,9 +27,8 @@ IMPL = None
|
||||
|
||||
def reset_backend():
|
||||
global IMPL
|
||||
IMPL = utils.LazyPluggable('ipv6_backend',
|
||||
rfc2462='nova.ipv6.rfc2462',
|
||||
account_identifier='nova.ipv6.account_identifier')
|
||||
IMPL = driver.DriverManager("nova.ipv6_backend",
|
||||
CONF.ipv6_backend).driver
|
||||
|
||||
|
||||
def to_global(prefix, mac, project_id):
|
||||
|
||||
@@ -372,41 +372,6 @@ def get_my_linklocal(interface):
|
||||
raise exception.NovaException(msg)
|
||||
|
||||
|
||||
class LazyPluggable(object):
|
||||
"""A pluggable backend loaded lazily based on some value."""
|
||||
|
||||
def __init__(self, pivot, config_group=None, **backends):
|
||||
self.__backends = backends
|
||||
self.__pivot = pivot
|
||||
self.__backend = None
|
||||
self.__config_group = config_group
|
||||
|
||||
def __get_backend(self):
|
||||
if not self.__backend:
|
||||
if self.__config_group is None:
|
||||
backend_name = CONF[self.__pivot]
|
||||
else:
|
||||
backend_name = CONF[self.__config_group][self.__pivot]
|
||||
if backend_name not in self.__backends:
|
||||
msg = _('Invalid backend: %s') % backend_name
|
||||
raise exception.NovaException(msg)
|
||||
|
||||
backend = self.__backends[backend_name]
|
||||
if isinstance(backend, tuple):
|
||||
name = backend[0]
|
||||
fromlist = backend[1]
|
||||
else:
|
||||
name = backend
|
||||
fromlist = backend
|
||||
|
||||
self.__backend = __import__(name, None, None, fromlist)
|
||||
return self.__backend
|
||||
|
||||
def __getattr__(self, key):
|
||||
backend = self.__get_backend()
|
||||
return getattr(backend, key)
|
||||
|
||||
|
||||
def xhtml_escape(value):
|
||||
"""Escapes a string so it is valid within XML or XHTML.
|
||||
|
||||
|
||||
@@ -170,6 +170,9 @@ nova.api.v3.test_extensions =
|
||||
basic = nova.tests.unit.api.openstack.compute.test_plugins.basic:Basic
|
||||
microversions = nova.tests.unit.api.openstack.compute.test_plugins.microversions:Microversions
|
||||
|
||||
nova.ipv6_backend =
|
||||
rfc2462 = nova.ipv6.rfc2462
|
||||
account_identifier = nova.ipv6.account_identifier
|
||||
|
||||
# These are for backwards compat with Havana notification_driver configuration values
|
||||
oslo.messaging.notify.drivers =
|
||||
|
||||
Reference in New Issue
Block a user