---
func/overlord/scripts.py | 10 +++++--
scripts/func-command | 58 +++++++++++++++++++++++++--------------------
scripts/func-down-hosts | 45 ++++++++++++++++++-----------------
3 files changed, 62 insertions(+), 51 deletions(-)
diff --git a/func/overlord/scripts.py b/func/overlord/scripts.py
index 57a6255..27ade78 100644
--- a/func/overlord/scripts.py
+++ b/func/overlord/scripts.py
@@ -9,7 +9,7 @@ from optparse import OptionParser
import sys
-def base_func_parser(opthosts=True, outputpath=True):
+def base_func_parser(opthosts=True, outputpath=True, forkdef=40,
timeoutdef=300):
parser = OptionParser()
if opthosts:
parser.add_option('--host', default=[], action='append',
@@ -17,9 +17,9 @@ def base_func_parser(opthosts=True, outputpath=True):
parser.add_option('--hosts-from-file', default=None, dest="hostfile",
help="read list of hosts from this file, if '-' read from
stdin")
- parser.add_option('--timeout', default=300, type='int',
+ parser.add_option('--timeout', default=timeoutdef, type='int',
help='set the wait timeout for func commands')
- parser.add_option('--forks', default=40, type='int',
+ parser.add_option('--forks', default=forkdef, type='int',
help='set the number of forks to start up')
if outputpath:
parser.add_option('--outputpath', default='/var/lib/func/data/',
dest="outputpath",
@@ -43,3 +43,7 @@ def handle_base_func_options(parser, opts):
return opts
+def errorprint(msg)
+ print >> sys.stderr, msg
+
+
diff --git a/scripts/func-command b/scripts/func-command
index e6b88f9..5e0f43d 100755
--- a/scripts/func-command
+++ b/scripts/func-command
@@ -5,39 +5,45 @@
import sys
import func.overlord.client
-from func.overlord.scripts import base_func_parser, handle_base_func_options
+from func.overlord.scripts import base_func_parser, handle_base_func_options,
errorprint
from func.utils import is_error
-parser = base_func_parser(outputpath=False)
-opts, args, parser = parse_args(sys.argv[1:])
-opts = handle_base_func_options(parser, opts)
-if len(args) < 1:
- print parser.format_help()
- sys.exit(1)
+def main(args):
+ parser = base_func_parser(outputpath=False)
+ opts, args, parser = parse_args(args)
+ opts = handle_base_func_options(parser, opts)
-mycmd = ' '.join(args)
+ if len(args) < 1:
+ errorprint(parser.format_help())
+ return 1
-hosts ='*'
-if opts.host:
- hosts = ';'.join(opts.host)
+ mycmd = ' '.join(args)
-fc = func.overlord.client.Client(hosts, timeout=opts.timeout,
nforks=opts.forks)
+ hosts ='*'
+ if opts.host:
+ hosts = ';'.join(opts.host)
-print mycmd
-results = fc.command.run(mycmd)
-for (hn, output) in results.items():
- if is_error(output):
- msg = 'Error: %s: ' % hn
- for item in output[1:3]:
- if type(item) == type(''):
- msg += ' %s' % item
- print >> sys.stderr, msg
- continue
+ fc = func.overlord.client.Client(hosts, timeout=opts.timeout,
nforks=opts.forks)
- # FIXME - maybe for commands don't do it one line with hostname first
+ print mycmd
+ results = fc.command.run(mycmd)
+ for (hn, output) in results.items():
+ if is_error(output):
+ msg = 'Error: %s: ' % hn
+ for item in output[1:3]:
+ if type(item) == type(''):
+ msg += ' %s' % item
+ errorprint(msg)
+ continue
- print '%s' % hn
- print output[1]
- print ''
+ # FIXME - maybe for commands don't do it one line with hostname first
+
+ print '%s' % hn
+ print output[1]
+ print ''
+
+ return 0
+if __name__ == "__main__":
+ sys.exit(main(sys.argv[1:]))
diff --git a/scripts/func-down-hosts b/scripts/func-down-hosts
index 5d556f0..8ee08a9 100755
--- a/scripts/func-down-hosts
+++ b/scripts/func-down-hosts
@@ -4,32 +4,33 @@
import sys
import func.overlord.client
-from optparse import OptionParser
+from func.overlord.scripts import base_func_parser, handle_base_func_options,
errorprint
+from func.utils import is_error
-def parse_args(args):
- parser = OptionParser(version = "1.0")
- parser.add_option('--host', default=[], action='append',
- help="hosts to act on, defaults to ALL")
- parser.add_option('--timeout', default=10, type='int',
- help='set the wait timeout for func commands')
- parser.add_option('--forks', default=40, type='int',
- help='set the number of forks to start up')
- (opts, args) = parser.parse_args(args)
- return opts, args, parser
+def main(args):
+ parser = base_func_parser(outputpath=False, timeoutdef=10)
+ opts, args, parser = parse_args(args)
+ opts = handle_base_func_options(parser, opts)
-opts, args, parser = parse_args(sys.argv[1:])
-hosts ='*'
-if opts.host:
- hosts = ';'.join(opts.host)
+ hosts ='*'
+ if opts.host:
+ hosts = ';'.join(opts.host)
-fc = func.overlord.client.Client(hosts, timeout=opts.timeout,
nforks=opts.forks)
+ fc = func.overlord.client.Client(hosts, timeout=opts.timeout,
nforks=opts.forks)
+
+ results = fc.test.ping()
+ offline = []
+ for (hn, out) in results.items():
+ if out != 1:
+ offline.append(hn)
+
+ print '\n'.join(sorted(offline))
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv[1:]))
-results = fc.test.ping()
-offline = []
-for (hn, out) in results.items():
- if out != 1:
- offline.append(hn)
-print '\n'.join(sorted(offline))
--
1.7.2.1
_______________________________________________
Func-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/func-list