++logs and migrate context -> local
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
parent
58bd230a61
commit
f79727559a
5 changed files with 55 additions and 54 deletions
|
@ -28,26 +28,30 @@ import time
|
||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
import cdist
|
import cdist
|
||||||
import cdist.context
|
|
||||||
|
import cdist.exec.local
|
||||||
|
import cdist.exec.remote
|
||||||
|
|
||||||
from cdist import core
|
from cdist import core
|
||||||
|
|
||||||
class ConfigInstall(object):
|
class ConfigInstall(object):
|
||||||
"""Cdist main class to hold arbitrary data"""
|
"""Cdist main class to hold arbitrary data"""
|
||||||
|
|
||||||
def __init__(self, context, dry_run=False):
|
def __init__(self, local, remote, dry_run=False):
|
||||||
|
|
||||||
self.context = context
|
self.local = local
|
||||||
|
self.remote = remote
|
||||||
self.log = logging.getLogger(self.context.target_host)
|
self.log = logging.getLogger(self.context.target_host)
|
||||||
self.dry_run = dry_run
|
self.dry_run = dry_run
|
||||||
|
|
||||||
self.explorer = core.Explorer(self.context.target_host, self.context.local, self.context.remote)
|
self.explorer = core.Explorer(self.target_host, self.local, self.remote)
|
||||||
self.manifest = core.Manifest(self.context.target_host, self.context.local)
|
self.manifest = core.Manifest(self.target_host, self.local)
|
||||||
self.code = core.Code(self.context.target_host, self.context.local, self.context.remote)
|
self.code = core.Code(self.target_host, self.local, self.remote)
|
||||||
|
|
||||||
def _init_files_dirs(self):
|
def _init_files_dirs(self):
|
||||||
"""Prepare files and directories for the run"""
|
"""Prepare files and directories for the run"""
|
||||||
self.context.local.create_files_dirs()
|
self.local.create_files_dirs()
|
||||||
self.context.remote.create_files_dirs()
|
self.remote.create_files_dirs()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def commandline(cls, args):
|
def commandline(cls, args):
|
||||||
|
@ -110,16 +114,23 @@ class ConfigInstall(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
context = cdist.context.Context(
|
local = cdist.local.Local(
|
||||||
target_host=host,
|
target_host=host,
|
||||||
remote_copy=args.remote_copy,
|
out_path=FIXME-OUT_PATH,
|
||||||
remote_exec=args.remote_exec,
|
|
||||||
initial_manifest=args.manifest,
|
|
||||||
add_conf_dirs=args.conf_dir,
|
|
||||||
exec_path=sys.argv[0],
|
exec_path=sys.argv[0],
|
||||||
debug=args.debug)
|
add_conf_dirs=args.conf_dir,
|
||||||
|
cache_dir=args.cache_dir)
|
||||||
|
|
||||||
c = cls(context)
|
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()
|
c.run()
|
||||||
context.cleanup()
|
context.cleanup()
|
||||||
|
|
||||||
|
@ -149,7 +160,7 @@ class ConfigInstall(object):
|
||||||
self.manifest.run_initial_manifest(self.context.initial_manifest)
|
self.manifest.run_initial_manifest(self.context.initial_manifest)
|
||||||
self.iterate_until_finished()
|
self.iterate_until_finished()
|
||||||
|
|
||||||
self.context.local.save_cache()
|
self.local.save_cache()
|
||||||
self.log.info("Finished successful run in %s seconds", time.time() - start_time)
|
self.log.info("Finished successful run in %s seconds", time.time() - start_time)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,6 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
from cdist.exec import local
|
|
||||||
from cdist.exec import remote
|
|
||||||
|
|
||||||
|
|
||||||
class Context(object):
|
class Context(object):
|
||||||
"""Hold information about current context"""
|
"""Hold information about current context"""
|
||||||
|
@ -52,19 +46,6 @@ class Context(object):
|
||||||
self.log = logging.getLogger(self.target_host)
|
self.log = logging.getLogger(self.target_host)
|
||||||
self.log.addFilter(self)
|
self.log.addFilter(self)
|
||||||
|
|
||||||
# Local temp directory
|
|
||||||
# FIXME: if __cdist_out_dir can be given from the outside, the same directory will be used for all hosts
|
|
||||||
if '__cdist_out_dir' in os.environ:
|
|
||||||
self.out_path = os.environ['__cdist_out_dir']
|
|
||||||
self.temp_dir = None
|
|
||||||
else:
|
|
||||||
self.temp_dir = tempfile.mkdtemp()
|
|
||||||
self.out_path = os.path.join(self.temp_dir, "out")
|
|
||||||
|
|
||||||
self.local = local.Local(self.target_host, self.out_path,
|
|
||||||
self.exec_path, add_conf_dirs=add_conf_dirs,
|
|
||||||
cache_dir=self.cache_dir)
|
|
||||||
|
|
||||||
self.initial_manifest = (initial_manifest or
|
self.initial_manifest = (initial_manifest or
|
||||||
os.path.join(self.local.manifest_path, "init"))
|
os.path.join(self.local.manifest_path, "init"))
|
||||||
|
|
||||||
|
@ -83,11 +64,6 @@ class Context(object):
|
||||||
self.remote = remote.Remote(self.target_host, self.remote_base_path,
|
self.remote = remote.Remote(self.target_host, self.remote_base_path,
|
||||||
self.remote_exec, self.remote_copy)
|
self.remote_exec, self.remote_copy)
|
||||||
|
|
||||||
def cleanup(self):
|
|
||||||
"""Remove temp stuff"""
|
|
||||||
if self.temp_dir:
|
|
||||||
shutil.rmtree(self.temp_dir)
|
|
||||||
|
|
||||||
def filter(self, record):
|
def filter(self, record):
|
||||||
"""Add hostname to logs via logging Filter"""
|
"""Add hostname to logs via logging Filter"""
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,10 @@ 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, out_path, exec_path, add_conf_dirs=None, cache_dir=None):
|
def __init__(self, target_host, exec_path, out_base_path=None, add_conf_dirs=None, cache_dir=None):
|
||||||
|
|
||||||
self.target_host = target_host
|
self.target_host = target_host
|
||||||
self.out_path = out_path
|
self.out_base_path = out_base_path
|
||||||
self.exec_path = exec_path
|
self.exec_path = exec_path
|
||||||
|
|
||||||
self._add_conf_dirs = add_conf_dirs
|
self._add_conf_dirs = add_conf_dirs
|
||||||
|
@ -71,11 +71,17 @@ class Local(object):
|
||||||
os.umask(0o077)
|
os.umask(0o077)
|
||||||
|
|
||||||
def _init_paths(self):
|
def _init_paths(self):
|
||||||
|
|
||||||
|
# FIXME: inherited behaviour from old context
|
||||||
|
if not self.out_base_path:
|
||||||
|
self.out_base_path = tempfile.mkdtemp()
|
||||||
|
|
||||||
|
|
||||||
# Depending on out_path
|
# Depending on out_path
|
||||||
self.bin_path = os.path.join(self.out_path, "bin")
|
self.bin_path = os.path.join(self.out_base_path, "bin")
|
||||||
self.conf_path = os.path.join(self.out_path, "conf")
|
self.conf_path = os.path.join(self.out_base_path, "conf")
|
||||||
self.global_explorer_out_path = os.path.join(self.out_path, "explorer")
|
self.global_explorer_out_path = os.path.join(self.out_base_path, "explorer")
|
||||||
self.object_path = os.path.join(self.out_path, "object")
|
self.object_path = os.path.join(self.out_base_path, "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")
|
||||||
|
@ -160,15 +166,13 @@ class Local(object):
|
||||||
|
|
||||||
def save_cache(self):
|
def save_cache(self):
|
||||||
destination = os.path.join(self.cache_path, self.target_host)
|
destination = os.path.join(self.cache_path, self.target_host)
|
||||||
self.log.debug("Saving " + self.out_path + " to " + destination)
|
self.log.debug("Saving " + self.out_base_path + " to " + destination)
|
||||||
if os.path.exists(destination):
|
if os.path.exists(destination):
|
||||||
shutil.rmtree(destination)
|
shutil.rmtree(destination)
|
||||||
shutil.move(self.out_path, destination)
|
shutil.move(self.out_base_path, destination)
|
||||||
|
|
||||||
|
|
||||||
def _create_context_dirs(self):
|
def _create_context_dirs(self):
|
||||||
self.mkdir(self.out_path)
|
|
||||||
|
|
||||||
self.mkdir(self.conf_path)
|
self.mkdir(self.conf_path)
|
||||||
self.mkdir(self.global_explorer_out_path)
|
self.mkdir(self.global_explorer_out_path)
|
||||||
self.mkdir(self.bin_path)
|
self.mkdir(self.bin_path)
|
||||||
|
|
|
@ -43,9 +43,9 @@ class Remote(object):
|
||||||
Directly accessing the remote side from python code is a bug.
|
Directly accessing the remote side from python code is a bug.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, target_host, remote_base_path, remote_exec, remote_copy):
|
def __init__(self, target_host, remote_exec, remote_copy):
|
||||||
self.target_host = target_host
|
self.target_host = target_host
|
||||||
self.base_path = remote_base_path
|
self.base_path = os.environ.get('__cdist_remote_out_dir', "/var/lib/cdist")
|
||||||
self._exec = remote_exec
|
self._exec = remote_exec
|
||||||
self._copy = remote_copy
|
self._copy = remote_copy
|
||||||
|
|
||||||
|
|
|
@ -5,3 +5,13 @@
|
||||||
- also add support for a per-host pidfile
|
- also add support for a per-host pidfile
|
||||||
- allow user to specify cache dir - to give
|
- allow user to specify cache dir - to give
|
||||||
full flexibility
|
full flexibility
|
||||||
|
- drop context - it is a very small unecessary wrapper
|
||||||
|
- maye introduce cdist.log instead!
|
||||||
|
- replace out_path with out_base
|
||||||
|
- directory under which all the subdirectories are
|
||||||
|
created
|
||||||
|
-> by default ~/.cdist/run
|
||||||
|
-> out_base_path
|
||||||
|
- drop support for deprecated environment variables
|
||||||
|
__cdist_out_dir
|
||||||
|
__cdist_remote_out_dir
|
||||||
|
|
Loading…
Reference in a new issue