changes for 3.0
[monitor.git] / pcubad.py
index ba9e83c..008ecd8 100755 (executable)
--- a/pcubad.py
+++ b/pcubad.py
@@ -7,17 +7,18 @@ import time
 
 from reboot import pcu_name
 
-import soltesz
+import database
 import comon
 import threadpool
 import syncplcdb
 from nodequery import verify,query_to_dict,node_select
+import parser as parsermodule
+from nodecommon import *
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 from unified_model import *
-from monitor_policy import MINUP
+from const import MINUP
 
 round = 1
 externalState = {'round': round, 'nodes': {}}
@@ -25,12 +26,12 @@ count = 0
 
 def main(config):
        global externalState
-       externalState = soltesz.if_cached_else(1, config.dbname, lambda : externalState) 
+       externalState = database.if_cached_else(1, config.dbname, lambda : externalState) 
        if config.increment:
                # update global round number to force refreshes across all pcus
                externalState['round'] += 1
 
-       l_plcpcus = soltesz.if_cached_else_refresh(1, 1, "pculist", lambda : plc.GetPCUs())
+       l_plcpcus = database.if_cached_else_refresh(1, 1, "pculist", lambda : plc.GetPCUs())
 
        l_pcu = None
        if config.pcu:
@@ -65,12 +66,12 @@ def checkAndRecordState(l_pcus, l_plcpcus):
                        count += 1
 
                if count % 20 == 0:
-                       soltesz.dbDump(config.dbname, externalState)
+                       database.dbDump(config.dbname, externalState)
 
-       soltesz.dbDump(config.dbname, externalState)
+       database.dbDump(config.dbname, externalState)
 
-fbpcu = soltesz.dbLoad('findbadpcus')
-hn2lb = soltesz.dbLoad("plcdb_hn2lb")
+fbpcu = database.dbLoad('findbadpcus')
+hn2lb = database.dbLoad("plcdb_hn2lb")
 
 def get(fb, path):
        indexes = path.split("/")
@@ -135,9 +136,7 @@ def collectStatusAndState(pcuname, l_plcpcus):
        return True
 
 if __name__ == '__main__':
-       from config import config
-       from optparse import OptionParser
-       parser = OptionParser()
+       parser = parsermodule.getParser()
        parser.set_defaults(filename=None, pcu=None, pcuselect=False, pcugroup=None, 
                                                increment=False, dbname="pcubad", cachepcus=False)
        parser.add_option("", "--pcu", dest="pcu", metavar="hostname", 
@@ -149,15 +148,16 @@ if __name__ == '__main__':
                                                help="Specify the name of the database to which the information is saved")
        parser.add_option("-i", "--increment", action="store_true", dest="increment", 
                                                help="Increment round number to force refresh or retry")
-       config = config(parser)
-       config.parse_args()
+       config = parsermodule.parse_args(parser)
 
        try:
                main(config)
        except Exception, err:
                import traceback
                print traceback.print_exc()
+               from nodecommon import email_exception
+               email_exception()
                print "Exception: %s" % err
                print "Saving data... exitting."
-               soltesz.dbDump(config.dbname, externalState)
+               database.dbDump(config.dbname, externalState)
                sys.exit(0)