forked from ungleich-public/cdist
prevent tracebacks in tempfile code/initial manifest from stdin
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
parent
58a88ca5bd
commit
5001e9cbe7
2 changed files with 18 additions and 13 deletions
29
bin/cdist
29
bin/cdist
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2010-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -91,13 +91,13 @@ def commandline():
|
||||||
logging.root.setLevel(logging.DEBUG)
|
logging.root.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
log.debug(args)
|
log.debug(args)
|
||||||
return args.func(args)
|
args.func(args)
|
||||||
|
|
||||||
def config(args):
|
def config(args):
|
||||||
return configinstall(args, mode=cdist.config.Config)
|
configinstall(args, mode=cdist.config.Config)
|
||||||
|
|
||||||
def install(args):
|
def install(args):
|
||||||
return configinstall(args, mode=cdist.install.Install)
|
configinstall(args, mode=cdist.install.Install)
|
||||||
|
|
||||||
def configinstall(args, mode):
|
def configinstall(args, mode):
|
||||||
"""Configure or install remote system"""
|
"""Configure or install remote system"""
|
||||||
|
@ -108,9 +108,13 @@ def configinstall(args, mode):
|
||||||
if args.manifest == '-':
|
if args.manifest == '-':
|
||||||
# read initial manifest from stdin
|
# read initial manifest from stdin
|
||||||
import tempfile
|
import tempfile
|
||||||
handle, initial_manifest_temp_path = tempfile.mkstemp(prefix='cdist.stdin.')
|
try:
|
||||||
with os.fdopen(handle, 'w') as fd:
|
handle, initial_manifest_temp_path = tempfile.mkstemp(prefix='cdist.stdin.')
|
||||||
fd.write(sys.stdin.read())
|
with os.fdopen(handle, 'w') as fd:
|
||||||
|
fd.write(sys.stdin.read())
|
||||||
|
except (IOError, OSError) as e:
|
||||||
|
raise cdist.Error("Creating tempfile for stdin data failed: %s" % e)
|
||||||
|
|
||||||
args.manifest = initial_manifest_temp_path
|
args.manifest = initial_manifest_temp_path
|
||||||
import atexit
|
import atexit
|
||||||
atexit.register(lambda: os.remove(initial_manifest_temp_path))
|
atexit.register(lambda: os.remove(initial_manifest_temp_path))
|
||||||
|
@ -139,12 +143,15 @@ def configinstall(args, mode):
|
||||||
if len(failed_hosts) > 0:
|
if len(failed_hosts) > 0:
|
||||||
log.warn("Failed to deploy to the following hosts: " +
|
log.warn("Failed to deploy to the following hosts: " +
|
||||||
" ".join(failed_hosts))
|
" ".join(failed_hosts))
|
||||||
exit_code = 1
|
|
||||||
|
|
||||||
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))
|
||||||
|
|
||||||
|
if len(failed_hosts) > 0:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
def configinstall_onehost(host, args, mode, parallel):
|
def configinstall_onehost(host, args, mode, parallel):
|
||||||
"""Configure or install ONE remote system"""
|
"""Configure or install ONE remote system"""
|
||||||
|
@ -212,9 +219,9 @@ if __name__ == "__main__":
|
||||||
logging.basicConfig(format='%(levelname)s: %(message)s')
|
logging.basicConfig(format='%(levelname)s: %(message)s')
|
||||||
|
|
||||||
if re.match("__", os.path.basename(sys.argv[0])):
|
if re.match("__", os.path.basename(sys.argv[0])):
|
||||||
run = emulator()
|
emulator()
|
||||||
else:
|
else:
|
||||||
run = commandline()
|
commandline()
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
@ -224,7 +231,5 @@ if __name__ == "__main__":
|
||||||
exit_code = 1
|
exit_code = 1
|
||||||
|
|
||||||
# Determine exit code by return value of function
|
# Determine exit code by return value of function
|
||||||
if not run:
|
|
||||||
exit_code = 1
|
|
||||||
|
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue