| LEFT | RIGHT |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # coding: utf-8 | 2 # coding: utf-8 |
| 3 | 3 |
| 4 import sys | 4 import sys |
| 5 import os | 5 import os |
| 6 import re | 6 import re |
| 7 import subprocess | 7 import subprocess |
| 8 import getopt | 8 import getopt |
| 9 import yaml | 9 import yaml |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 def getValidHosts(): | 45 def getValidHosts(): |
| 46 dirname = os.path.dirname(sys.argv[0]) | 46 dirname = os.path.dirname(sys.argv[0]) |
| 47 path_name = os.path.join(dirname, "hiera", "private", "hosts.yaml") | 47 path_name = os.path.join(dirname, "hiera", "private", "hosts.yaml") |
| 48 with open(path_name, 'rb') as handle: | 48 with open(path_name, 'rb') as handle: |
| 49 config = yaml.load(handle) | 49 config = yaml.load(handle) |
| 50 servers = config.get('servers', {}) | 50 servers = config.get('servers', {}) |
| 51 return servers | 51 return servers |
| 52 | 52 |
| 53 def resolveHostList(hosts): | 53 def resolveHostList(hosts): |
| 54 | 54 |
| 55 host_names = (str(item) for item in hosts) | |
| 56 result = set() | 55 result = set() |
| 57 | 56 |
| 58 try: | 57 try: |
| 59 valid_hosts = getValidHosts() | 58 valid_hosts = getValidHosts() |
| 60 except Warning as error: | 59 except Warning as error: |
| 61 print >>sys.stderr, 'Warning: failed to determine valid hosts:', error | 60 print >>sys.stderr, 'Warning: failed to determine valid hosts:', error |
| 62 result.update(host_names) | 61 result.update(hosts) |
| 63 else: | 62 else: |
| 64 for name in host_names: | 63 for name in hosts: |
| 65 chunk = [ | 64 chunk = [ |
| 66 value.get('dns', key) for (key, value) in valid_hosts.items() | 65 value.get('dns', key) for (key, value) in valid_hosts.items() |
| 67 | 66 |
| 68 if name == key | 67 if name == key |
| 69 or name == '*' | 68 or name == '*' |
| 70 or name == value.get('dns', None) | 69 or name == value.get('dns', None) |
| 71 or name in value.get('groups', ()) | 70 or name in value.get('groups', ()) |
| 72 ] | 71 ] |
| 73 | 72 |
| 74 if len(chunk) == 0: | 73 if len(chunk) == 0: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 89 | 88 |
| 90 if __name__ == "__main__": | 89 if __name__ == "__main__": |
| 91 user, hosts, ignore_errors, args = parseOptions(sys.argv[1:]) | 90 user, hosts, ignore_errors, args = parseOptions(sys.argv[1:]) |
| 92 selectedHosts = resolveHostList(hosts) | 91 selectedHosts = resolveHostList(hosts) |
| 93 if len(selectedHosts) == 0: | 92 if len(selectedHosts) == 0: |
| 94 print >>sys.stderr, 'No valid hosts or groups specified, nothing to do' | 93 print >>sys.stderr, 'No valid hosts or groups specified, nothing to do' |
| 95 sys.exit(0) | 94 sys.exit(0) |
| 96 for host in selectedHosts: | 95 for host in selectedHosts: |
| 97 print >>sys.stderr, 'Running on %s...' % host | 96 print >>sys.stderr, 'Running on %s...' % host |
| 98 runCommand(user, host, args, ignore_errors=ignore_errors) | 97 runCommand(user, host, args, ignore_errors=ignore_errors) |
| LEFT | RIGHT |