diff options
author | Davanum Srinivas <dims@linux.vnet.ibm.com> | 2013-01-21 21:18:34 -0500 |
---|---|---|
committer | Davanum Srinivas <dims@linux.vnet.ibm.com> | 2013-01-21 21:18:34 -0500 |
commit | 52bee33eca1719bc01318cdef5f95c2b48992c0a (patch) | |
tree | f309ff294bf2dd3c9c53a25ab20f1afcfb43794b | |
parent | a4d608fa33b328d7ed77c7f9c40ffbb43c0ade6b (diff) | |
download | nova-52bee33eca1719bc01318cdef5f95c2b48992c0a.tar.gz nova-52bee33eca1719bc01318cdef5f95c2b48992c0a.tar.xz nova-52bee33eca1719bc01318cdef5f95c2b48992c0a.zip |
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
-rw-r--r-- | nova/utils.py | 8 | ||||
-rw-r--r-- | nova/virt/baremetal/db/api.py | 13 | ||||
-rw-r--r-- | nova/virt/baremetal/db/migration.py | 3 |
3 files changed, 17 insertions, 7 deletions
diff --git a/nova/utils.py b/nova/utils.py index 75cba0a7c..f9e08fd80 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -507,14 +507,18 @@ def str_dict_replace(s, mapping): class LazyPluggable(object): """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.__pivot = pivot self.__backend = None + self.__config_group = config_group def __get_backend(self): 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: msg = _('Invalid backend: %s') % backend_name raise exception.NovaException(msg) diff --git a/nova/virt/baremetal/db/api.py b/nova/virt/baremetal/db/api.py index 206a59b4f..002425333 100644 --- a/nova/virt/baremetal/db/api.py +++ b/nova/virt/baremetal/db/api.py @@ -50,16 +50,21 @@ from nova import utils # because utils.LazyPluggable doesn't support reading from # option groups. See bug #1093043. db_opts = [ - cfg.StrOpt('baremetal_db_backend', + cfg.StrOpt('db_backend', default='sqlalchemy', - help='The backend to use for db'), + help='The backend to use for bare-metal database'), ] +baremetal_group = cfg.OptGroup(name='baremetal', + title='Baremetal Options') + CONF = cfg.CONF -CONF.register_opts(db_opts) +CONF.register_group(baremetal_group) +CONF.register_opts(db_opts, baremetal_group) IMPL = utils.LazyPluggable( - 'baremetal_db_backend', + 'db_backend', + config_group='baremetal', sqlalchemy='nova.virt.baremetal.db.sqlalchemy.api') diff --git a/nova/virt/baremetal/db/migration.py b/nova/virt/baremetal/db/migration.py index 40631bf45..d630ccf65 100644 --- a/nova/virt/baremetal/db/migration.py +++ b/nova/virt/baremetal/db/migration.py @@ -22,7 +22,8 @@ from nova import utils IMPL = utils.LazyPluggable( - 'baremetal_db_backend', + 'db_backend', + config_group='baremetal', sqlalchemy='nova.virt.baremetal.db.sqlalchemy.migration') INIT_VERSION = 0 |