From 6d46ab9b534b60675a3dcb11fcb664589a3691f8 Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Fri, 15 Aug 2008 22:07:49 +0000 Subject: [PATCH] www/database.php add hack to conver monitor.conf into monitorconfig.php findbad.py use new util.file rather than old config.* nodebad.py added --site argument testapi.py accept site from cmd line. nodecommon.py added get_nodeset to consolidate the code for getting a set of nodes from cmd line. findbadpcu.py added --site argument database.py use package's version of PHPUnserialize and PHPSerialize. monitor-default.conf filled in usual default values. phpconfig.py load monitor.conf not old monitorconfig.py todo --- database.py | 4 ++-- findbad.py | 3 ++- findbadpcu.py | 20 ++++++++++++++++++-- monitor-default.conf | 7 +++---- nodebad.py | 9 +++++---- nodecommon.py | 35 ++++++++++++++++++++++++++++++++++- phpconfig.py | 8 ++++---- testapi.py | 2 +- todo | 20 +++++++++++++++----- www/database.php | 4 +++- 10 files changed, 87 insertions(+), 25 deletions(-) diff --git a/database.py b/database.py index 3b5bd65..1173d8a 100644 --- a/database.py +++ b/database.py @@ -3,8 +3,8 @@ import sys import pickle noserial=False try: - from PHPSerialize import * - from PHPUnserialize import * + from util.PHPSerialize import * + from util.PHPUnserialize import * except: #print >>sys.stderr, "PHPSerial db type not allowed." noserial=True diff --git a/findbad.py b/findbad.py index 7e45408..47459ad 100755 --- a/findbad.py +++ b/findbad.py @@ -5,6 +5,7 @@ import sys import string import time import config +import util.file # QUERY all nodes. @@ -342,7 +343,7 @@ def main(): cohash = cotop.coget(cotop_url) l_nodes = syncplcdb.create_plcdb() if config.nodelist: - f_nodes = config.getListFromFile(config.nodelist) + f_nodes = util.file.getListFromFile(config.nodelist) l_nodes = filter(lambda x: x['hostname'] in f_nodes, l_nodes) elif config.node: f_nodes = [config.node] diff --git a/findbadpcu.py b/findbadpcu.py index 55422a3..e3d160d 100755 --- a/findbadpcu.py +++ b/findbadpcu.py @@ -5,6 +5,9 @@ import sys import string import time import socket +import util.file +import plc +import sets import signal @@ -380,11 +383,20 @@ def main(): # update global round number to force refreshes across all nodes externalState['round'] += 1 - if config.nodelist == None and config.pcuid == None: + if config.site is not None: + api = plc.getAuthAPI() + site = api.GetSites(config.site) + l_nodes = api.GetNodes(site[0]['node_ids'], ['pcu_ids']) + pcus = [] + for node in l_nodes: + pcus += node['pcu_ids'] + l_pcus = [pcu for pcu in sets.Set(pcus)] + + elif 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.nodelist is not None: - l_pcus = config.getListFromFile(config.nodelist) + l_pcus = util.file.getListFromFile(config.nodelist) l_pcus = [int(pcu) for pcu in l_pcus] elif config.pcuid is not None: l_pcus = [ config.pcuid ] @@ -409,14 +421,18 @@ if __name__ == '__main__': parser.set_defaults(nodelist=None, increment=False, pcuid=None, + site=None, dbname="findbadpcus", cachenodes=False, refresh=False, ) parser.add_option("-f", "--nodelist", dest="nodelist", metavar="FILE", help="Provide the input file for the node list") + parser.add_option("", "--site", dest="site", metavar="FILE", + help="Get all pcus associated with the given site's nodes") parser.add_option("", "--pcuid", dest="pcuid", metavar="id", help="Provide the id for a single pcu") + parser.add_option("", "--cachenodes", action="store_true", help="Cache node lookup from PLC") parser.add_option("", "--dbname", dest="dbname", metavar="FILE", diff --git a/monitor-default.conf b/monitor-default.conf index d8d1e40..bf01c52 100644 --- a/monitor-default.conf +++ b/monitor-default.conf @@ -18,10 +18,9 @@ API_AUTH_PASSWORD= # SERVER PATHS MONITOR_HOSTNAME=monitor.planet-lab.org -MONITOR_SCRIPT_ROOT= -MONITOR_DATA_ROOT= -MONITOR_DATA_ROOTWEB=/var/www/cgi-bin/pdb -MONITOR_ARCHIVE_ROOT= +MONITOR_SCRIPT_ROOT=/usr/share/monitor-server +MONITOR_DATA_ROOT=/var/lib/monitor-server +MONITOR_ARCHIVE_ROOT=/usr/share/monitor-server/archive-pdb [commandline] debug=0 diff --git a/nodebad.py b/nodebad.py index 8aacf71..0130c3e 100755 --- a/nodebad.py +++ b/nodebad.py @@ -32,10 +32,11 @@ def main(config): l_nodes = syncplcdb.create_plcdb() l_plcnodes = database.dbLoad("l_plcnodes") - if config.node: - l_nodes = [config.node] - else: - l_nodes = [node['hostname'] for node in l_plcnodes] + l_nodes = get_nodeset(config) + #if config.node: + # l_nodes = [config.node] + ##else: + # l_nodes = [node['hostname'] for node in l_plcnodes] checkAndRecordState(l_nodes, l_plcnodes) diff --git a/nodecommon.py b/nodecommon.py index cef1247..ba67625 100644 --- a/nodecommon.py +++ b/nodecommon.py @@ -2,6 +2,8 @@ import struct import reboot import time +import util.file +import plc from monitor import database from unified_model import PersistFlags esc = struct.pack('i', 27) @@ -37,7 +39,6 @@ def get_current_state(fbnode): return l def color_pcu_state(fbnode): - import plc if 'plcnode' in fbnode and 'pcu_ids' in fbnode['plcnode'] and len(fbnode['plcnode']['pcu_ids']) > 0 : values = reboot.get_pcu_values(fbnode['plcnode']['pcu_ids'][0]) @@ -151,3 +152,35 @@ def datetime_fromstr(str): tup = time.strptime(str, "%m/%d/%Y") ret = datetime.fromtimestamp(time.mktime(tup)) return ret + +def get_nodeset(config): + """ + Given the config values passed in, return the set of hostnames that it + evaluates to. + """ + api = plc.getAuthAPI() + l_nodes = database.dbLoad("l_plcnodes") + + if config.nodelist: + f_nodes = util.file.getListFromFile(config.nodelist) + l_nodes = filter(lambda x: x['hostname'] in f_nodes, l_nodes) + elif config.node: + f_nodes = [config.node] + l_nodes = filter(lambda x: x['hostname'] in f_nodes, l_nodes) + elif config.nodegroup: + ng = api.GetNodeGroups({'name' : config.nodegroup}) + l_nodes = api.GetNodes(ng[0]['node_ids'], ['hostname']) + elif config.site: + site = api.GetSites(config.site) + l_nodes = api.GetNodes(site[0]['node_ids'], ['hostname']) + + l_nodes = [node['hostname'] for node in l_nodes] + + # perform this query after the above options, so that the filter above + # does not break. + if config.nodeselect: + fb = database.dbLoad("findbad") + l_nodes = node_select(config.nodeselect, fb['nodes'].keys(), fb) + + return l_nodes + diff --git a/phpconfig.py b/phpconfig.py index 663bcc3..2848c75 100755 --- a/phpconfig.py +++ b/phpconfig.py @@ -1,10 +1,10 @@ #!/usr/bin/python -import monitorconfig +import config print "" diff --git a/testapi.py b/testapi.py index fa81fd5..5e7daa8 100755 --- a/testapi.py +++ b/testapi.py @@ -5,7 +5,7 @@ import sys import traceback api = plc.getAuthAPI() -loginbase = "princeton" +loginbase = sys.argv[1] # "princeton" try: site = api.GetSites(loginbase)[0] diff --git a/todo b/todo index 94b2ab4..d7370ef 100644 --- a/todo +++ b/todo @@ -4,15 +4,22 @@ TODO: * had to mount -t devpts devpts /dev/pts to get ssh to work inside the chroot. also, disable the pam modules in /etc/pam.d/sshd + * auto configuration for php configuration. + maybe run translation of monitor.conf before loading monitorconfig.php? + * A setup script of some kind would be nice that walked through : - writing monitorconfig.py - creation of monitorconfig.php - run syncplcdb.py - testapi.py - findbad.py on sample site. + - nodebad.py + - nodequery.py + - nodegroups.py + - findbadpcus.py - loads webpage for those retreived values to confirm setup succeeded. - * reimplement the config.py / .config mechanism. i'd like for many commands + * 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. @@ -28,11 +35,9 @@ TODO: - python supports load-once modules, so subsequent imports refer to the same module object. + * have package pull in threadpool from easy_install - * 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, - they should sit in a location that is accessible from the www scripts, - backend scripts, and user utilities. + * place PKL files in a real database * clean up plc.py; there's a lot of redundent code. @@ -49,6 +54,7 @@ TODO: configuration, policy, data model, + data access, object interfaces. Lower priority: @@ -61,6 +67,10 @@ Lower priority: availble with PLC. Done: + * 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, + they should sit in a location that is accessible from the www scripts, + backend scripts, and user utilities. * nodebad loads plc_hn2lb unconditionally * nodeinfo loads act_all unconditionally * change findbad.py default db name diff --git a/www/database.php b/www/database.php index 070be1f..ce12c8e 100644 --- a/www/database.php +++ b/www/database.php @@ -1,8 +1,10 @@ /var/www/cgi-bin/monitor/monitorconfig.php"); include 'monitorconfig.php'; -define("PICKLE_PATH", MONITOR_DATA_ROOTWEB); +define("PICKLE_PATH", MONITOR_DATA_ROOT); class Pickle { -- 2.43.0