forked from ungleich-public/cdist
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 argparse
|
||||||
import logging
|
import logging
|
||||||
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
@ -116,9 +117,32 @@ def configinstall(args, mode):
|
||||||
|
|
||||||
time_start = time.time()
|
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
|
import cdist.context
|
||||||
|
|
||||||
for host in args.host:
|
|
||||||
context = cdist.context.Context(
|
context = cdist.context.Context(
|
||||||
target_host=host,
|
target_host=host,
|
||||||
initial_manifest=args.manifest,
|
initial_manifest=args.manifest,
|
||||||
|
@ -127,25 +151,9 @@ def configinstall(args, mode):
|
||||||
debug=args.debug)
|
debug=args.debug)
|
||||||
|
|
||||||
c = mode(context)
|
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()
|
c.deploy_and_cleanup()
|
||||||
|
|
||||||
context.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():
|
def emulator():
|
||||||
"""Prepare and run emulator"""
|
"""Prepare and run emulator"""
|
||||||
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue