diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2013-05-16 21:15:35 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-05-16 21:15:35 +0200 |
commit | 787f5f43cb6e8fb1a012115f979049375f6910b1 (patch) | |
tree | bb76a899efd5993bc38cde02fce5d3129e11d608 /bin | |
parent | 9a09a2f1a5cd428abc84f615196f518cac3cdc9f (diff) | |
download | tools-787f5f43cb6e8fb1a012115f979049375f6910b1.tar.gz tools-787f5f43cb6e8fb1a012115f979049375f6910b1.tar.bz2 tools-787f5f43cb6e8fb1a012115f979049375f6910b1.zip |
bin/hostinfo: add --keys to get valid keys for a host
The bash completion uses now a dynamic list of valid keys for
a host and therefor calls the hostinfo tool itself.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/hostinfo | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/bin/hostinfo b/bin/hostinfo index 1b92fdf..391e7db 100755 --- a/bin/hostinfo +++ b/bin/hostinfo @@ -24,6 +24,26 @@ def print_info(path, key=None, oneline=False): p = printer.Printer(data, oneline) p.info(key) +def _print_keys(data, prefix = ''): + for key in data.keys(): + print "%s%s" % (prefix, key) + + if key == 'addresses': + for k in set([a['interface'] for a in data[key]]): + print "%s%s.%s" % (prefix, key, k) + if key == 'ports': + for k in set([p['process'] for p in data[key] if 'process' in p]): + print "%s%s.%s" % (prefix, key, k) + if len([p for p in data[key] if 'process' not in p]) > 0: + print "%s%s.%s" % (prefix, key, 'UNKNOWN') + + if isinstance(data[key], dict): + _print_keys(data[key], "%s%s." % (prefix, key)) + +def print_keys(path): + data = _get_data(path) + _print_keys(data) + def find_host(host): path = "/usr/local/share/hostinfo/%s" % host if os.path.exists(path): @@ -51,11 +71,12 @@ def find_host(host): def main(): self_name = sys.argv.pop(0) - optlist, args = getopt.gnu_getopt(sys.argv, 'of', ['oneline', 'file']) + optlist, args = getopt.gnu_getopt(sys.argv, 'ofk', ['oneline', 'file', 'keys']) flags = [opt for (opt, value) in optlist if value == ''] file = '--file' in flags or '-f' in flags oneline = '--oneline' in flags or '-o' in flags + keys = '--keys' in flags or '-k' in flags if len(args) < 1: print('Usage: %s <host> [info]' % self_name) @@ -68,6 +89,8 @@ def main(): if file: print(path) + elif keys: + print_keys(path) else: if len(args) == 1: print_info(path, oneline=oneline) |