Merge branch 'master' into new-docs-format
This commit is contained in:
commit
54834e277d
4 changed files with 71 additions and 12 deletions
|
|
@ -26,6 +26,7 @@ import shutil
|
|||
import sys
|
||||
import time
|
||||
import pprint
|
||||
import itertools
|
||||
|
||||
import cdist
|
||||
|
||||
|
|
@ -53,6 +54,27 @@ class Config(object):
|
|||
self.local.create_files_dirs()
|
||||
self.remote.create_files_dirs()
|
||||
|
||||
@staticmethod
|
||||
def hosts(source):
|
||||
"""Yield hosts from source.
|
||||
Source can be a sequence or filename (stdin if \'-\').
|
||||
In case of filename each line represents one host.
|
||||
"""
|
||||
if isinstance(source, str):
|
||||
import fileinput
|
||||
try:
|
||||
for host in fileinput.input(files=(source)):
|
||||
# remove leading and trailing whitespace
|
||||
yield host.strip()
|
||||
except (IOError, OSError) as e:
|
||||
raise cdist.Error("Error reading hosts from \'{}\'".format(
|
||||
source))
|
||||
else:
|
||||
if source:
|
||||
for host in source:
|
||||
yield host
|
||||
|
||||
|
||||
@classmethod
|
||||
def commandline(cls, args):
|
||||
"""Configure remote system"""
|
||||
|
|
@ -60,6 +82,13 @@ class Config(object):
|
|||
|
||||
# FIXME: Refactor relict - remove later
|
||||
log = logging.getLogger("cdist")
|
||||
|
||||
if args.manifest == '-' and args.hostfile == '-':
|
||||
raise cdist.Error(("Cannot read both, manifest and host file, "
|
||||
"from stdin"))
|
||||
# if no host source is specified then read hosts from stdin
|
||||
if not (args.hostfile or args.host):
|
||||
args.hostfile = '-'
|
||||
|
||||
initial_manifest_tempfile = None
|
||||
if args.manifest == '-':
|
||||
|
|
@ -79,8 +108,11 @@ class Config(object):
|
|||
process = {}
|
||||
failed_hosts = []
|
||||
time_start = time.time()
|
||||
|
||||
for host in args.host:
|
||||
|
||||
hostcnt = 0
|
||||
for host in itertools.chain(cls.hosts(args.host),
|
||||
cls.hosts(args.hostfile)):
|
||||
hostcnt += 1
|
||||
if args.parallel:
|
||||
log.debug("Creating child process for %s", host)
|
||||
process[host] = multiprocessing.Process(target=cls.onehost, args=(host, args, True))
|
||||
|
|
@ -101,7 +133,7 @@ class Config(object):
|
|||
failed_hosts.append(host)
|
||||
|
||||
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", hostcnt,
|
||||
(time_end - time_start))
|
||||
|
||||
if len(failed_hosts) > 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue