Add support for Option Groups in LazyPluggable

Use @markmc's suggestion to enhance LazyPluggable with an
optional config group. Also fix the baremetal database
backend option to use the "baremetal" config group.

Fixes LP #1093043

Change-Id: I28cf51a2962f516fcef4ced19e30c985220e86dc
This commit is contained in:
Davanum Srinivas
2013-01-21 21:18:34 -05:00
parent 6fee72f8d5
commit 94538a653d

View File

@@ -507,14 +507,18 @@ def str_dict_replace(s, mapping):
class LazyPluggable(object): class LazyPluggable(object):
"""A pluggable backend loaded lazily based on some value.""" """A pluggable backend loaded lazily based on some value."""
def __init__(self, pivot, **backends): def __init__(self, pivot, config_group=None, **backends):
self.__backends = backends self.__backends = backends
self.__pivot = pivot self.__pivot = pivot
self.__backend = None self.__backend = None
self.__config_group = config_group
def __get_backend(self): def __get_backend(self):
if not self.__backend: if not self.__backend:
backend_name = CONF[self.__pivot] 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: if backend_name not in self.__backends:
msg = _('Invalid backend: %s') % backend_name msg = _('Invalid backend: %s') % backend_name
raise exception.NovaException(msg) raise exception.NovaException(msg)