Allow registering individual plugin CONF options

Give plugins some more flexibility in registering there own CONF
options.

Change-Id: Id6d47e59e96b7b42c04cecdd53c13a887f60c75b
This commit is contained in:
Jamie Lennox
2014-08-12 07:38:16 +10:00
parent 8f1605e30a
commit feaafdc651
2 changed files with 33 additions and 10 deletions

View File

@@ -171,3 +171,34 @@ class BaseAuthPlugin(object):
kwargs.setdefault(opt.dest, val)
return cls.load_from_options(**kwargs)
@classmethod
def register_conf_options(cls, conf, group):
"""Register the oslo.config options that are needed for a plugin.
:param conf: An oslo.config conf object.
:param string group: The group name that options should be read from.
"""
plugin_opts = cls.get_options()
conf.register_opts(plugin_opts, group=group)
@classmethod
def load_from_conf_options(cls, conf, group, **kwargs):
"""Load the plugin from a CONF object.
Convert the options already registered into a real plugin.
:param conf: An oslo.config conf object.
:param string group: The group name that options should be read from.
:returns plugin: An authentication Plugin.
"""
plugin_opts = cls.get_options()
for opt in plugin_opts:
val = conf[group][opt.dest]
if val is not None:
val = opt.type(val)
kwargs.setdefault(opt.dest, val)
return cls.load_from_options(**kwargs)

View File

@@ -104,13 +104,5 @@ def load_from_conf_options(conf, group, **kwargs):
raise exceptions.NoMatchingPlugin('No plugin name provided for config')
plugin_class = base.get_plugin_class(name)
plugin_opts = plugin_class.get_options()
conf.register_opts(plugin_opts, group=group)
for opt in plugin_opts:
val = conf[group][opt.dest]
if val is not None:
val = opt.type(val)
kwargs.setdefault(opt.dest, val)
return plugin_class.load_from_options(**kwargs)
plugin_class.register_conf_options(conf, group)
return plugin_class.load_from_conf_options(conf, group, **kwargs)