split config.py and parser.py into two modules. updated all files to use the
authorStephen Soltesz <soltesz@cs.princeton.edu>
Fri, 8 Aug 2008 18:01:33 +0000 (18:01 +0000)
committerStephen Soltesz <soltesz@cs.princeton.edu>
Fri, 8 Aug 2008 18:01:33 +0000 (18:01 +0000)
parser module for option parsing and config for the resulting values.

one extra variable added to monitorconfig-default.py

43 files changed:
action.py
automate_pl03.sh
bootman.py
clean_policy.py
config.py
database.py
diagnose.py
fetch.py
findbad.py
findbadpcu.py
getconf.py
getnodes.py
grouprins.py
mailer.py
moncommands.py
monitor_policy.py
monitorconfig-default.py
nodeaction.py
nodebad.py
nodecommon.py
nodeconfig.py
nodediff.py
nodegroups.py
nodehistory.py
nodeinfo.py
nodenetwork.py
nodequery.py
nodesets.py
pcubad.py
pcuinfo.py
pkl2php.py
plc.py
policy.py
printbadcsv.py
query.py
reboot.py
sitebad.py
siteinfo.py
soltesz.py
syncplcdb.py
todo
unified_model.py
www/database.php

index 23e4508..dad6227 100755 (executable)
--- a/action.py
+++ b/action.py
@@ -15,9 +15,9 @@ import Queue
 from sets import Set
 
 # Global config options
-from config import config
-from optparse import OptionParser
-parser = OptionParser()
+import parser as parsermodule
+
+parser = parsermodule.getParser()
 
 parser.set_defaults(nodelist=None, 
                                        cachert=False, 
@@ -36,8 +36,7 @@ parser.add_option("", "--ticketlist", dest="ticketlist",
 parser.add_option("", "--blacklist", dest="blacklist",
                                        help="Blacklist all nodes in this file")
 
-config = config(parser)
-config.parse_args()
+config = parsermodule.parse_args(parser)
 
 # daemonize and *pid
 #from util.process import * 
index eccbc68..182aeec 100755 (executable)
@@ -1,11 +1,13 @@
 #!/bin/bash
 
-source monitorconfig.py
+# NOTE: Must be an absolute path to guarantee it is read.
+source /home/soltesz/monitor/monitorconfig.py
 cd ${MONITOR_SCRIPT_ROOT}
 set -e
 DATE=`date +%Y-%m-%d-%T`
 MONITOR_PID="$HOME/monitor/SKIP"
 
+echo "Performing API test"
 API=$(./testapi.py)
 if [ "$API" != "ok" ] ; then 
        # NOTE: Do not try to run any commands if the API is obviously broken.
@@ -27,6 +29,7 @@ if [ -f $MONITOR_PID ] ; then
 fi
 echo $$ > $MONITOR_PID
 
+echo "Performing Findbad Nodes"
 #########################
 # 1. FINDBAD NODES 
 rm -f ${MONITOR_DATA_ROOT}/production.findbad2.pkl
@@ -34,6 +37,7 @@ ${MONITOR_SCRIPT_ROOT}/findbad.py --increment --cachenodes --debug=0 --dbname="f
 cp ${MONITOR_DATA_ROOT}/production.findbad2.pkl ${MONITOR_DATA_ROOT}/production.findbad.pkl
 ps ax | grep BatchMode | grep -v grep | awk '{print $1}' | xargs kill || :
 
+echo "Performing Findbad PCUs"
 #########################
 # 2. FINDBAD PCUS
 rm -f ${MONITOR_DATA_ROOT}/production.findbadpcus2.pkl
@@ -42,17 +46,20 @@ cp ${MONITOR_DATA_ROOT}/production.findbadpcus2.pkl ${MONITOR_DATA_ROOT}/product
 # clean up stray 'locfg' processes that hang around inappropriately...
 ps ax | grep locfg | grep -v grep | awk '{print $1}' | xargs kill || :
 
+echo "Generating web data"
 # badcsv.txt
 ${MONITOR_SCRIPT_ROOT}/printbadcsv.py  | grep -v loading | tr -d ' ' > badcsv.txt
 cp badcsv.txt /plc/data/var/www/html/monitor/
 ${MONITOR_SCRIPT_ROOT}/showlatlon.py | head -9 | awk 'BEGIN {print "<table>"} { print "<tr><td>", $0, "</td></tr>"} END{print "</table>"}'  | sed -e 's\|\</td><td>\g' > /plc/data/var/www/html/monitor/regions.html
 
+echo "Performing uptime changes for sites, nodes, and pcus"
 ########################
 # 3. record last-changed for sites, nodes and pcus.
 ${MONITOR_SCRIPT_ROOT}/sitebad.py --increment || :
 ${MONITOR_SCRIPT_ROOT}/nodebad.py --increment || :
 ${MONITOR_SCRIPT_ROOT}/pcubad.py --increment || :
 
+echo "Converting pkl files to phpserial"
 #########################
 # 4. convert pkl to php serialize format.
 ${MONITOR_SCRIPT_ROOT}/pkl2php.py -i findbadpcus2 -o findbadpcus
@@ -62,20 +69,23 @@ ${MONITOR_SCRIPT_ROOT}/pkl2php.py -i findbad -o findbadnodes
 ${MONITOR_SCRIPT_ROOT}/pkl2php.py -i ad_dbTickets -o ad_dbTickets
 ${MONITOR_SCRIPT_ROOT}/pkl2php.py -i idTickets -o idTickets
 
+echo "Archiving pkl files"
 #########################
 # Archive pkl files.
 for f in findbad act_all findbadpcus l_plcnodes site_persistflags node_persistflags pcu_persistflags ; do 
        cp ${MONITOR_DATA_ROOT}/production.$f.pkl ${MONITOR_ARCHIVE_ROOT}/`date +%F-%H:%M`.production.$f.pkl
 done
 
+echo "Running grouprins on all dbg nodes"
 ############################
 # 5. Check if there are any nodes in dbg state.  Clean up afterward.
 ${MONITOR_SCRIPT_ROOT}/grouprins.py --mail=1 \
-       --nodeselect 'state=DEBUG&&boot_state=dbg||state=DEBUG&&boot_state=boot' \
+       --nodeselect 'state=DEBUG&&boot_state=(rins|dbg|boot)' \
        --stopselect 'state=BOOT&&kernel=2.6.22.19-vs2.3.0.34.9.planetlab' \
        --reboot || :
 ${MONITOR_SCRIPT_ROOT}/findbad.py --increment --cachenodes --debug=0 --dbname="findbad" --nodeselect 'state=DEBUG&&boot_state=dbg||state=DEBUG&&boot_state=boot' || :
 
+echo "Collecting RT database dump"
 ##########################
 # 6. cache the RT db locally.
 python ${MONITOR_SCRIPT_ROOT}/rt.py
index c3116bc..b9a161f 100755 (executable)
@@ -445,7 +445,7 @@ def reboot(hostname, config=None, forced_action=None):
 
                        loginbase = plc.siteId(hostname)
                        m.send([policy.PIEMAIL % loginbase, policy.TECHEMAIL % loginbase])
-                       conn.set_nodestate('diag')
+                       conn.set_nodestate('disable')
                        return False
 
        print "...Downloading bm.log from %s" % node
@@ -701,7 +701,7 @@ def reboot(hostname, config=None, forced_action=None):
                        loginbase = plc.siteId(hostname)
                        m.send([policy.PIEMAIL % loginbase, policy.TECHEMAIL % loginbase])
                        conn.dump_plconf_file()
-                       conn.set_nodestate('diag')
+                       conn.set_nodestate('disable')
 
                elif sequences[s] == "nodenetwork_email":
                        print "...Sending message to LOOK AT NODE NETWORK"
@@ -713,7 +713,7 @@ def reboot(hostname, config=None, forced_action=None):
                        loginbase = plc.siteId(hostname)
                        m.send([policy.PIEMAIL % loginbase, policy.TECHEMAIL % loginbase])
                        conn.dump_plconf_file()
-                       conn.set_nodestate('diag')
+                       conn.set_nodestate('disable')
 
                elif sequences[s] == "update_bootcd_email":
                        print "...NOTIFY OWNER TO UPDATE BOOTCD!!!"
@@ -792,10 +792,11 @@ def reboot(hostname, config=None, forced_action=None):
 # MAIN -------------------------------------------------------------------
 
 def main():
-       from config import config
-       from optparse import OptionParser
-       parser = OptionParser()
-       parser.set_defaults(node=None, nodelist=None, child=False, collect=False, nosetup=False, verbose=False, force=None, quiet=False)
+       import parser as parsermodule
+       parser = parsermodule.getParser()
+
+       parser.set_defaults(child=False, collect=False, nosetup=False, verbose=False, 
+                                               force=None, quiet=False)
        parser.add_option("", "--child", dest="child", action="store_true", 
                                                help="This is the child mode of this process.")
        parser.add_option("", "--force", dest="force", metavar="boot_state",
@@ -810,12 +811,9 @@ def main():
                                                help="No action, just collect dmesg, and bm.log")
        parser.add_option("", "--nosetup", dest="nosetup", action="store_true", 
                                                help="Do not perform the orginary setup phase.")
-       parser.add_option("", "--node", dest="node", metavar="nodename.edu", 
-                                               help="A single node name to try to bring out of debug mode.")
-       parser.add_option("", "--nodelist", dest="nodelist", metavar="nodelist.txt", 
-                                               help="A list of nodes to bring out of debug mode.")
-       config = config(parser)
-       config.parse_args()
+
+       parser = parsermodule.getParser(['nodesets', 'defaults'], parser)
+       config = parsermodule.parse_args(parser)
 
        if config.nodelist:
                nodes = config.getListFromFile(config.nodelist)
index 5e9f625..f1249cf 100644 (file)
@@ -1,6 +1,4 @@
-from config import config
-#print "policy"
-config = config()
+import config
 import database 
 import time
 import mailer
index 0a66b75..859d0aa 100644 (file)
--- a/config.py
+++ b/config.py
@@ -5,38 +5,21 @@ import getopt
 import sys
 import __main__
 from optparse import OptionParser
+from parser import parse_bool
+
+debug=0
+mail=0
+bcc=0
+email="soltesz@cs.utk.edu"
+run=False
+checkopt=False
+squeeze=0
+policysavedb=0
 
 config_command = False
 
-XMLRPC_SERVER="https://boot.planet-lab.org/PLCAPI/"
-def parse_bool(option, opt_str, value, parser):
-       if opt_str in ["--debug"]:
-               parser.values.debug = int(int(value))
-       elif opt_str in ["--mail"]:
-               parser.values.mail = int(int(value))
-       elif opt_str in ["--bcc"]:
-               parser.values.bcc = int(int(value))
-       elif opt_str in ["--policysavedb"]:
-               parser.values.policysavedb = int(int(value))
-       elif opt_str in ["--squeeze"]:
-               parser.values.squeeze = int(int(value))
-       else:
-               print "blue"
-
-def setFileFromList(file, list):
-       f = open(file, 'w')
-       for line in list:
-               f.write(line + "\n")
-       f.close()
-       return True
-
-def getListFromFile(file):
-       f = open(file, 'r')
-       list = []
-       for line in f:
-               line = line.strip()
-               list += [line]
-       return list
+def updatemodule(module, cf):
+       module.__dict__.update(cf.__dict__)
 
 class config:
        debug=0
index 14fc0e3..3c657fe 100644 (file)
@@ -11,15 +11,12 @@ except:
 
 import inspect
 import shutil
-from config import config as cfg
-config = cfg()
-
+import config
 import monitorconfig
 
 DEBUG= 0
 PICKLE_PATH=monitorconfig.MONITOR_DATA_ROOT
 
-class ExceptionTimeout(Exception): pass
 
 def dbLoad(name, type=None):
        return SPickle().load(name, type)
index 4e25974..ca4345e 100755 (executable)
@@ -15,9 +15,8 @@ import Queue
 from sets import Set
 
 # Global config options
-from config import config
-from optparse import OptionParser
-parser = OptionParser()
+import parser as parsermodule
+parser = parsermodule.getParser()
 
 parser.set_defaults(nodelist=None, 
                                        refresh=False,
@@ -39,8 +38,7 @@ parser.add_option("", "--ticketlist", dest="ticketlist",
 parser.add_option("", "--blacklist", dest="blacklist",
                                        help="Blacklist all nodes in this file")
 
-config = config(parser)
-config.parse_args()
+config = parsermodule.parse_args(parser)
 
 # daemonize and *pid
 #from util.process import * 
index e2f33a8..7d93967 100755 (executable)
--- a/fetch.py
+++ b/fetch.py
@@ -3,12 +3,10 @@
 import csv
 import sys
 import os
-import config
 from glob import glob
 
 import vxargs
-from config import config
-from optparse import OptionParser
+import parser as parsermodule
 from automate import *
 
 def build_vx_args(shell_cmd):
@@ -23,20 +21,14 @@ def vx_start(filelist,outdir,cmd, timeout=0):
        vxargs.start(None, 20, filelist, outdir, False, args, timeout)
 
 if __name__ == "__main__":
-       parser = OptionParser()
-       parser.set_defaults(nodelist=None, 
-                                               node=None,
-                                               outdir=None,
-                                               querystr=None,
+
+       parser = parsermodule.getParser(['nodesets'])
+       parser.set_defaults(outdir=None,
                                                timeout=0,
                                                simple=False,
                                                run=False,
                                                cmdfile=None,)
 
-       parser.add_option("", "--nodelist", dest="nodelist", metavar="filename",
-                                               help="Read list of nodes from specified file")
-       parser.add_option("", "--node", dest="node", metavar="hostname",
-                                               help="specify a single node name.")
        parser.add_option("", "--timeout", dest="timeout", metavar="seconds",
                                                help="Number of seconds to wait before timing out on host.")
        parser.add_option("", "--outdir", dest="outdir", metavar="dirname",
@@ -45,8 +37,7 @@ if __name__ == "__main__":
                                                help="Name of file that contains a unix-to-csv command " + \
                                                         "to run on the hosts.")
 
-       config = config(parser)
-       config.parse_args()
+       config = parsermodule.parse_args(parser)
 
        if config.outdir == None: 
                outdir="checkhosts"
@@ -56,6 +47,10 @@ if __name__ == "__main__":
        if not os.path.exists(outdir):
                os.system('mkdir -p %s' % outdir)
 
+       if config.site is not None or config.nodeselect is not None or config.nodegroup is not None:
+               print "TODO: implement support for nodeselect and site queries."
+               sys.exit(1)
+
        if config.nodelist == None and config.node == None:
                filelist="nocomon.txt"
                filelist = vxargs.getListFromFile(open(filelist,'r'))
index 2b8fe00..ce41d30 100755 (executable)
@@ -4,6 +4,7 @@ import os
 import sys
 import string
 import time
+import config
 
 
 # QUERY all nodes.
@@ -340,8 +341,8 @@ def main():
        #cohash = {}
        cohash = cotop.coget(cotop_url)
        l_nodes = syncplcdb.create_plcdb()
-       if config.filename:
-               f_nodes = config.getListFromFile(config.filename)
+       if config.nodelist:
+               f_nodes = config.getListFromFile(config.nodelist)
                l_nodes = filter(lambda x: x['hostname'] in f_nodes, l_nodes)
        elif config.node:
                f_nodes = [config.node]
@@ -368,30 +369,21 @@ def main():
 
 
 if __name__ == '__main__':
-       from config import config
-       from optparse import OptionParser
-       parser = OptionParser()
-       parser.set_defaults(filename=None, node=None, site=None, nodeselect=False, nodegroup=None, 
-                                               increment=False, dbname="findbadnodes", cachenodes=False)
-       parser.add_option("", "--node", dest="node", metavar="hostname", 
-                                               help="Provide a single node to operate on")
-       parser.add_option("-f", "--nodelist", dest="filename", metavar="FILE", 
-                                               help="Provide the input file for the node list")
-       parser.add_option("", "--nodeselect", dest="nodeselect", metavar="query string", 
-                                               help="Provide a selection string to return a node list.")
-       parser.add_option("", "--nodegroup", dest="nodegroup", metavar="FILE", 
-                                               help="Provide the nodegroup for the list of nodes.")
-       parser.add_option("", "--site", dest="site", metavar="site name",
-                                               help="Specify a site to view node status")
+       import parser as parsermodule
 
+       parser = parsermodule.getParser(['nodesets'])
+
+       parser.set_defaults( increment=False, dbname="findbadnodes", cachenodes=False)
        parser.add_option("", "--cachenodes", action="store_true",
                                                help="Cache node lookup from PLC")
        parser.add_option("", "--dbname", dest="dbname", metavar="FILE", 
                                                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()
+
+       parser = parsermodule.getParser(['defaults'], parser)
+       
+       cfg = parsermodule.parse_args(parser)
 
        try:
                main()
index 5f54235..de4474b 100755 (executable)
@@ -380,11 +380,11 @@ def main():
                # update global round number to force refreshes across all nodes
                externalState['round'] += 1
 
-       if config.filename == None and config.pcuid == None:
+       if config.nodelist == None and config.pcuid == None:
                print "Calling API GetPCUs() : refresh(%s)" % config.refresh
                l_pcus  = [pcu['pcu_id'] for pcu in l_pcus]
-       elif config.filename is not None:
-               l_pcus = config.getListFromFile(config.filename)
+       elif config.nodelist is not None:
+               l_pcus = config.getListFromFile(config.nodelist)
                l_pcus = [int(pcu) for pcu in l_pcus]
        elif config.pcuid is not None:
                l_pcus = [ config.pcuid ] 
@@ -407,14 +407,14 @@ if __name__ == '__main__':
        from config import config
        from optparse import OptionParser
        parser = OptionParser()
-       parser.set_defaults(filename=None, 
+       parser.set_defaults(nodelist=None, 
                                                increment=False, 
                                                pcuid=None,
                                                dbname="findbadpcus", 
                                                cachenodes=False,
                                                refresh=False,
                                                )
-       parser.add_option("-f", "--nodelist", dest="filename", metavar="FILE", 
+       parser.add_option("-f", "--nodelist", dest="nodelist", metavar="FILE", 
                                                help="Provide the input file for the node list")
        parser.add_option("", "--pcuid", dest="pcuid", metavar="id", 
                                                help="Provide the id for a single pcu")
index 56cf1b8..205f0ff 100755 (executable)
@@ -4,6 +4,7 @@ import plc
 api = plc.getAuthAPI()
 import sys
 import os
+import monitorconfig
 
 def getconf(hostname, force=False, media=None):
        n = api.GetNodes(hostname)
@@ -20,33 +21,32 @@ def getconf(hostname, force=False, media=None):
 
        args = {}
        if not media:
-               args['url_list']  = "   http://monitor.planet-lab.org/bootcds/%s-partition.usb\n" % hostname
-               args['url_list'] += "   http://monitor.planet-lab.org/bootcds/%s.iso" % hostname
+               args['url_list']  = "   http://%s/bootcds/%s-partition.usb\n" % (monitorconfig.MONITOR_HOSTNAME, hostname)
+               args['url_list'] += "   http://%s/bootcds/%s.iso" % (monitorconfig.MONITOR_HOSTNAME, hostname)
        else:
                if media == "usb":
-                       args['url_list']  = "   http://monitor.planet-lab.org/bootcds/%s-partition.usb\n" % hostname
+                       args['url_list']  = "   http://%s/bootcds/%s-partition.usb\n" % (monitorconfig.MONITOR_HOSTNAME, hostname)
                elif media == "iso":
-                       args['url_list']  = "   http://monitor.planet-lab.org/bootcds/%s.iso" % hostname
+                       args['url_list']  = "   http://%s/bootcds/%s.iso" % (monitorconfig.MONITOR_HOSTNAME, hostname)
                else:
-                       args['url_list']  = "   http://monitor.planet-lab.org/bootcds/%s-partition.usb\n" % hostname
-                       args['url_list'] += "   http://monitor.planet-lab.org/bootcds/%s.iso" % hostname
+                       args['url_list']  = "   http://%s/bootcds/%s-partition.usb\n" % (monitorconfig.MONITOR_HOSTNAME, hostname)
+                       args['url_list'] += "   http://%s/bootcds/%s.iso" % (monitorconfig.MONITOR_HOSTNAME, hostname)
                        
-       #print "http://monitor.planet-lab.org/bootcds/%s.usb\n" % hostname
 
        return args
 
 if __name__ == '__main__':
-       from config import config as cfg
-       from optparse import OptionParser
-       parser = OptionParser()
+       import parser as parsermodule
+
+       parser = parsermodule.getParser()
        parser.set_defaults(media='both', force=False)
        parser.add_option("", "--media", dest="media", metavar="usb, iso, both", 
                                                help="""Which media to generate the message for.""")
        parser.add_option("", "--force", dest="force", action="store_true", 
                                                help="""Force the recreation of the usb images.""")
+       parser = parsermodule.getParser(['defaults'], parser)
 
-       config = cfg(parser)
-       config.parse_args()
+       config = parsesrmodule.parse_args(parser)
 
        ret = {'url_list' : ''} 
        for i in config.args:
index 2116fe5..7be8a0e 100755 (executable)
@@ -2,22 +2,18 @@
 
 import database
 import plc
-from optparse import OptionParser
 import sys
 from reboot import pcu_name, get_pcu_values
 
 import sys
-from config import config
+import parser as parsermodule
 
-parser = OptionParser()
+parser = parsermodule.getParser()
 parser.set_defaults(withpcu=False,
                                        refresh=False)
 parser.add_option("", "--refresh", action="store_true", dest="refresh",
                                        help="Refresh the cached values")
-
-
-config = config(parser)
-config.parse_args()
+config = parsermodule.parse_args(parser)
 
 if not config.run:
        k = config.__dict__.keys()
index ffb4f85..92a745c 100755 (executable)
@@ -18,7 +18,7 @@ api = plc.getAuthAPI()
 import policy
 import traceback
 from config import config as cfg
-import config as configmodule
+import util.file
 from optparse import OptionParser
 
 from nodecommon import *
@@ -28,6 +28,7 @@ from unified_model import *
 import os
 
 import time
+import parser as parsermodule
 
 from model import *
 import bootman                 # debug nodes
@@ -159,12 +160,8 @@ try:
 except:
        rebootlog = LogRoll()
 
-parser = OptionParser()
-parser.set_defaults(nodegroup=None,
-                                       node=None,
-                                       nodelist=None,
-                                       nodeselect=None,
-                                       timewait=0,
+parser = parsermodule.getParser(['nodesets'])
+parser.set_defaults( timewait=0,
                                        skip=0,
                                        rins=False,
                                        reboot=False,
@@ -176,33 +173,9 @@ parser.set_defaults(nodegroup=None,
                                        stopvalue=None,
                                        quiet=False,
                                        )
-parser.add_option("", "--node", dest="node", metavar="nodename.edu", 
-                                       help="A single node name to add to the nodegroup")
-parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt", 
-                                       help="Use all nodes in the given file for operation.")
-parser.add_option("", "--nodegroup", dest="nodegroup", metavar="NodegroupName",
-                                       help="Specify a nodegroup to perform actions on")
-parser.add_option("", "--nodeselect", dest="nodeselect", metavar="querystring",
-                                       help="Specify a query to perform on findbad db")
-
-parser.add_option("", "--verbose", dest="verbose", action="store_true", 
-                                       help="Extra debug output messages.")
-parser.add_option("", "--nosetup", dest="nosetup", action="store_true", 
-                                       help="Do not perform the orginary setup phase.")
-
-parser.add_option("", "--skip", dest="skip", 
-                                       help="Number of machines to skip on the input queue.")
-parser.add_option("", "--timewait", dest="timewait", 
-                                       help="Minutes to wait between iterations of 10 nodes.")
 
 parser.add_option("", "--stopselect", dest="stopselect", metavar="", 
                                        help="The select string that must evaluate to true for the node to be considered 'done'")
-
-parser.add_option("", "--stopkey", dest="stopkey", metavar="", 
-                                       help="")
-parser.add_option("", "--stopvalue", dest="stopvalue", metavar="", 
-                                       help="")
-
 parser.add_option("", "--findbad", dest="findbad", action="store_true", 
                                        help="Re-run findbad on the nodes we're going to check before acting.")
 parser.add_option("", "--force", dest="force", action="store_true", 
@@ -211,9 +184,18 @@ parser.add_option("", "--rins", dest="rins", action="store_true",
                                        help="Set the boot_state to 'rins' for all nodes.")
 parser.add_option("", "--reboot", dest="reboot", action="store_true", 
                                        help="Actively try to reboot the nodes, keeping a log of actions.")
-#config = config(parser)
-config = cfg(parser)
-config.parse_args()
+
+parser.add_option("", "--verbose", dest="verbose", action="store_true", 
+                                       help="Extra debug output messages.")
+parser.add_option("", "--nosetup", dest="nosetup", action="store_true", 
+                                       help="Do not perform the orginary setup phase.")
+parser.add_option("", "--skip", dest="skip", 
+                                       help="Number of machines to skip on the input queue.")
+parser.add_option("", "--timewait", dest="timewait", 
+                                       help="Minutes to wait between iterations of 10 nodes.")
+
+parser = parsermodule.getParser(['defaults'], parser)
+config = parsermodule.parse_args(parser)
 
 # COLLECT nodegroups, nodes and node lists
 if config.nodegroup:
@@ -231,7 +213,7 @@ if config.nodeselect:
 if config.findbad:
        # rerun findbad with the nodes in the given nodes.
        file = "findbad.txt"
-       configmodule.setFileFromList(file, hostnames)
+       util.file.setFileFromList(file, hostnames)
        os.system("./findbad.py --cachenodes --debug=0 --dbname=findbad --increment --nodelist %s" % file)
 
 fb = database.dbLoad("findbad")
index f2af6cf..da6249d 100755 (executable)
--- a/mailer.py
+++ b/mailer.py
@@ -7,14 +7,13 @@
 # $Id: mailer.py,v 1.10 2007/08/08 13:28:06 soltesz Exp $
 from emailTxt import *
 import smtplib
-from config import config
+import config
 import calendar
 import logging
 import os
 import time
 import monitorconfig
 
-config = config()
 logger = logging.getLogger("monitor")
 
 MTA="localhost"
index 65684c5..869cc96 100644 (file)
@@ -2,6 +2,7 @@ import os
 
 DEBUG= 0
 
+class ExceptionTimeout(Exception): pass
 COMMAND_TIMEOUT = 60
 ssh_options = { 'StrictHostKeyChecking':'no', 
                                'BatchMode':'yes', 
index 7d79fab..3dd244c 100644 (file)
@@ -1,6 +1,4 @@
-from config import config
-#print "policy"
-config = config()
+import config
 import database
 import time
 import mailer
index a30ab16..f568e47 100644 (file)
@@ -20,3 +20,4 @@ API_AUTH_PASSWORD=""
 MONITOR_SCRIPT_ROOT="/home/soltesz/monitor"
 MONITOR_DATA_ROOT="/home/soltesz/monitor/pdb"
 MONITOR_ARCHIVE_ROOT="/home/soltesz/monitor/archive-pdb"
+MONITOR_HOSTNAME="monitor.planet-lab.org"
index 62095d1..cff7f6a 100755 (executable)
@@ -8,10 +8,9 @@ import reboot
 import time
 from model import *
 
-from config import config
-from optparse import OptionParser
+import parser as parsermodule
 
-parser = OptionParser()
+parser = parsermodule.getParser()
 parser.set_defaults(node=None, rins=False, bootstate=None, endrecord=False)
 parser.add_option("", "--backoff", dest="backoff", action="store_true",
                                        help="Back off all penalties applied to a site.")
@@ -19,15 +18,12 @@ parser.add_option("", "--rins", dest="rins", action="store_true",
                                        help="Back off all penalties applied to a site.")
 parser.add_option("", "--bootstate", dest="bootstate", 
                                        help="set the bootstate for a node.")
-config = config(parser)
-config.parse_args()
+parser = parsermodule.getParser(['defaults'], parser)
+config = parsermodule.parse_args(parser)
 
 for node in config.args:
        config.node = node
 
-       #plc_nodeinfo = api.GetNodes({'hostname': config.node}, None)[0]
-       #fb_nodeinfo  = fb['nodes'][config.node]['values']
-
        if config.bootstate:
                print "Setting %s to bootstate %s" % ( node, config.bootstate )
                api.UpdateNode(node, {'boot_state' : config.bootstate})
index c274f49..3261f88 100755 (executable)
@@ -11,6 +11,7 @@ import comon
 import threadpool
 import syncplcdb
 from nodequery import verify,query_to_dict,node_select
+from nodecommon import *
 
 import plc
 api = plc.getAuthAPI()
@@ -132,22 +133,17 @@ def collectStatusAndState(nodename, l_plcnodes):
        return True
 
 if __name__ == '__main__':
-       from config import config
-       from optparse import OptionParser
-       parser = OptionParser()
+       import parser as parsermodule
+       parser = parsermodule.getParser(['nodesets'])
        parser.set_defaults(filename=None, node=None, nodeselect=False, nodegroup=None, 
                                                increment=False, dbname="nodebad", cachenodes=False)
-       parser.add_option("", "--node", dest="node", metavar="hostname", 
-                                               help="Provide a single node to operate on")
-       parser.add_option("", "--nodelist", dest="nodelist", metavar="file.list", 
-                                               help="Provide a list of files to operate on")
-
+       
        parser.add_option("", "--dbname", dest="dbname", metavar="FILE", 
                                                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()
+       parser = parsermodule.getParser(['defaults'], parser)
+       config = parsermodule.parse_args(parser)
 
        try:
                main(config)
index 40c892a..b9027d8 100644 (file)
@@ -74,12 +74,15 @@ def color_boot_state(l):
        else:
                return l
 
-def diff_time(timestamp):
+def diff_time(timestamp, abstime=True):
        import math
        now = time.time()
        if timestamp == None:
                return "unknown"
-       diff = now - timestamp
+       if abstime:
+               diff = now - timestamp
+       else:
+               diff = timestamp
        # return the number of seconds as a difference from current time.
        t_str = ""
        if diff < 60: # sec in min.
@@ -127,8 +130,12 @@ def nodegroup_display(node, fb, conf=None):
        node['lastupdate'] = diff_time(node['last_contact'])
        pf = PersistFlags(node['hostname'], 1, db='node_persistflags')
        node['lc'] = diff_time(pf.last_changed)
+       ut = fb['nodes'][node['hostname']]['values']['comonstats']['uptime']
+       if ut != "null":
+               ut = diff_time(float(fb['nodes'][node['hostname']]['values']['comonstats']['uptime']), False)
+       node['uptime'] = ut
 
-       return "%(hostname)-42s %(boot_state)8s %(current)5s %(pcu)6s %(key)10.10s... %(kernel)33s %(lastupdate)12s, %(lc)s" % node
+       return "%(hostname)-42s %(boot_state)8s %(current)5s %(pcu)6s %(key)10.10s... %(kernel)33s %(lastupdate)12s, %(lc)s, %(uptime)s" % node
 
 from model import *
 import database
index d8a8c12..2327ec0 100755 (executable)
@@ -4,7 +4,7 @@
 import plc
 api = plc.getAuthAPI()
 
-from optparse import OptionParser
+import parser as parsermodule
 from sets import Set
 
 from nodecommon import *
@@ -21,10 +21,9 @@ def network_config_to_str(net):
        
 
 def main():
-       from config import config
        fb = database.dbLoad("findbad")
 
-       parser = OptionParser()
+       parser = parsermodule.getParser()
        parser.set_defaults(nodelist=None,
                                                list=False,
                                                add=False,
@@ -33,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:
index a05f291..933ddc6 100644 (file)
@@ -2,8 +2,8 @@
 
 import sys
 import database
-
-from config import config as cfg
+import config
+import parser as parsermodule
 
 def nodes_from_time(time_str):
        path = "archive-pdb"
@@ -22,13 +22,13 @@ def nodes_from_time(time_str):
        
 
 def main():
-       parser = OptionParser()
+       parser = parsermodule.getParser()
        parser.set_defaults(nodeselect=None,)
        parser.add_option("", "--nodeselect", dest="nodeselect", metavar="state=BOOT", 
                                                help="""Query on the nodes to count""")
 
-       config = cfg(parser)
-       config.parse_args()
+       parser = parsermodule.getParser(['defaults'], parser)
+       cfg = parsermodule.parse_args(parser)
 
        time1 = config.args[0]
        time2 = config.args[1]
index be4ed6f..e96e7b4 100755 (executable)
@@ -16,7 +16,7 @@
 import plc
 api = plc.getAuthAPI()
 
-from optparse import OptionParser
+import parser as parsermodule
 from sets import Set
 from nodequery import verify,query_to_dict,node_select
 
@@ -24,29 +24,17 @@ from nodecommon import *
 import database
 
 def main():
-       from config import config
        fb = database.dbLoad("findbad")
 
-       parser = OptionParser()
-       parser.set_defaults(nodegroup="Alpha",
-                                               node=None,
-                                               nodelist=None,
-                                               list=True,
+       parser = parsermodule.getParser(['nodesets'])
+       parser.set_defaults( list=True,
                                                add=False,
                         nocolor=False,
                                                notng=False,
-                                               delete=False,
-                                               nodeselect=None,
-                                               )
+                                               delete=False,)
+
        parser.add_option("", "--not", dest="notng", action="store_true", 
                                                help="All nodes NOT in nodegroup.")
-       parser.add_option("", "--nodegroup", dest="nodegroup", metavar="NodegroupName",
-                                               help="Specify a nodegroup to perform actions on")
-       parser.add_option("", "--nodeselect", dest="nodeselect", metavar="querystring",
-                                               help="Specify a query to perform on findbad db")
-       parser.add_option("", "--site", dest="site", metavar="site name",
-                                               help="Specify a site to view node status")
-
        parser.add_option("", "--nocolor", dest="nocolor", action="store_true", 
                                                help="Enable color")
        parser.add_option("", "--list", dest="list", action="store_true", 
@@ -55,12 +43,9 @@ def main():
                                                help="Add nodes to the given nodegroup")
        parser.add_option("", "--delete", dest="delete", action="store_true", 
                                                help="Delete nodes from the given nodegroup")
-       parser.add_option("", "--node", dest="node", metavar="nodename.edu", 
-                                               help="A single node name to add to the nodegroup")
-       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
        if config.node or config.nodelist:
@@ -131,6 +116,7 @@ def main():
 
        elif config.list:
                print " ---- Nodes in the %s Node Group ----" % group_str
+               print "   Hostname                                   plc  obs     pcu     key         kernel                        last_contact, last change, comon uptime"
                i = 1
                for node in nodelist:
                        print "%-2d" % i, 
index 520037c..abbcee8 100755 (executable)
@@ -73,10 +73,9 @@ def pcu_print_info(pcuinfo, hostname):
                                (reboot.pcu_name(pcuinfo), pcuinfo['username'], pcuinfo['password'])
 
 def main():
-       from config import config
-       from optparse import OptionParser
+       import parser as parsermodule
 
-       parser = OptionParser()
+       parser = parsermodule.getParser()
        parser.set_defaults(node=None, fields='state', fromtime=None)
        parser.add_option("", "--node", dest="node", metavar="nodename.edu", 
                                                help="A single node name to add to the nodegroup")
@@ -84,8 +83,7 @@ def main():
                                                help="Which record field to extract from all files.")
        parser.add_option("", "--fromtime", dest="fromtime", metavar="YYYY-MM-DD",
                                                help="Specify a starting date from which to begin the query.")
-       config = config(parser)
-       config.parse_args()
+       config = parsermodule.parse_args(parser)
 
        path = "archive-pdb"
        archive = database.SPickle(path)
index f50f846..fc27781 100755 (executable)
@@ -10,12 +10,11 @@ import time
 from model import *
 from nodecommon import *
 
-import config as configmodule
+import util.file
 
-from config import config as cfg
-from optparse import OptionParser
+import parser as parsermodule
 
-parser = OptionParser()
+parser = parsermodule.getParser()
 parser.set_defaults(node=None, 
                                        findbad=False,
                                        endrecord=False)
@@ -27,35 +26,8 @@ parser.add_option("", "--findbad", dest="findbad", action="store_true",
                                        help="Re-run findbad on the nodes we're going to check before acting.")
 parser.add_option("", "--bootcd", dest="bootcd", action="store_true",
                                        help="A stock help message for fetching a new BootCD from the PLC GUI.")
-config = cfg(parser)
-config.parse_args()
-
-def diff_time(timestamp):
-       now = time.time()
-       if timestamp == None:
-               return "unknown"
-       diff = now - timestamp
-       # return the number of seconds as a difference from current time.
-       t_str = ""
-       if diff < 60: # sec in min.
-               t = diff
-               t_str = "%s sec ago" % t
-       elif diff < 60*60: # sec in hour
-               t = diff // (60)
-               t_str = "%s min ago" % int(t)
-       elif diff < 60*60*24: # sec in day
-               t = diff // (60*60)
-               t_str = "%s hours ago" % int(t)
-       elif diff < 60*60*24*7: # sec in week
-               t = diff // (60*60*24)
-               t_str = "%s days ago" % int(t)
-       elif diff < 60*60*24*30: # approx sec in month
-               t = diff // (60*60*24*7)
-               t_str = "%s weeks ago" % int(t)
-       elif diff > 60*60*24*30: # approx sec in month
-               t = diff // (60*60*24*7*30)
-               t_str = "%s months ago" % int(t)
-       return t_str
+config = parsermodule.parse_args(parser)
+
 
 def plc_print_nodeinfo(plcnode):
        url = "https://www.planet-lab.org/db/nodes/index.php?nodepattern="
@@ -157,7 +129,7 @@ if config.findbad:
        # rerun findbad with the nodes in the given nodes.
        import os
        file = "findbad.txt"
-       configmodule.setFileFromList(file, config.args)
+       util.file.setFileFromList(file, config.args)
        os.system("./findbad.py --cachenodes --debug=0 --dbname=findbad --increment --nodelist %s" % file)
 
 fb = database.dbLoad("findbad")
index ec8d869..5c1a439 100755 (executable)
@@ -3,7 +3,7 @@
 import sys
 import plc
 api = plc.getAuthAPI()
-import config
+import util.file
 
 if len(sys.argv[1:]) > 0:
        for host in sys.argv[1:]:
@@ -24,7 +24,7 @@ if len(sys.argv[1:]) > 0:
                                        #print nn2['nodenetwork_id']
                                        #api.DeleteNodeNetwork(nn2['nodenetwork_id'])
 else:
-       nnids = config.getListFromFile('nnids.txt')
+       nnids = util.file.getListFromFile('nnids.txt')
        nnids = [ int(i) for i in nnids]
        for id in nnids:
                nnet2 = api.GetNodeNetworks(id)
index a982e20..87aad9f 100755 (executable)
@@ -10,6 +10,7 @@ from policy import Diagnose
 import glob
 import os
 from reboot import pcu_name
+import util.file
 
 import time
 import re
@@ -240,10 +241,11 @@ def main():
        global fb
        global fbpcu
 
-       from config import config
-       from optparse import OptionParser
-       parser = OptionParser()
-       parser.set_defaults(node=None, fromtime=None, select=None, list=None, pcuselect=None, nodelist=None, daysdown=None, fields=None)
+       import parser as parsermodule
+       parser = parsermodule.getParser()
+
+       parser.set_defaults(node=None, fromtime=None, select=None, list=None, 
+                                               pcuselect=None, nodelist=None, daysdown=None, fields=None)
        parser.add_option("", "--daysdown", dest="daysdown", action="store_true",
                                                help="List the node state and days down...")
        parser.add_option("", "--select", dest="select", metavar="key=value", 
@@ -258,8 +260,9 @@ def main():
                                                help="A list of nodes to bring out of debug mode.")
        parser.add_option("", "--fromtime", dest="fromtime", metavar="YYYY-MM-DD",
                                        help="Specify a starting date from which to begin the query.")
-       config = config(parser)
-       config.parse_args()
+
+       parser = parsermodule.getParser(['defaults'], parser)
+       config = parsermodule.parse_args(parser)
        
        if config.fromtime:
                path = "archive-pdb"
@@ -278,7 +281,7 @@ def main():
        fbpcu = database.dbLoad("findbadpcus")
 
        if config.nodelist:
-               nodelist = config.getListFromFile(config.nodelist)
+               nodelist = util.file.getListFromFile(config.nodelist)
        else:
                nodelist = fb['nodes'].keys()
 
@@ -291,7 +294,6 @@ def main():
        elif config.pcuselect is not None:
                nodelist, pculist = pcu_select(config.pcuselect, nodelist)
 
-
        if pculist:
                for pcu in pculist:
                        print pcu
index 85bf9b7..63b049c 100755 (executable)
@@ -1,19 +1,17 @@
 #!/usr/bin/python
 
-from config import config as cfg
 import sys
 import os
 from sets import Set
-from optparse import OptionParser
+import parser as parsermodule
 
 def main():
-       parser = OptionParser()
+       parser = parsermodule.getParser()
        parser.set_defaults(operation="and",)
        parser.add_option("", "--operation", dest="operation", metavar="and", 
                                                help="""Which operation to perform on the two sets.  (and, or, minus""")
 
-       config = cfg(parser)
-       config.parse_args()
+       config = parsermodule.parse_args(parser)
 
        f1 = config.args[0]
        f2 = config.args[1]
index fbcdb17..c2886f5 100755 (executable)
--- a/pcubad.py
+++ b/pcubad.py
@@ -12,6 +12,8 @@ import comon
 import threadpool
 import syncplcdb
 from nodequery import verify,query_to_dict,node_select
+import parser as parsermodule
+from nodecommon import *
 
 import plc
 api = plc.getAuthAPI()
@@ -134,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", 
@@ -148,8 +148,7 @@ 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)
index 20f9895..d6d5e87 100755 (executable)
@@ -2,18 +2,17 @@
 
 import database
 import plc
-from optparse import OptionParser
+import parser as parsermodule
 import sys
 from reboot import pcu_name, get_pcu_values
 
 import sys
-from config import config
 
 def print_dict(dict):
        for key in dict.keys():
                print "%30s : %s" % (key, dict[key])
 
-parser = OptionParser()
+parser = parsermodule.getParser()
 parser.set_defaults(withpcu=False,
                                        refresh=False)
 parser.add_option("-f", "--nodelist",dest="filename",default="", metavar="FILE",
@@ -21,9 +20,7 @@ parser.add_option("-f", "--nodelist",dest="filename",default="", metavar="FILE",
 parser.add_option("", "--refresh", action="store_true", dest="refresh",
                                        help="Refresh the cached values")
 
-
-config = config(parser)
-config.parse_args()
+config = parsermodule.parse_args(parser)
 
 if not config.run:
        k = config.__dict__.keys()
index 34d90e0..677a54f 100755 (executable)
@@ -1,16 +1,15 @@
 #!/usr/bin/python
 
 import database 
-from config import config
-from optparse import OptionParser
-parser = OptionParser()
+import parser as parsermodule
+
+parser = parsermodule.getParser()
 parser.set_defaults(filename=None)
 parser.add_option("-i", "--idb", dest="input", metavar="dbname", 
                                        help="Provide the input dbname to convert")
 parser.add_option("-o", "--odb", dest="output", metavar="dbname", 
                                        help="Provide the output dbname to save to")
-config = config(parser)
-config.parse_args()
+config = parsermodule.parse_args(parser)
 
 if config.input is None:
        print "please provide a pickle file to convert"
diff --git a/plc.py b/plc.py
index 11d6e6e..363bc8c 100644 (file)
--- a/plc.py
+++ b/plc.py
@@ -13,8 +13,7 @@ import logging
 import time
 import traceback
 try:
-       from config import config
-       config = config()
+       import config
        debug = config.debug
 except:
        debug = False
index e72ec8b..027da35 100644 (file)
--- a/policy.py
+++ b/policy.py
@@ -22,9 +22,7 @@ import reboot
 import database
 import string
 from www.printbadnodes import cmpCategoryVal
-from config import config
-#print "policy"
-config = config()
+import config
 
 DAT="./monitor.dat"
 
index 0d6ccec..5d6989d 100755 (executable)
@@ -1,7 +1,8 @@
 #!/usr/bin/python
 import database
-from config import config
-from optparse import OptionParser
+import config
+import parser as parsermodule
+
 from www.printbadnodes import *
 
 def main():
@@ -128,7 +129,7 @@ def main():
        print ""
 import cgi
 if __name__ == '__main__':
-       parser = OptionParser()
+       parser = parsermodule.getParser()
        parser.set_defaults(cmpdays=False, 
                                                comon="sshstatus", 
                                                fields="nodename,ping,ssh,pcu,category,state,kernel,bootcd,rt", 
@@ -148,6 +149,5 @@ if __name__ == '__main__':
        parser.add_option("", "--kernel",       dest="cmpkernel", action="store_true", help="")
        parser.add_option("", "--state",        dest="cmpstate", action="store_true", help="")
        parser.add_option("", "--comon",        dest="comon",   help="")
-       config = config(parser)
-       config.parse_args()
+       config = parsermodule.parse_args(parser)
        main()
index 53eadfb..835883e 100755 (executable)
--- a/query.py
+++ b/query.py
@@ -9,11 +9,11 @@ import re
 from cgi import parse_qs
 
 import vxargs
-from config import config
-from optparse import OptionParser
+import parser as parsermodule
+
 from automate import *
 
-parser = OptionParser()
+parser = parsermodule.getParser()
 parser.set_defaults(nodelist=None, 
                                    outdir=None,
                                        querystr=None,
@@ -30,9 +30,7 @@ parser.add_option("", "--query", dest="querystr", metavar="QUERY",
 parser.add_option("", "--simple", dest="simple", action="store_true",
                                        help="display simple output")
 
-config = config(parser)
-config.parse_args()
-
+config = parsermodule.parse_args(parser)
 
 if config.outdir == None: 
        outdir="checkhosts"
index f45a0a7..76cacd3 100755 (executable)
--- a/reboot.py
+++ b/reboot.py
@@ -706,7 +706,9 @@ class BayTechCtrlCUnibe(PCUControl):
 
                # Control Outlets  (5 ,1).........5
                try:
-                       index = s.expect(["Enter Request :"])
+                       print s
+                       print "Enter Request" in s.before
+                       index = s.expect("Enter Request")
 
                        if index == 0:
                                print "3"
@@ -786,7 +788,10 @@ class BayTechCtrlC(PCUControl):
                                                        print "sending Y"
                                                        s.send("Y\r\n")
 
-                               index = s.expect(["DS-RPC>"])
+                               # NOTE: for some reason, the script times out with the
+                               # following line.  In manual tests, it works correctly, but
+                               # with automated tests, evidently it fails.
+                               #index = s.expect(["DS-RPC>"])
                                #print "got prompt back"
 
                        s.close()
index 6b12ef3..dc0e8a7 100755 (executable)
@@ -119,9 +119,9 @@ def collectStatusAndState(sitename, l_plcsites):
        return True
 
 if __name__ == '__main__':
-       from config import config
-       from optparse import OptionParser
-       parser = OptionParser()
+       import parser as parsermodule
+
+       parser = parsermodule.getParser()
        parser.set_defaults(filename=None, node=None, site=None, nodeselect=False, nodegroup=None, 
                                                increment=False, dbname="sitebad", cachenodes=False)
        parser.add_option("", "--site", dest="site", metavar="login_base", 
@@ -133,8 +133,7 @@ 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)
index f3692bc..e9dc9d5 100755 (executable)
@@ -10,12 +10,12 @@ import time
 from model import *
 from nodecommon import *
 
-import config as configmodule
+import util.file
 
-from config import config as cfg
-from optparse import OptionParser
+import parser as parsermodule
 
-parser = OptionParser()
+
+parser = parsermodule.getParser()
 parser.set_defaults(site=None, 
                                        findbad=False,
                                        enable=False,
@@ -29,8 +29,7 @@ parser.add_option("", "--enable", dest="enable", action="store_true",
                                        help="")
 parser.add_option("", "--disable", dest="disable", action="store_true",
                                        help="")
-config = cfg(parser)
-config.parse_args()
+config = parsermodule.parse_args(parser)
 
 from unified_model import *
 def color_sitestatus(status):
@@ -94,7 +93,7 @@ for site in config.args:
                file = "findbad.txt"
                nodes = api.GetNodes(plc_siteinfo['node_ids'], ['hostname'])
                nodes = [ n['hostname'] for n in nodes ]
-               configmodule.setFileFromList(file, nodes)
+               util.file.setFileFromList(file, nodes)
                os.system("./findbad.py --cachenodes --debug=0 --dbname=findbad --increment --nodelist %s" % file)
 
        print "%(login_base)s %(url)s" % plc_siteinfo
index ea61b70..3f57530 100644 (file)
@@ -11,8 +11,7 @@ except:
 
 import inspect
 import shutil
-from config import config as cfg
-config = cfg()
+import config
 
 import monitorconfig
 
index e7a8a49..de6a474 100755 (executable)
@@ -1,12 +1,10 @@
 #!/usr/bin/python
 
 import plc
-from config import config
+import config
 import database
 import sys
 
-config = config()
-
 def dsites_from_lsites(l_sites):
        d_sites = {}
        id2lb = {}
diff --git a/todo b/todo
index cedd0aa..9ad2141 100644 (file)
--- a/todo
+++ b/todo
@@ -3,6 +3,19 @@ TODO:
  * reimplement the config.py / .config mechanism.  i'd like for many commands
    to share very similar argument or argument sets, as well as have some
    common config options.  I'm not sure the best way to do this.
+    
+        - features of config.py
+               * parse arguments and return an object with attributes equal to the
+                 parser values.
+               * maintain values consistently across modules at run time.
+               * have default values that are not specified at each run time.
+               * easy to import and use
+
+        - config module is available via 'import config' or as returned by
+                 parsermodule.parse_args()
+     - python supports load-once modules, so subsequent imports refer to the
+          same module object.
+          
 
  * Find a better location to place and pull the PKL files currently in the pdb
    directory.  Ultimately, these should be stored in a real DB.  Until then,
@@ -11,6 +24,13 @@ TODO:
 
  * clean up plc.py; there's a lot of redundent code.
 
+ * figure out python paths for user commands.
+   - directories for pickle files.
+   - add user in rpm install
+   - user permissions for data files for day-to-day operations.
+
+ * fix BayTechCtrlCUnibe expect script.
+
 Lower priority:
  * Add a more structured, 'automate' library of scripts and means of making
    batch calls, etc.
index 01c99a2..2fbb6e2 100755 (executable)
@@ -10,10 +10,11 @@ import time
 from nodecommon import *
 
 from const import *
+import util.file
+import config
 
 def gethostlist(hostlist_file):
-       import config
-       return config.getListFromFile(hostlist_file)
+       return util.file.getListFromFile(hostlist_file)
        
        #nodes = api.GetNodes({'peer_id' : None}, ['hostname'])
        #return [ n['hostname'] for n in nodes ]
@@ -532,10 +533,6 @@ class Record(object):
                return message
        
        def getContacts(self):
-               from config import config
-               #print "policy"
-               config = config()
-
                roles = self.data['email']
 
                if not config.mail and not config.debug and config.bcc:
index bef3e03..070be1f 100644 (file)
@@ -1,8 +1,8 @@
 
 <?php 
 
-// PICKLE_PATH="/home/soltesz/research/planetlab/monitor3/pdb";
-define("PICKLE_PATH", "pdb");
+include 'monitorconfig.php';
+define("PICKLE_PATH", MONITOR_DATA_ROOTWEB);
 
 class Pickle
 {