www/database.php
authorStephen Soltesz <soltesz@cs.princeton.edu>
Fri, 15 Aug 2008 22:07:49 +0000 (22:07 +0000)
committerStephen Soltesz <soltesz@cs.princeton.edu>
Fri, 15 Aug 2008 22:07:49 +0000 (22:07 +0000)
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
findbad.py
findbadpcu.py
monitor-default.conf
nodebad.py
nodecommon.py
phpconfig.py
testapi.py
todo
www/database.php

index 3b5bd65..1173d8a 100644 (file)
@@ -3,8 +3,8 @@ import sys
 import pickle
 noserial=False
 try:
 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
 except:
        #print >>sys.stderr, "PHPSerial db type not allowed."
        noserial=True
index 7e45408..47459ad 100755 (executable)
@@ -5,6 +5,7 @@ import sys
 import string
 import time
 import config
 import string
 import time
 import config
+import util.file
 
 
 # QUERY all nodes.
 
 
 # QUERY all nodes.
@@ -342,7 +343,7 @@ def main():
        cohash = cotop.coget(cotop_url)
        l_nodes = syncplcdb.create_plcdb()
        if config.nodelist:
        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]
                l_nodes = filter(lambda x: x['hostname'] in f_nodes, l_nodes)
        elif config.node:
                f_nodes = [config.node]
index 55422a3..e3d160d 100755 (executable)
@@ -5,6 +5,9 @@ import sys
 import string
 import time
 import socket
 import string
 import time
 import socket
+import util.file
+import plc
+import sets
 
     
 import signal
 
     
 import signal
@@ -380,11 +383,20 @@ def main():
                # update global round number to force refreshes across all nodes
                externalState['round'] += 1
 
                # 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:
                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 ] 
                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,
        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")
                                                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("", "--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", 
        parser.add_option("", "--cachenodes", action="store_true",
                                                help="Cache node lookup from PLC")
        parser.add_option("", "--dbname", dest="dbname", metavar="FILE", 
index d8d1e40..bf01c52 100644 (file)
@@ -18,10 +18,9 @@ API_AUTH_PASSWORD=
 
 # SERVER PATHS
 MONITOR_HOSTNAME=monitor.planet-lab.org
 
 # 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
 
 [commandline]
 debug=0
index 8aacf71..0130c3e 100755 (executable)
@@ -32,10 +32,11 @@ def main(config):
        l_nodes = syncplcdb.create_plcdb()
        l_plcnodes = database.dbLoad("l_plcnodes")
 
        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)
 
        
        checkAndRecordState(l_nodes, l_plcnodes)
 
index cef1247..ba67625 100644 (file)
@@ -2,6 +2,8 @@
 import struct
 import reboot
 import time
 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)
 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):
        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])
 
        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
                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
+       
index 663bcc3..2848c75 100755 (executable)
@@ -1,10 +1,10 @@
 #!/usr/bin/python
 
 #!/usr/bin/python
 
-import monitorconfig
+import config
 
 print "<?php"
 
 print "<?php"
-for attr in dir(monitorconfig):
-       val = monitorconfig.__getattribute__(attr)
-       if attr[0].isupper():
+for attr in dir(config):
+       val = config.__getattribute__(attr)
+       if attr[0].isupper() and attr[1].isupper():
                print "define('%s', '%s'); " % (attr, val)
 print "?>"
                print "define('%s', '%s'); " % (attr, val)
 print "?>"
index fa81fd5..5e7daa8 100755 (executable)
@@ -5,7 +5,7 @@ import sys
 import traceback
 
 api = plc.getAuthAPI()
 import traceback
 
 api = plc.getAuthAPI()
-loginbase = "princeton"
+loginbase = sys.argv[1] # "princeton"
 
 try:
        site = api.GetSites(loginbase)[0]
 
 try:
        site = api.GetSites(loginbase)[0]
diff --git a/todo b/todo
index 94b2ab4..d7370ef 100644 (file)
--- 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
 
        * 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.
  * 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.
 
        - 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.
     
    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.
           
      - 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.
 
 
  * clean up plc.py; there's a lot of redundent code.
 
@@ -49,6 +54,7 @@ TODO:
                configuration, 
                policy, 
                data model, 
                configuration, 
                policy, 
                data model, 
+               data access,
                object interfaces.
 
 Lower priority:
                object interfaces.
 
 Lower priority:
@@ -61,6 +67,10 @@ Lower priority:
    availble with PLC.
 
 Done:
    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
  * nodebad loads plc_hn2lb unconditionally
  * nodeinfo loads act_all unconditionally
  * change findbad.py default db name
index 070be1f..ce12c8e 100644 (file)
@@ -1,8 +1,10 @@
 
 <?php 
 
 
 <?php 
 
+# TODO: clean up this aweful hack.
+system("/usr/share/monitor-server/phpconfig.py > /var/www/cgi-bin/monitor/monitorconfig.php");
 include 'monitorconfig.php';
 include 'monitorconfig.php';
-define("PICKLE_PATH", MONITOR_DATA_ROOTWEB);
+define("PICKLE_PATH", MONITOR_DATA_ROOT);
 
 class Pickle
 {
 
 class Pickle
 {