From d21126189cc92957087da37b3f4c5d0b4b0ab367 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 18:04:13 +0200 Subject: [PATCH 1/3] indent/cleanup Signed-off-by: Nico Schottelius --- lib/cdist/config_install.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py index fcbc79fc..766cffa2 100644 --- a/lib/cdist/config_install.py +++ b/lib/cdist/config_install.py @@ -90,13 +90,13 @@ class ConfigInstall: # Submit debug flag to manifest, can be used by emulator and types if self.debug: - env['__debug'] = "yes" + env['__debug'] = "yes" # Required for recording source in emulator env['__cdist_manifest'] = manifest_path # Required to find types in emulator - env['__cdist_type_base_path'] = self.context.type_base_path + env['__cdist_type_base_path'] = self.context.type_base_path # Other environment stuff if extra_env: From 11a8379c75265e721452ab039b7adefb37939579 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 18:13:58 +0200 Subject: [PATCH 2/3] +comment Signed-off-by: Nico Schottelius --- lib/cdist/config_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py index 766cffa2..3e67f7c1 100644 --- a/lib/cdist/config_install.py +++ b/lib/cdist/config_install.py @@ -105,7 +105,7 @@ class ConfigInstall: cdist.exec.shell_run_or_debug_fail(manifest_path, [manifest_path], env=env) def object_run(self, cdist_object): - """Run gencode or code for an object""" + """Run gencode and code for an object""" log.debug("Running object %s", cdist_object) # Catch requirements, which re-call us From 71ed728b4adf68ab3460e309d012554af46216d5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 18:14:17 +0200 Subject: [PATCH 3/3] move parallel code to main binary, allow branching out on install and config Signed-off-by: Nico Schottelius --- bin/cdist | 40 ++++++++++++++++++++++++++++++++++++++-- lib/cdist/config.py | 27 --------------------------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/bin/cdist b/bin/cdist index 7d2c035b..1b8b4346 100755 --- a/bin/cdist +++ b/bin/cdist @@ -81,12 +81,12 @@ def commandline(): # Config parser['config'] = parser['sub'].add_parser('config', parents=[parser['loglevel'], parser['configinstall']]) - parser['config'].set_defaults(func=cdist.config.config) + parser['config'].set_defaults(func=config) # Install parser['install'] = parser['sub'].add_parser('install', parents=[parser['loglevel'], parser['configinstall']]) - parser['install'].set_defaults(func=cdist.install.install) + parser['install'].set_defaults(func=install) for p in parser: parser[p].epilog = "Get cdist at http://www.nico.schottelius.org/software/cdist/" @@ -102,6 +102,42 @@ def commandline(): log.debug(args) args.func(args) +def config(args): + configinstall(args, mode=cdist.config.Config) + +def install(args): + configinstall(args, mode=cdist.install.Install) + +def configinstall(args, mode): + """Configure or install remote system""" + process = {} + + time_start = datetime.datetime.now() + + os.environ['__remote_exec'] = "ssh -o User=root -q" + os.environ['__remote_copy'] = "scp -o User=root -q" + + for host in args.host: + c = mode(host, initial_manifest=args.manifest, base_path=args.cdist_home, debug=args.debug) + if args.parallel: + log.debug("Creating child process for %s", host) + process[host] = multiprocessing.Process(target=c.deploy_and_cleanup) + process[host].start() + else: + c.deploy_and_cleanup() + + if args.parallel: + for p in process.keys(): + log.debug("Joining process %s", p) + process[p].join() + + # FIXME: error handling for parallel mode! + + time_end = datetime.datetime.now() + log.info("Total processing time for %s host(s): %s", len(args.host), + (time_end - time_start).total_seconds()) + + if __name__ == "__main__": try: logging.basicConfig(format='%(levelname)s: %(message)s') diff --git a/lib/cdist/config.py b/lib/cdist/config.py index 71ce14ed..782c88a1 100644 --- a/lib/cdist/config.py +++ b/lib/cdist/config.py @@ -31,30 +31,3 @@ log = logging.getLogger(__name__) class Config(cdist.config_install.ConfigInstall): pass - -def config(args): - """Configure remote system""" - process = {} - - time_start = datetime.datetime.now() - - os.environ['__remote_exec'] = "ssh -o User=root -q" - os.environ['__remote_copy'] = "scp -o User=root -q" - - for host in args.host: - c = Config(host, initial_manifest=args.manifest, base_path=args.cdist_home, debug=args.debug) - if args.parallel: - log.debug("Creating child process for %s", host) - process[host] = multiprocessing.Process(target=c.deploy_and_cleanup) - process[host].start() - else: - c.deploy_and_cleanup() - - if args.parallel: - for p in process.keys(): - log.debug("Joining process %s", p) - process[p].join() - - time_end = datetime.datetime.now() - log.info("Total processing time for %s host(s): %s", len(args.host), - (time_end - time_start).total_seconds())