From eaf1721212ba779449b8e5f85c2cab00f7263761 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 19 Aug 2013 00:52:15 +0200 Subject: [PATCH] begin to migrate to '--output-base-path', shrink context Signed-off-by: Nico Schottelius --- cdist/config_install.py | 22 ++++++++-------------- cdist/context.py | 12 +----------- cdist/exec/local.py | 12 +++++++++++- scripts/cdist | 4 ++-- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/cdist/config_install.py b/cdist/config_install.py index 70f15c74..7b38ae97 100644 --- a/cdist/config_install.py +++ b/cdist/config_install.py @@ -41,7 +41,7 @@ class ConfigInstall(object): self.local = local self.remote = remote - self.log = logging.getLogger(self.context.target_host) + self.log = logging.getLogger(self.local.target_host) self.dry_run = dry_run self.explorer = core.Explorer(self.target_host, self.local, self.remote) @@ -113,26 +113,20 @@ class ConfigInstall(object): """Configure or install ONE system""" try: - local = cdist.local.Local( target_host=host, - out_path=FIXME-OUT_PATH, exec_path=sys.argv[0], - add_conf_dirs=args.conf_dir, - cache_dir=args.cache_dir) + initial_manifest=args.manifest, + out_base_path=args.out_base_path, + add_conf_dirs=args.conf_dir) remote = cdist.remote.Remote( target_host=host, remote_exec=args.remote_exec, remote_copy=args.remote_copy) - - - #initial_manifest=args.manifest, - #debug=args.debug) c = cls(local, remote) c.run() - context.cleanup() except cdist.Error as e: context.log.error(e) @@ -156,8 +150,8 @@ class ConfigInstall(object): self._init_files_dirs() - self.explorer.run_global_explorers(self.context.local.global_explorer_out_path) - self.manifest.run_initial_manifest(self.context.initial_manifest) + self.explorer.run_global_explorers(self.local.global_explorer_out_path) + self.manifest.run_initial_manifest(self.local.initial_manifest) self.iterate_until_finished() self.local.save_cache() @@ -166,8 +160,8 @@ class ConfigInstall(object): def object_list(self): """Short name for object list retrieval""" - for cdist_object in core.CdistObject.list_objects(self.context.local.object_path, - self.context.local.type_path): + for cdist_object in core.CdistObject.list_objects(self.local.object_path, + self.local.type_path): yield cdist_object def iterate_once(self): diff --git a/cdist/context.py b/cdist/context.py index 9e20f969..0c11502e 100644 --- a/cdist/context.py +++ b/cdist/context.py @@ -27,22 +27,12 @@ import sys class Context(object): """Hold information about current context""" - def __init__(self, - target_host, - remote_copy, - remote_exec, - initial_manifest=False, - add_conf_dirs=None, - exec_path=sys.argv[0], - debug=False, - cache_dir=None): + def __init__(self, target_host) # Context logging self.log = logging.getLogger(self.target_host) self.log.addFilter(self) - self.initial_manifest = (initial_manifest or - os.path.join(self.local.manifest_path, "init")) def filter(self, record): """Add hostname to logs via logging Filter""" diff --git a/cdist/exec/local.py b/cdist/exec/local.py index 76c090cc..e74c8a4f 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -38,11 +38,17 @@ class Local(object): Directly accessing the local side from python code is a bug. """ - def __init__(self, target_host, exec_path, out_base_path=None, add_conf_dirs=None, cache_dir=None): + def __init__(self, + target_host, + exec_path, + initial_manifest=None, + out_base_path=None, + add_conf_dirs=None) self.target_host = target_host self.out_base_path = out_base_path self.exec_path = exec_path + self.custom_initial_manifest = initial_manifest self._add_conf_dirs = add_conf_dirs @@ -52,6 +58,7 @@ class Local(object): self._init_cache_dir(cache_dir) self._init_conf_dirs() + @property def dist_conf_dir(self): return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf")) @@ -86,6 +93,9 @@ class Local(object): # Depending on conf_path self.global_explorer_path = os.path.join(self.conf_path, "explorer") self.manifest_path = os.path.join(self.conf_path, "manifest") + self.initial_manifest = (self.custom_initial_manifest or + os.path.join(self.manifest_path, "init")) + self.type_path = os.path.join(self.conf_path, "type") def _init_conf_dirs(self): diff --git a/scripts/cdist b/scripts/cdist index 66735f4b..e9a5833e 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -60,13 +60,13 @@ def commandline(): parser['configinstall'].add_argument('-c', '--conf-dir', help='Add configuration directory (can be repeated, last one wins)', action='append') - parser['configinstall'].add_argument('-C', '--cache-dir', - help='Directory to save cache in (usually derived from target host name)') parser['configinstall'].add_argument('-i', '--initial-manifest', help='Path to a cdist manifest or \'-\' to read from stdin.', dest='manifest', required=False) parser['configinstall'].add_argument('-n', '--dry-run', help='Do not execute code', action='store_true') + parser['configinstall'].add_argument('-o', '--output-base-path', + help='Directory prefix to save cdist output in') parser['configinstall'].add_argument('-p', '--parallel', help='Operate on multiple hosts in parallel', action='store_true', dest='parallel')