Changed 'import auth' statements to use plc.py or monitorconfig.py
authorStephen Soltesz <soltesz@cs.princeton.edu>
Mon, 4 Aug 2008 16:18:20 +0000 (16:18 +0000)
committerStephen Soltesz <soltesz@cs.princeton.edu>
Mon, 4 Aug 2008 16:18:20 +0000 (16:18 +0000)
21 files changed:
bootman.py
findbad.py
getconf.py
grouprins.py
monitor.py
nodeaction.py
nodebad.py
nodeconfig.py
nodegroups.py
nodehistory.py
nodeinfo.py
nodenetwork.py
nodequery.py
pcubad.py
plc.py
prep_power_users.py
showlatlon.py
sitebad.py
siteinfo.py
todo
unified_model.py

index 0a75fac..c3116bc 100755 (executable)
@@ -3,8 +3,7 @@
 # Attempt to reboot a node in debug state.
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 import sys
 import os
index 7efa52c..2b8fe00 100755 (executable)
@@ -29,8 +29,7 @@ import syncplcdb
 from nodequery import verify,query_to_dict,node_select
 import traceback
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 def collectPingAndSSH(nodename, cohash):
        ### RUN PING ######################
index 155c26f..56cf1b8 100755 (executable)
@@ -1,12 +1,11 @@
 #!/usr/bin/python
 
-import auth
 import plc
+api = plc.getAuthAPI()
 import sys
 import os
 
 def getconf(hostname, force=False, media=None):
-       api = plc.PLC(auth.auth, auth.plc)
        n = api.GetNodes(hostname)
        filename = "bootcd/" + hostname + ".txt"
        if not os.path.exists(filename) or force:
index 14be85f..ffb4f85 100755 (executable)
@@ -13,8 +13,7 @@
 # 
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 import policy
 import traceback
index b9e3ece..48fa514 100644 (file)
@@ -13,8 +13,7 @@ import rt
 import sys
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 from clean_policy import *
 
index 00d2810..62095d1 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/python
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 import reboot
 
index 96720fb..c274f49 100755 (executable)
@@ -13,8 +13,7 @@ import syncplcdb
 from nodequery import verify,query_to_dict,node_select
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 from unified_model import *
 from monitor_policy import MINUP
 
index fa4a3eb..d8a8c12 100755 (executable)
@@ -2,8 +2,7 @@
 
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 from optparse import OptionParser
 from sets import Set
index 207efae..be4ed6f 100755 (executable)
@@ -14,8 +14,7 @@
 #  * 
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 from optparse import OptionParser
 from sets import Set
index d09f01f..520037c 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/python
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 import database
 import reboot
index 23afab9..f50f846 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/python
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 import database
 import reboot
index bf80e00..ec8d869 100755 (executable)
@@ -2,8 +2,7 @@
 
 import sys
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 import config
 
 if len(sys.argv[1:]) > 0:
index 3ee4236..a982e20 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/python
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 import sys
 import database
index 5b71845..fbcdb17 100755 (executable)
--- a/pcubad.py
+++ b/pcubad.py
@@ -14,8 +14,7 @@ import syncplcdb
 from nodequery import verify,query_to_dict,node_select
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 from unified_model import *
 from monitor_policy import MINUP
 
diff --git a/plc.py b/plc.py
index 0506ad5..0970eaa 100644 (file)
--- a/plc.py
+++ b/plc.py
 
 import xml, xmlrpclib
 import logging
-try:
-    import auth
-except:
-       class Anon:
-               def __init__(self):
-                       self.auth = {'AuthMethod': "anonymous"}
-       auth = Anon()
-
 import time
+import traceback
 try:
        from config import config
        config = config()
        debug = config.debug
 except:
        debug = False
+logger = logging.getLogger("monitor")
        
-XMLRPC_SERVER="https://boot.planet-lab.org/PLCAPI/"
+class Auth:
+       def __init__(self):
+               self.auth = {'AuthMethod': "anonymous"}
 
-logger = logging.getLogger("monitor")
+# NOTE: this host is used by default when there are no auth files.
+XMLRPC_SERVER="https://boot.planet-lab.org/PLCAPI/"
 
-api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False, allow_none=True)
+# NOTE: by default, use anonymous access, but if auth files are 
+#       configured, use them, with their auth definitions.
+auth = Auth()
+try:
+       import monitorconfig
+       auth.auth = monitorconfig.API_AUTH
+       auth.server = monitorconfig.API_SERVER
+except:
+       try:
+               import auth
+               auth.server = auth.plc
+       except:
+               auth.server = XMLRPC_SERVER
 
-def getAPI(url):
-       api = xmlrpclib.Server(url, verbose=False, allow_none=True)
-       return api
+api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
 
 class PLC:
        def __init__(self, auth, url):
@@ -52,8 +59,10 @@ class PLC:
        def __repr__(self):
                return self.api.__repr__()
 
+def getAPI(url):
+       return xmlrpclib.Server(url, verbose=False, allow_none=True)
+
 def getAuthAPI():
-       import monitorconfig
        return PLC(monitorconfig.API_AUTH, monitorconfig.API_SERVER)
 
 '''
@@ -61,7 +70,7 @@ Returns list of nodes in dbg as reported by PLC
 '''
 def nodesDbg():
        dbgNodes = []
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+       api = xmlrpclib.Server(auth.server, verbose=False)
        anon = {'AuthMethod': "anonymous"}
        for node in api.GetNodes(anon, {"boot_state":"dbg"},["hostname"]):
                dbgNodes.append(node['hostname'])
@@ -73,7 +82,7 @@ def nodesDbg():
 Returns loginbase for given nodename
 '''
 def siteId(nodename):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+       api = xmlrpclib.Server(auth.server, verbose=False)
        anon = {'AuthMethod': "anonymous"}
        site_id = api.GetNodes (anon, {"hostname": nodename}, ['site_id'])
        if len(site_id) == 1:
@@ -85,7 +94,7 @@ Returns list of slices for a site.
 '''
 def slices(loginbase):
        siteslices = []
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+       api = xmlrpclib.Server(auth.server, verbose=False)
        sliceids = api.GetSites (auth.auth, {"login_base" : loginbase}, ["slice_ids"])[0]['slice_ids']
        for slice in api.GetSlices(auth.auth, {"slice_id" : sliceids}, ["name"]):
                siteslices.append(slice['name'])
@@ -95,7 +104,7 @@ def slices(loginbase):
 Returns dict of PCU info of a given node.
 '''
 def getpcu(nodename):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+       api = xmlrpclib.Server(auth.server, verbose=False)
        anon = {'AuthMethod': "anonymous"}
        nodeinfo = api.GetNodes(auth.auth, {"hostname": nodename}, ["pcu_ids", "ports"])[0]
        if nodeinfo['pcu_ids']:
@@ -107,7 +116,7 @@ def getpcu(nodename):
                return False
 
 def GetPCUs(filter=None, fields=None):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False, allow_none=True)
+       api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
        pcu_list = api.GetPCUs(auth.auth, filter, fields)
        return pcu_list 
 
@@ -115,7 +124,7 @@ def GetPCUs(filter=None, fields=None):
 Returns all site nodes for site id (loginbase).
 '''
 def getSiteNodes(loginbase, fields=None):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+       api = xmlrpclib.Server(auth.server, verbose=False)
        nodelist = []
        anon = {'AuthMethod': "anonymous"}
        try:
@@ -128,7 +137,7 @@ def getSiteNodes(loginbase, fields=None):
        return nodelist
 
 def getPersons(filter=None, fields=None):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False, allow_none=True)
+       api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
        persons = []
        try:
                persons = api.GetPersons(auth.auth, filter, fields)
@@ -138,21 +147,20 @@ def getPersons(filter=None, fields=None):
        return persons
 
 def getSites(filter=None, fields=None):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False, allow_none=True)
+       api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
        sites = []
        anon = {'AuthMethod': "anonymous"}
        try:
                #sites = api.GetSites(anon, filter, fields)
                sites = api.GetSites(auth.auth, filter, fields)
        except Exception, exc:
-               import traceback
                traceback.print_exc()
                print "getSites:  %s" % exc
                logger.info("getSites:  %s" % exc)
        return sites
 
 def getSiteNodes2(loginbase):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+       api = xmlrpclib.Server(auth.server, verbose=False)
        nodelist = []
        anon = {'AuthMethod': "anonymous"}
        try:
@@ -163,12 +171,12 @@ def getSiteNodes2(loginbase):
        return nodelist
 
 def getNodeNetworks(filter=None):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False, allow_none=True)
+       api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
        nodenetworks = api.GetNodeNetworks(auth.auth, filter, None)
        return nodenetworks
 
 def getNodes(filter=None, fields=None):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False, allow_none=True)
+       api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
        nodes = api.GetNodes(auth.auth, filter, fields) 
                        #['boot_state', 'hostname', 
                        #'site_id', 'date_created', 'node_id', 'version', 'nodenetwork_ids',
@@ -179,14 +187,14 @@ def getNodes(filter=None, fields=None):
 Sets boot state of a node.
 '''
 def nodeBootState(nodename, state):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+       api = xmlrpclib.Server(auth.server, verbose=False)
        try:
                return api.UpdateNode(auth.auth, nodename, {'boot_state': state})
        except Exception, exc:
                logger.info("nodeBootState:  %s" % exc)
 
 def updateNodeKey(nodename, key):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+       api = xmlrpclib.Server(auth.server, verbose=False)
        try:
                return api.UpdateNode(auth.auth, nodename, {'key': key})
        except Exception, exc:
@@ -196,7 +204,7 @@ def updateNodeKey(nodename, key):
 Sends Ping Of Death to node.
 '''
 def nodePOD(nodename):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+       api = xmlrpclib.Server(auth.server, verbose=False)
        logger.info("Sending POD to %s" % nodename)
        try:
                if not debug:
@@ -208,7 +216,7 @@ def nodePOD(nodename):
 Freeze all site slices.
 '''
 def suspendSlices(nodename):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+       api = xmlrpclib.Server(auth.server, verbose=False)
        for slice in slices(siteId(nodename)):
                logger.info("Suspending slice %s" % slice)
                try:
@@ -218,7 +226,7 @@ def suspendSlices(nodename):
                        logger.info("suspendSlices:  %s" % exc)
 
 def enableSlices(nodename):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False, allow_none=True)
+       api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
        for slice in slices(siteId(nodename)):
                logger.info("Enabling slices %s" % slice)
                try:
@@ -241,13 +249,13 @@ def enableSlices(nodename):
 #Enable suspended site slices.
 #'''
 #def enableSlices(nodename, slicelist):
-#      api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+#      api = xmlrpclib.Server(auth.server, verbose=False)
 #      for slice in  slices(siteId(nodename)):
 #              logger.info("Suspending slice %s" % slice)
 #              api.SliceAttributeAdd(auth.auth, slice, "plc_slice_state", {"state" : "suspended"})
 #
 def enableSliceCreation(nodename):
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False, allow_none=True)
+       api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
        try:
                loginbase = siteId(nodename)
                logger.info("Enabling slice creation for site %s" % loginbase)
@@ -263,7 +271,7 @@ Removes ability to create slices. Returns previous max_slices
 '''
 def removeSliceCreation(nodename):
        print "removeSliceCreation(%s)" % nodename
-       api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+       api = xmlrpclib.Server(auth.server, verbose=False)
        try:
                loginbase = siteId(nodename)
                #numslices = api.GetSites(auth.auth, {"login_base": loginbase}, 
@@ -279,7 +287,7 @@ def removeSliceCreation(nodename):
 QED
 '''
 #def enableSliceCreation(nodename, maxslices):
-#      api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
+#      api = xmlrpclib.Server(auth.server, verbose=False)
 #      anon = {'AuthMethod': "anonymous"}
 #      siteid = api.AnonAdmQuerySite (anon, {"node_hostname": nodename})
 #      if len(siteid) == 1:
@@ -313,5 +321,4 @@ def main():
        #print slices("princeton")
 
 if __name__=="__main__":
-       import reboot
        main() 
index 3f354c0..8566a6d 100755 (executable)
@@ -1,7 +1,6 @@
 #!/usr/bin/python
 
 import plc
-import auth
 import sys
 import time
 
@@ -16,8 +15,9 @@ email_list = [ 'monitor@planet-lab.org',
                 # 'vivek@cs.princeton.edu',
                ]
 
-api   = plc.PLC(auth.auth, auth.plc)
-api06 = plc.PLC(auth.auth06, auth.plc06)
+import monitorconfig
+api   = plc.PLC(monitorconfig.API_AUTH, monitorconfig.API_SERVER)
+api06 = plc.PLC(monitorconfig.API_AUTH06, monitorconfig.API_SERVER06)
 
 
 # add planetlab-15.cs.princeton.edu, and use the key on the CD.
index fbed374..10367e4 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/python
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 import sys
 import reboot
index c9e0033..6b12ef3 100755 (executable)
@@ -13,8 +13,7 @@ import syncplcdb
 from nodequery import verify,query_to_dict,node_select
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 from unified_model import *
 from monitor_policy import MINUP
 
index d248b99..f3692bc 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/python
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 import database
 import reboot
diff --git a/todo b/todo
index 066e683..cedd0aa 100644 (file)
--- a/todo
+++ b/todo
@@ -4,25 +4,27 @@ TODO:
    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.
 
- * Find a better location to place and pull the PLK files currently in the pdb
+ * 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.
 
- * pull out global configuration information from various files, like rt_db,
-   mailer.py,  auth.py, and any others.  Create a single configuration file
-   from which all others pull.
-
-   - convert plc and other files to use the new monitorconfig.py rather than
-     auth, or plc.*
-   - need to alter all import 'auth' statements.
+ * clean up plc.py; there's a lot of redundent code.
 
 Lower priority:
  * Add a more structured, 'automate' library of scripts and means of making
    batch calls, etc.
 
  * add a third package for user tools that will interact with the Monitor
-   service.  Mostly, I'm guessing this would be queries for the live status
+   service.  Mostly, I'm guessing this would be queries for the live status of
    nodes and a more reliable 'reboot' and 'reinstall' mechanism than currently
    availble with PLC.
 
+Done:
+ * pull out global configuration information from various files, like rt_db,
+   mailer.py,  auth.py, and any others.  Create a single configuration file
+   from which all others pull.
+
+   - convert plc and other files to use the new monitorconfig.py rather than
+     auth, or plc.*
+   - need to alter all import 'auth' statements.
index 602c902..01c99a2 100755 (executable)
@@ -3,8 +3,7 @@
 import database
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 import mailer
 import time