a template for a tool that will spit out the configuration for a node to see
authorStephen Soltesz <soltesz@cs.princeton.edu>
Mon, 23 Jun 2008 17:04:48 +0000 (17:04 +0000)
committerStephen Soltesz <soltesz@cs.princeton.edu>
Mon, 23 Jun 2008 17:04:48 +0000 (17:04 +0000)
if it has any errors.

nodeconfig.py [new file with mode: 0755]

diff --git a/nodeconfig.py b/nodeconfig.py
new file mode 100755 (executable)
index 0000000..0b23c7b
--- /dev/null
@@ -0,0 +1,83 @@
+#!/usr/bin/python
+
+
+import plc
+import auth
+api = plc.PLC(auth.auth, auth.plc)
+
+from optparse import OptionParser
+from sets import Set
+
+from nodecommon import *
+import soltesz
+
+def main():
+       from config import config
+       fb = soltesz.dbLoad("findbad")
+
+       parser = OptionParser()
+       parser.set_defaults(nodelist=None,
+                                               list=False,
+                                               add=False,
+                                               notng=False,
+                                               delete=False,
+                                               )
+       parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt", 
+                                               help="Use all nodes in the given file for operation.")
+       config = config(parser)
+       config.parse_args()
+
+       # COLLECT nodegroups, nodes and node lists
+       for node in config.args:
+
+               try:
+                       n = api.GetNodes(node)[0]
+                       print n
+                       net = api.GetNodeNetworks(n['nodenetwork_ids'])[0]
+                       print net
+
+                       node_keys = ['boot_state', 'key', 'last_updated', 'last_contact']
+                       for k in node_keys:
+                               if 'last' in k:
+                                       print "%15s == %s" % (k, diff_time(net[k]))
+                               else:
+                                       print "%15s == %s" % (k, net[k])
+
+                       static_keys = ['method', 'ip', 'gateway', 'network', 'broadcast', 'netmask', 'dns1', 'dns2', 'mac', 'is_primary']
+                       for k in static_keys:
+                               print "%15s == %s" % (k, net[k])
+
+                       #for k in net.keys():
+                       #       print k, "==" , net[k]
+               except:
+                       print "Error with %s" % node
+                       pass
+
+       # commands:
+       if False:
+               if config.list:
+                       print " ---- Nodes in the %s Node Group ----" % group_str
+                       i = 1
+                       for node in nodelist:
+                               print "%-2d" % i, 
+                               print nodegroup_display(node, fb)
+                               i += 1
+
+               elif config.add and config.nodegroup:
+                       for node in hostnames:
+                               print "Adding %s to %s nodegroup" % (node, config.nodegroup)
+                               api.AddNodeToNodeGroup(node, config.nodegroup)
+
+               elif config.delete:
+                       for node in hostnames:
+                               print "Deleting %s from %s nodegroup" % (node, config.nodegroup)
+                               api.DeleteNodeFromNodeGroup(node, config.nodegroup)
+
+               else:
+                       print "no other options supported."
+
+if __name__ == "__main__":
+       try:
+               main()
+       except IOError:
+               pass