create new method to encapsulate configinstall run of one host
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
parent
3883fe4247
commit
72687b5aeb
1 changed files with 24 additions and 15 deletions
43
bin/cdist
43
bin/cdist
|
@ -22,6 +22,7 @@
|
|||
|
||||
import argparse
|
||||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
@ -116,9 +117,32 @@ def configinstall(args, mode):
|
|||
|
||||
time_start = time.time()
|
||||
|
||||
for host in args.host:
|
||||
if args.parallel:
|
||||
log.debug("Creating child process for %s", host)
|
||||
process[host] = multiprocessing.Process(target=configinstall_onehost, args=(host, args, mode))
|
||||
process[host].start()
|
||||
else:
|
||||
configinstall_onehost(host, args, mode)
|
||||
|
||||
# FIXME: error handling for parallel mode!
|
||||
if args.parallel:
|
||||
for p in process.keys():
|
||||
log.debug("Joining process %s", p)
|
||||
process[p].join()
|
||||
|
||||
|
||||
time_end = time.time()
|
||||
log.info("Total processing time for %s host(s): %s", len(args.host),
|
||||
(time_end - time_start))
|
||||
|
||||
|
||||
def configinstall_onehost(host, args, mode):
|
||||
"""Configure or install remote system"""
|
||||
process = {}
|
||||
|
||||
import cdist.context
|
||||
|
||||
for host in args.host:
|
||||
context = cdist.context.Context(
|
||||
target_host=host,
|
||||
initial_manifest=args.manifest,
|
||||
|
@ -127,25 +151,9 @@ def configinstall(args, mode):
|
|||
debug=args.debug)
|
||||
|
||||
c = mode(context)
|
||||
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()
|
||||
|
||||
context.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 = time.time()
|
||||
log.info("Total processing time for %s host(s): %s", len(args.host),
|
||||
(time_end - time_start))
|
||||
|
||||
def emulator():
|
||||
"""Prepare and run emulator"""
|
||||
|
@ -168,6 +176,7 @@ if __name__ == "__main__":
|
|||
commandline()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
# FIXME: catch children if in parallel mode
|
||||
sys.exit(0)
|
||||
except cdist.Error as e:
|
||||
log.error(e)
|
||||
|
|
Loading…
Reference in a new issue