| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # coding: utf-8 | 2 # coding: utf-8 |
| 3 | 3 |
| 4 import argparse | 4 import argparse |
| 5 import sys | 5 import sys |
| 6 import os | 6 import os |
| 7 import re | 7 import re |
| 8 import subprocess | 8 import subprocess |
| 9 import yaml | 9 import yaml |
| 10 | 10 |
| 11 def createArgumentParser(**kwargs): | 11 def createArgumentParser(**kwargs): |
| 12 parser = argparse.ArgumentParser(**kwargs) | 12 parser = argparse.ArgumentParser(**kwargs) |
| 13 parser.add_argument( | 13 parser.add_argument( |
| 14 '-u', '--user', metavar='<user>', dest='user', type=str, default='vagrant', | 14 '-u', '--user', metavar='user', dest='user', type=str, default='vagrant', |
|
Wladimir Palant
2015/04/07 15:50:25
Please remove < and > from metavar here as well.
mathias
2015/04/07 15:56:22
Done.
| |
| 15 help='user name for use with SSH, must exist on all hosts' | 15 help='user name for use with SSH, must exist on all hosts' |
| 16 ) | 16 ) |
| 17 | 17 |
| 18 return parser | 18 return parser |
| 19 | 19 |
| 20 def parseOptions(args): | 20 def parseOptions(args): |
| 21 description = 'Run a command on the given hosts or groups of hosts' | 21 description = 'Run a command on the given hosts or groups of hosts' |
| 22 parser = createArgumentParser(description=description) | 22 parser = createArgumentParser(description=description) |
| 23 parser.add_argument( | 23 parser.add_argument( |
| 24 '-i', '--ignore-errors', action='store_true', dest='ignore_errors', | 24 '-i', '--ignore-errors', action='store_true', dest='ignore_errors', |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 87 |
| 88 if __name__ == '__main__': | 88 if __name__ == '__main__': |
| 89 options = parseOptions(sys.argv[1:]) | 89 options = parseOptions(sys.argv[1:]) |
| 90 selectedHosts = resolveHostList(options.hosts) | 90 selectedHosts = resolveHostList(options.hosts) |
| 91 if len(selectedHosts) == 0: | 91 if len(selectedHosts) == 0: |
| 92 print >>sys.stderr, 'No valid hosts or groups specified, nothing to do' | 92 print >>sys.stderr, 'No valid hosts or groups specified, nothing to do' |
| 93 sys.exit(0) | 93 sys.exit(0) |
| 94 for host in selectedHosts: | 94 for host in selectedHosts: |
| 95 print >>sys.stderr, 'Running on %s...' % host | 95 print >>sys.stderr, 'Running on %s...' % host |
| 96 runCommand(options.user, host, options.args, options.ignore_errors) | 96 runCommand(options.user, host, options.args, options.ignore_errors) |
| LEFT | RIGHT |