Moved configuration options of dragonflow

Change-Id: I92c08efc65bfea552af7817a577689afa4a0a3a1
Implements: blueprint centralize-config-options
This commit is contained in:
Rajiv Kumar 2016-12-11 22:17:16 +05:30
parent 01d5a7483d
commit ce3b78fe1c
7 changed files with 74 additions and 18 deletions

View File

@ -16,9 +16,9 @@ from dragonflow.conf import df_active_port_detection
from dragonflow.conf import df_common_params
from dragonflow.conf import df_dhcp
from dragonflow.conf import df_dnat
from dragonflow.conf import df_l2
from dragonflow.conf import df_metadata_service
from dragonflow.conf import df_ryu
from dragonflow.conf import l2_ml2
CONF = cfg.CONF
@ -28,6 +28,6 @@ df_common_params.register_opts()
df_dhcp.register_opts()
df_metadata_service.register_opts()
df_active_port_detection.register_opts()
l2_ml2.register_opts()
df_l2.register_opts()
df_dnat.register_opts()
df_ryu.register_opts()

View File

@ -164,3 +164,7 @@ df_opts = [
def register_opts():
cfg.CONF.register_opts(df_opts, 'df')
def list_opts():
return {'df': df_opts}

View File

@ -35,3 +35,7 @@ df_dhcp_opts = [
def register_opts():
cfg.CONF.register_opts(df_dhcp_opts, 'df_dhcp_app')
def list_opts():
return {'df_dhcp_app': df_dhcp_opts}

View File

@ -32,3 +32,7 @@ df_dnat_app_opts = [
def register_opts():
cfg.CONF.register_opts(df_dnat_app_opts, group='df_dnat_app')
def list_opts():
return {'df_dnat_app': df_dnat_app_opts}

View File

@ -39,3 +39,7 @@ df_l2_app_opts = [
def register_opts():
cfg.CONF.register_opts(df_l2_app_opts, group='df_l2_app')
def list_opts():
return {'df_l2_app': df_l2_app_opts}

View File

@ -28,3 +28,7 @@ df_ryu_opts = [
def register_opts():
cfg.CONF.register_opts(df_ryu_opts, 'df_ryu')
def list_opts():
return {'df_ryu': df_ryu_opts}

View File

@ -10,22 +10,58 @@
# License for the specific language governing permissions and limitations
# under the License.
from dragonflow.conf import df_active_port_detection
from dragonflow.conf import df_common_params
from dragonflow.conf import df_dhcp
from dragonflow.conf import df_dnat
from dragonflow.conf import df_metadata_service
from dragonflow.conf import df_ryu
from dragonflow.conf import l2_ml2
"""
This is the single point of entry to generate the sample configuration
file for dragonflow. It collects all the necessary info from the other modules
in this package. It is assumed that:
* every other module in this package has a 'list_opts' function which
return a dict where
* the keys are strings which are the group names
* the value of each key is a list of config options for that group
* the dragonflow.conf package doesn't have further packages with config options
* this module is only used in the context of sample file generation
"""
import collections
import imp
import os
import pkgutil
from dragonflow._i18n import _ as _i18
LIST_OPTS_FUNC_NAME = "list_opts"
def list_opts():
return [
('df', df_common_params.df_opts),
('df_ryu', df_ryu.df_ryu_opts),
('df_dhcp_app', df_dhcp.df_dhcp_opts),
('df_dnat_app', df_dnat.df_dnat_app_opts),
('df_l2_app', l2_ml2.df_l2_app_opts),
('df_metadata', df_metadata_service.df_metadata_opts),
('df_active_port_detection',
df_active_port_detection.df_active_port_detection_opts)]
opts = collections.defaultdict(list)
imported_modules = _import_modules()
_append_config_options(imported_modules, opts)
return [(key, val) for key, val in opts.items()]
def _import_modules():
imported_modules = []
package_path = os.path.dirname(os.path.abspath(__file__))
for _, modname, ispkg in pkgutil.iter_modules(path=[package_path]):
if modname == __name__.split('.')[-1] or ispkg:
continue
path = ('%s/%s.py' % (package_path, modname))
mod = imp.load_source(modname, path)
if not hasattr(mod, LIST_OPTS_FUNC_NAME):
msg = _i18("The module '%s' should have a '%s' function which "
"returns the config options." % (mod.__name__,
LIST_OPTS_FUNC_NAME))
raise Exception(msg)
else:
imported_modules.append(mod)
return imported_modules
def _append_config_options(imported_modules, config_options):
for mod in imported_modules:
configs = mod.list_opts()
for key, val in configs.items():
config_options[key].extend(val)