changes for 3.0
[monitor.git] / nodeconfig.py
index 61d31f9..ac84ec3 100755 (executable)
@@ -2,20 +2,28 @@
 
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
-from optparse import OptionParser
+import parser as parsermodule
 from sets import Set
 
 from nodecommon import *
 import database
 
+def network_config_to_str(net):
+
+       str = ""
+       static_keys = ['method', 'ip', 'gateway', 'network', 'broadcast', 'netmask', 'dns1', 'dns2', 'mac', 'is_primary']
+       for k in static_keys:
+               str += "%15s == %s\n" % (k, net[k])
+
+       return str
+       
+
 def main():
-       from config import config
        fb = database.dbLoad("findbad")
 
-       parser = OptionParser()
+       parser = parsermodule.getParser()
        parser.set_defaults(nodelist=None,
                                                list=False,
                                                add=False,
@@ -24,8 +32,8 @@ def main():
                                                )
        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()
+       parser = parsermodule.getParser(['defaults'], parser)
+       config = parsermodule.parse_args(parser)
 
        # COLLECT nodegroups, nodes and node lists
        for node in config.args:
@@ -33,7 +41,7 @@ def main():
                try:
                        n = api.GetNodes(node)[0]
                        #print n
-                       net = api.GetNodeNetworks(n['nodenetwork_ids'])[0]
+                       net = api.GetInterfaces(n['interface_ids'])[0]
                        #print net
 
                        node_keys = ['boot_state', 'key', 'last_updated', 'last_contact']
@@ -43,15 +51,15 @@ def main():
                                else:
                                        print "%15s == %s" % (k, n[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])
+                       print network_config_to_str(net)
 
                        #for k in net.keys():
                        #       print k, "==" , net[k]
                except:
                        print "Error with %s" % node
                        import traceback; print traceback.print_exc()
+                       from nodecommon import email_exception
+                       email_exception()
                        pass
 
        # commands: