parser module for option parsing and config for the resulting values.
one extra variable added to monitorconfig-default.py
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,
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 *
#!/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.
fi
echo $$ > $MONITOR_PID
+echo "Performing Findbad Nodes"
#########################
# 1. FINDBAD NODES
rm -f ${MONITOR_DATA_ROOT}/production.findbad2.pkl
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
# 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
${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
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
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"
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!!!"
# 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",
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)
-from config import config
-#print "policy"
-config = config()
+import config
import database
import time
import mailer
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
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)
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,
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 *
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):
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",
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"
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'))
import sys
import string
import time
+import config
# QUERY all nodes.
#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]
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()
# 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 ]
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")
api = plc.getAuthAPI()
import sys
import os
+import monitorconfig
def getconf(hostname, force=False, media=None):
n = api.GetNodes(hostname)
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:
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()
import policy
import traceback
from config import config as cfg
-import config as configmodule
+import util.file
from optparse import OptionParser
from nodecommon import *
import os
import time
+import parser as parsermodule
from model import *
import bootman # debug nodes
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,
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",
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:
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")
# $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"
DEBUG= 0
+class ExceptionTimeout(Exception): pass
COMMAND_TIMEOUT = 60
ssh_options = { 'StrictHostKeyChecking':'no',
'BatchMode':'yes',
-from config import config
-#print "policy"
-config = config()
+import config
import database
import time
import mailer
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"
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.")
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})
import threadpool
import syncplcdb
from nodequery import verify,query_to_dict,node_select
+from nodecommon import *
import plc
api = plc.getAuthAPI()
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)
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.
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
import plc
api = plc.getAuthAPI()
-from optparse import OptionParser
+import parser as parsermodule
from sets import Set
from nodecommon import *
def main():
- from config import config
fb = database.dbLoad("findbad")
- parser = OptionParser()
+ parser = parsermodule.getParser()
parser.set_defaults(nodelist=None,
list=False,
add=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()
+ parser = parsermodule.getParser(['defaults'], parser)
+ config = parsermodule.parse_args(parser)
# COLLECT nodegroups, nodes and node lists
for node in config.args:
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"
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]
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
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",
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:
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,
(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")
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)
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)
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="
# 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")
import sys
import plc
api = plc.getAuthAPI()
-import config
+import util.file
if len(sys.argv[1:]) > 0:
for host in sys.argv[1:]:
#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)
import glob
import os
from reboot import pcu_name
+import util.file
import time
import re
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",
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"
fbpcu = database.dbLoad("findbadpcus")
if config.nodelist:
- nodelist = config.getListFromFile(config.nodelist)
+ nodelist = util.file.getListFromFile(config.nodelist)
else:
nodelist = fb['nodes'].keys()
elif config.pcuselect is not None:
nodelist, pculist = pcu_select(config.pcuselect, nodelist)
-
if pculist:
for pcu in pculist:
print pcu
#!/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]
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()
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",
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)
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",
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()
#!/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"
import time
import traceback
try:
- from config import config
- config = config()
+ import config
debug = config.debug
except:
debug = False
import database
import string
from www.printbadnodes import cmpCategoryVal
-from config import config
-#print "policy"
-config = config()
+import config
DAT="./monitor.dat"
#!/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():
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",
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()
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,
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"
# 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"
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()
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",
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)
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,
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):
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
import inspect
import shutil
-from config import config as cfg
-config = cfg()
+import config
import monitorconfig
#!/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 = {}
* 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,
* 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.
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 ]
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:
<?php
-// PICKLE_PATH="/home/soltesz/research/planetlab/monitor3/pdb";
-define("PICKLE_PATH", "pdb");
+include 'monitorconfig.php';
+define("PICKLE_PATH", MONITOR_DATA_ROOTWEB);
class Pickle
{