-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_pillar_info.nacl
executable file
·49 lines (38 loc) · 1.21 KB
/
get_pillar_info.nacl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3
import argparse
import json
import logging
import os
import requests
import sys
from nacl.app import Nacl
parser = argparse.ArgumentParser ()
parser.add_argument ('--config', '-c', help = "Path to 'nacl_config.json'")
parser.add_argument ('--all', '-a', action = 'store_true', help = 'Print all nodes')
parser.add_argument ('node', help = 'Node id to query for (output will include private info for this one)')
args = parser.parse_args ()
#
# Default config file paths
#
default_configs = [
'nacl_config.json',
'/etc/nacl/nacl_config.json'
]
if not getattr (args, 'config'):
for path in default_configs:
if os.path.isfile (path):
setattr (args, 'config', path)
break
nacl = Nacl (args.config, logging.getLogger ('nacl'), False)
resp = nacl.get_pillar_info (args.node)
if resp.code != 200:
print (f"Error while getting pillar info, got HTTP code {resp.code}!")
sys.exit (1)
nodes = resp.value
if args.all:
print (json.dumps (nodes, indent = 4, sort_keys = True))
else:
node = nodes.get (args.node, None)
if not node:
print (f"Node '{args.node}' not found!")
print (json.dumps (node, indent = 4, sort_keys = True))