create new method to encapsulate configinstall run of one host

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-10-16 00:12:51 +02:00
parent 3883fe4247
commit 72687b5aeb

View file

@ -22,6 +22,7 @@
import argparse import argparse
import logging import logging
import multiprocessing
import os import os
import re import re
import sys import sys
@ -116,37 +117,44 @@ def configinstall(args, mode):
time_start = time.time() time_start = time.time()
import cdist.context
for host in args.host: for host in args.host:
context = cdist.context.Context(
target_host=host,
initial_manifest=args.manifest,
base_path=args.cdist_home,
exec_path=sys.argv[0],
debug=args.debug)
c = mode(context)
if args.parallel: if args.parallel:
log.debug("Creating child process for %s", host) log.debug("Creating child process for %s", host)
process[host] = multiprocessing.Process(target=c.deploy_and_cleanup) process[host] = multiprocessing.Process(target=configinstall_onehost, args=(host, args, mode))
process[host].start() process[host].start()
else: else:
c.deploy_and_cleanup() configinstall_onehost(host, args, mode)
context.cleanup()
# FIXME: error handling for parallel mode!
if args.parallel: if args.parallel:
for p in process.keys(): for p in process.keys():
log.debug("Joining process %s", p) log.debug("Joining process %s", p)
process[p].join() process[p].join()
# FIXME: error handling for parallel mode!
time_end = time.time() time_end = time.time()
log.info("Total processing time for %s host(s): %s", len(args.host), log.info("Total processing time for %s host(s): %s", len(args.host),
(time_end - time_start)) (time_end - time_start))
def configinstall_onehost(host, args, mode):
"""Configure or install remote system"""
process = {}
import cdist.context
context = cdist.context.Context(
target_host=host,
initial_manifest=args.manifest,
base_path=args.cdist_home,
exec_path=sys.argv[0],
debug=args.debug)
c = mode(context)
c.deploy_and_cleanup()
context.cleanup()
def emulator(): def emulator():
"""Prepare and run emulator""" """Prepare and run emulator"""
emulator = cdist.emulator.Emulator(sys.argv) emulator = cdist.emulator.Emulator(sys.argv)
@ -168,6 +176,7 @@ if __name__ == "__main__":
commandline() commandline()
except KeyboardInterrupt: except KeyboardInterrupt:
# FIXME: catch children if in parallel mode
sys.exit(0) sys.exit(0)
except cdist.Error as e: except cdist.Error as e:
log.error(e) log.error(e)