keystone  18.0.0
About: OpenStack Keystone (Core Service: Identity) provides an authentication and authorization service for other OpenStack services. Provides a catalog of endpoints for all OpenStack services.
The "Victoria" series (maintained release).
  Fossies Dox: keystone-18.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

opts.py
Go to the documentation of this file.
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12 
13 """Single point of entry to generate the sample configuration file.
14 
15 This module collects all the necessary info from the other modules in this
16 package. It is assumed that:
17 
18 * Every other module in this package has a 'list_opts' function which
19  returns a dict where:
20 
21  * The keys are strings which are the group names.
22 
23  * The value of each key is a list of config options for that group.
24 
25 * The conf package doesn't have further packages with config options.
26 
27 * This module is only used in the context of sample file generation.
28 
29 """
30 
31 import collections
32 import importlib
33 import os
34 import pkgutil
35 
36 
37 LIST_OPTS_FUNC_NAME = 'list_opts'
38 IGNORED_MODULES = ('opts', 'constants', 'utils')
39 
40 
41 def list_opts():
42  opts = collections.defaultdict(list)
43  module_names = _list_module_names()
44  imported_modules = _import_modules(module_names)
45  _append_config_options(imported_modules, opts)
46  return _tupleize(opts)
47 
48 
49 def _tupleize(d):
50  """Convert a dict of options to the 2-tuple format."""
51  return [(key, value) for key, value in d.items()]
52 
53 
55  module_names = []
56  package_path = os.path.dirname(os.path.abspath(__file__))
57  for _, module_name, ispkg in pkgutil.iter_modules(path=[package_path]):
58  if module_name in IGNORED_MODULES or ispkg:
59  # Skip this module.
60  continue
61  else:
62  module_names.append(module_name)
63  return module_names
64 
65 
66 def _import_modules(module_names):
67  imported_modules = []
68  for module_name in module_names:
69  full_module_path = '.'.join(__name__.split('.')[:-1] + [module_name])
70  module = importlib.import_module(full_module_path)
71  if not hasattr(module, LIST_OPTS_FUNC_NAME):
72  raise Exception(
73  "The module '%s' should have a '%s' function which "
74  "returns the config options." % (
75  full_module_path,
76  LIST_OPTS_FUNC_NAME))
77  else:
78  imported_modules.append(module)
79  return imported_modules
80 
81 
82 def _append_config_options(imported_modules, config_options):
83  for module in imported_modules:
84  configs = module.list_opts()
85  for key, val in configs.items():
86  config_options[key].extend(val)
keystone.conf.opts.list_opts
def list_opts()
Definition: opts.py:41
keystone.conf.opts._append_config_options
def _append_config_options(imported_modules, config_options)
Definition: opts.py:82
keystone.conf.opts._list_module_names
def _list_module_names()
Definition: opts.py:54
keystone.conf.opts._tupleize
def _tupleize(d)
Definition: opts.py:49
keystone.conf.opts._import_modules
def _import_modules(module_names)
Definition: opts.py:66