Added a check for bad dns on the node that prevents bootmanager from booting.
[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 database
13
14 def network_config_to_str(net):
15
16         str = ""
17         static_keys = ['method', 'ip', 'gateway', 'network', 'broadcast', 'netmask', 'dns1', 'dns2', 'mac', 'is_primary']
18         for k in static_keys:
19                 str += "%15s == %s\n" % (k, net[k])
20
21         return str
22         
23
24 def main():
25         from config import config
26         fb = database.dbLoad("findbad")
27
28         parser = OptionParser()
29         parser.set_defaults(nodelist=None,
30                                                 list=False,
31                                                 add=False,
32                                                 notng=False,
33                                                 delete=False,
34                                                 )
35         parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt", 
36                                                 help="Use all nodes in the given file for operation.")
37         config = config(parser)
38         config.parse_args()
39
40         # COLLECT nodegroups, nodes and node lists
41         for node in config.args:
42
43                 try:
44                         n = api.GetNodes(node)[0]
45                         #print n
46                         net = api.GetNodeNetworks(n['nodenetwork_ids'])[0]
47                         #print net
48
49                         node_keys = ['boot_state', 'key', 'last_updated', 'last_contact']
50                         for k in node_keys:
51                                 if 'last' in k:
52                                         print "%15s == %s" % (k, diff_time(n[k]))
53                                 else:
54                                         print "%15s == %s" % (k, n[k])
55
56                         print network_config_to_str(net)
57
58                         #for k in net.keys():
59                         #       print k, "==" , net[k]
60                 except:
61                         print "Error with %s" % node
62                         import traceback; print traceback.print_exc()
63                         pass
64
65         # commands:
66         if False:
67                 if config.list:
68                         print " ---- Nodes in the %s Node Group ----" % group_str
69                         i = 1
70                         for node in nodelist:
71                                 print "%-2d" % i, 
72                                 print nodegroup_display(node, fb)
73                                 i += 1
74
75                 elif config.add and config.nodegroup:
76                         for node in hostnames:
77                                 print "Adding %s to %s nodegroup" % (node, config.nodegroup)
78                                 api.AddNodeToNodeGroup(node, config.nodegroup)
79
80                 elif config.delete:
81                         for node in hostnames:
82                                 print "Deleting %s from %s nodegroup" % (node, config.nodegroup)
83                                 api.DeleteNodeFromNodeGroup(node, config.nodegroup)
84
85                 else:
86                         print "no other options supported."
87
88 if __name__ == "__main__":
89         try:
90                 main()
91         except IOError:
92                 pass