Skip to content

Commit

Permalink
begin to migrate to '--output-base-path', shrink context
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
  • Loading branch information
Nico Schottelius committed Aug 18, 2013
1 parent b9a6cf7 commit eaf1721
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
22 changes: 8 additions & 14 deletions cdist/config_install.py
Expand Up @@ -41,7 +41,7 @@ def __init__(self, local, remote, dry_run=False):

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)
Expand Down Expand Up @@ -113,26 +113,20 @@ def onehost(cls, host, args, parallel):
"""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)
Expand All @@ -156,8 +150,8 @@ def run(self):

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()
Expand All @@ -166,8 +160,8 @@ def run(self):

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):
Expand Down
12 changes: 1 addition & 11 deletions cdist/context.py
Expand Up @@ -27,22 +27,12 @@
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"""
Expand Down
12 changes: 11 additions & 1 deletion cdist/exec/local.py
Expand Up @@ -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

Expand All @@ -52,6 +58,7 @@ def __init__(self, target_host, exec_path, out_base_path=None, add_conf_dirs=Non
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"))
Expand Down Expand Up @@ -86,6 +93,9 @@ def _init_paths(self):
# 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):
Expand Down
4 changes: 2 additions & 2 deletions scripts/cdist
Expand Up @@ -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')
Expand Down

0 comments on commit eaf1721

Please sign in to comment.