a template for a tool that will spit out the configuration for a node to see
[monitor.git] / nodeconfig.py
1 #!/usr/bin/python
2
3
4 import plc
5 import auth
6 api = plc.PLC(auth.auth, auth.plc)
7
8 from optparse import OptionParser
9 from sets import Set
10
11 from nodecommon import *
12 import soltesz
13
14 def main():
15         from config import config
16         fb = soltesz.dbLoad("findbad")
17
18         parser = OptionParser()
19         parser.set_defaults(nodelist=None,
20                                                 list=False,
21                                                 add=False,
22                                                 notng=False,
23                                                 delete=False,
24                                                 )
25         parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt", 
26                                                 help="Use all nodes in the given file for operation.")
27         config = config(parser)
28         config.parse_args()
29
30         # COLLECT nodegroups, nodes and node lists
31         for node in config.args:
32
33                 try:
34                         n = api.GetNodes(node)[0]
35                         print n
36                         net = api.GetNodeNetworks(n['nodenetwork_ids'])[0]
37                         print net
38
39                         node_keys = ['boot_state', 'key', 'last_updated', 'last_contact']
40                         for k in node_keys:
41                                 if 'last' in k:
42                                         print "%15s == %s" % (k, diff_time(net[k]))
43                                 else:
44                                         print "%15s == %s" % (k, net[k])
45
46                         static_keys = ['method', 'ip', 'gateway', 'network', 'broadcast', 'netmask', 'dns1', 'dns2', 'mac', 'is_primary']
47                         for k in static_keys:
48                                 print "%15s == %s" % (k, net[k])
49
50                         #for k in net.keys():
51                         #       print k, "==" , net[k]
52                 except:
53                         print "Error with %s" % node
54                         pass
55
56         # commands:
57         if False:
58                 if config.list:
59                         print " ---- Nodes in the %s Node Group ----" % group_str
60                         i = 1
61                         for node in nodelist:
62                                 print "%-2d" % i, 
63                                 print nodegroup_display(node, fb)
64                                 i += 1
65
66                 elif config.add and config.nodegroup:
67                         for node in hostnames:
68                                 print "Adding %s to %s nodegroup" % (node, config.nodegroup)
69                                 api.AddNodeToNodeGroup(node, config.nodegroup)
70
71                 elif config.delete:
72                         for node in hostnames:
73                                 print "Deleting %s from %s nodegroup" % (node, config.nodegroup)
74                                 api.DeleteNodeFromNodeGroup(node, config.nodegroup)
75
76                 else:
77                         print "no other options supported."
78
79 if __name__ == "__main__":
80         try:
81                 main()
82         except IOError:
83                 pass