forked from ungleich-public/cdist
Fix missing configuration file usage, support -g
PreOS code did not use configuration support. This fix adds support for using cdist configuration, which takes into account cdist configuration file, environment variables and command line options, especially conf_dir. It also adds support for -g, --config-file option, for specifying custom configuration file.
This commit is contained in:
parent
51ba4a49d8
commit
11f569959d
3 changed files with 18 additions and 14 deletions
|
|
@ -5,8 +5,9 @@ import inspect
|
|||
import argparse
|
||||
import cdist
|
||||
import logging
|
||||
import re
|
||||
import cdist.argparse
|
||||
import cdist.configuration
|
||||
import cdist.exec.util as util
|
||||
|
||||
|
||||
_PREOS_CALL = "commandline"
|
||||
|
|
@ -24,16 +25,6 @@ def extend_plugins_path(dirs):
|
|||
_PLUGINS_PATH.append(preos_dir)
|
||||
|
||||
|
||||
cdist_home = cdist.home_dir()
|
||||
if cdist_home:
|
||||
extend_plugins_path((cdist_home, ))
|
||||
x = 'CDIST_PATH'
|
||||
if x in os.environ:
|
||||
vals = re.split(r'(?<!\\):', os.environ[x])
|
||||
vals = [x for x in vals if x]
|
||||
extend_plugins_path(vals)
|
||||
|
||||
|
||||
def preos_plugin(obj):
|
||||
"""It is preos if _PREOS_MARKER is True and has _PREOS_CALL."""
|
||||
if hasattr(obj, _PREOS_MARKER):
|
||||
|
|
@ -102,6 +93,9 @@ class PreOS(object):
|
|||
help=('Add configuration directory (one that '
|
||||
'contains "preos" subdirectory)'),
|
||||
action='append')
|
||||
parser.add_argument('-g', '--config-file',
|
||||
help='Use specified custom configuration file.',
|
||||
dest="config_file", required=False)
|
||||
parser.add_argument('-L', '--list-preoses',
|
||||
help='List available PreOS-es',
|
||||
action='store_true', default=False)
|
||||
|
|
@ -110,8 +104,12 @@ class PreOS(object):
|
|||
cdist.argparse.handle_loglevel(args)
|
||||
log.debug("preos args : {}".format(args))
|
||||
|
||||
if args.conf_dir:
|
||||
extend_plugins_path(args.conf_dir)
|
||||
cfg = cdist.configuration.Configuration(args)
|
||||
configuration = cfg.get_config(section='GLOBAL')
|
||||
conf_dirs = util.resolve_conf_dirs(configuration,
|
||||
args.conf_dir)
|
||||
|
||||
extend_plugins_path(conf_dirs)
|
||||
sys.path.extend(_PLUGINS_PATH)
|
||||
cls.preoses = find_preoses()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue