begin to migrate to '--output-base-path', shrink context

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
Nico Schottelius 2013-08-19 00:52:15 +02:00
parent b9a6cf7c6a
commit eaf1721212
4 changed files with 22 additions and 28 deletions

View File

@ -41,7 +41,7 @@ class ConfigInstall(object):
self.local = local self.local = local
self.remote = remote 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.dry_run = dry_run
self.explorer = core.Explorer(self.target_host, self.local, self.remote) self.explorer = core.Explorer(self.target_host, self.local, self.remote)
@ -113,26 +113,20 @@ class ConfigInstall(object):
"""Configure or install ONE system""" """Configure or install ONE system"""
try: try:
local = cdist.local.Local( local = cdist.local.Local(
target_host=host, target_host=host,
out_path=FIXME-OUT_PATH,
exec_path=sys.argv[0], exec_path=sys.argv[0],
add_conf_dirs=args.conf_dir, initial_manifest=args.manifest,
cache_dir=args.cache_dir) out_base_path=args.out_base_path,
add_conf_dirs=args.conf_dir)
remote = cdist.remote.Remote( remote = cdist.remote.Remote(
target_host=host, target_host=host,
remote_exec=args.remote_exec, remote_exec=args.remote_exec,
remote_copy=args.remote_copy) remote_copy=args.remote_copy)
#initial_manifest=args.manifest,
#debug=args.debug)
c = cls(local, remote) c = cls(local, remote)
c.run() c.run()
context.cleanup()
except cdist.Error as e: except cdist.Error as e:
context.log.error(e) context.log.error(e)
@ -156,8 +150,8 @@ class ConfigInstall(object):
self._init_files_dirs() self._init_files_dirs()
self.explorer.run_global_explorers(self.context.local.global_explorer_out_path) self.explorer.run_global_explorers(self.local.global_explorer_out_path)
self.manifest.run_initial_manifest(self.context.initial_manifest) self.manifest.run_initial_manifest(self.local.initial_manifest)
self.iterate_until_finished() self.iterate_until_finished()
self.local.save_cache() self.local.save_cache()
@ -166,8 +160,8 @@ class ConfigInstall(object):
def object_list(self): def object_list(self):
"""Short name for object list retrieval""" """Short name for object list retrieval"""
for cdist_object in core.CdistObject.list_objects(self.context.local.object_path, for cdist_object in core.CdistObject.list_objects(self.local.object_path,
self.context.local.type_path): self.local.type_path):
yield cdist_object yield cdist_object
def iterate_once(self): def iterate_once(self):

View File

@ -27,22 +27,12 @@ import sys
class Context(object): class Context(object):
"""Hold information about current context""" """Hold information about current context"""
def __init__(self, def __init__(self, target_host)
target_host,
remote_copy,
remote_exec,
initial_manifest=False,
add_conf_dirs=None,
exec_path=sys.argv[0],
debug=False,
cache_dir=None):
# Context logging # Context logging
self.log = logging.getLogger(self.target_host) self.log = logging.getLogger(self.target_host)
self.log.addFilter(self) self.log.addFilter(self)
self.initial_manifest = (initial_manifest or
os.path.join(self.local.manifest_path, "init"))
def filter(self, record): def filter(self, record):
"""Add hostname to logs via logging Filter""" """Add hostname to logs via logging Filter"""

View File

@ -38,11 +38,17 @@ class Local(object):
Directly accessing the local side from python code is a bug. 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.target_host = target_host
self.out_base_path = out_base_path self.out_base_path = out_base_path
self.exec_path = exec_path self.exec_path = exec_path
self.custom_initial_manifest = initial_manifest
self._add_conf_dirs = add_conf_dirs self._add_conf_dirs = add_conf_dirs
@ -52,6 +58,7 @@ class Local(object):
self._init_cache_dir(cache_dir) self._init_cache_dir(cache_dir)
self._init_conf_dirs() self._init_conf_dirs()
@property @property
def dist_conf_dir(self): def dist_conf_dir(self):
return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf")) return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf"))
@ -86,6 +93,9 @@ class Local(object):
# Depending on conf_path # Depending on conf_path
self.global_explorer_path = os.path.join(self.conf_path, "explorer") self.global_explorer_path = os.path.join(self.conf_path, "explorer")
self.manifest_path = os.path.join(self.conf_path, "manifest") 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") self.type_path = os.path.join(self.conf_path, "type")
def _init_conf_dirs(self): def _init_conf_dirs(self):

View File

@ -60,13 +60,13 @@ def commandline():
parser['configinstall'].add_argument('-c', '--conf-dir', parser['configinstall'].add_argument('-c', '--conf-dir',
help='Add configuration directory (can be repeated, last one wins)', help='Add configuration directory (can be repeated, last one wins)',
action='append') 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', parser['configinstall'].add_argument('-i', '--initial-manifest',
help='Path to a cdist manifest or \'-\' to read from stdin.', help='Path to a cdist manifest or \'-\' to read from stdin.',
dest='manifest', required=False) dest='manifest', required=False)
parser['configinstall'].add_argument('-n', '--dry-run', parser['configinstall'].add_argument('-n', '--dry-run',
help='Do not execute code', action='store_true') 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', parser['configinstall'].add_argument('-p', '--parallel',
help='Operate on multiple hosts in parallel', help='Operate on multiple hosts in parallel',
action='store_true', dest='parallel') action='store_true', dest='parallel')