X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=monitor%2Fwrapper%2Fplc.py;h=2ab180872d51df05a41e1e971efc074dce614198;hb=4d56ef5473c6486c321dd2797be45b45b0606dae;hp=2ddb06120ba02e2e5c8ba9325795dc875d6b6a8f;hpb=8e90984231a680415cc3f6a60f008b3029ad4548;p=monitor.git diff --git a/monitor/wrapper/plc.py b/monitor/wrapper/plc.py index 2ddb061..2ab1808 100644 --- a/monitor/wrapper/plc.py +++ b/monitor/wrapper/plc.py @@ -15,21 +15,24 @@ import traceback from monitor import database try: - import config + from monitor import config debug = config.debug except: debug = False logger = logging.getLogger("monitor") class Auth: - def __init__(self, username=None, password=None): - if username==None and password==None: - self.auth = {'AuthMethod': "anonymous"} + def __init__(self, username=None, password=None, **kwargs): + if 'session' in kwargs: + self.auth= { 'AuthMethod' : 'session', + 'session' : kwargs['session'] } else: - self.auth = {'Username' : username, - 'AuthMethod' : 'password', - 'AuthString' : password} - + if username==None and password==None: + self.auth = {'AuthMethod': "anonymous"} + else: + self.auth = {'Username' : username, + 'AuthMethod' : 'password', + 'AuthString' : password} # NOTE: this host is used by default when there are no auth files. XMLRPC_SERVER="https://boot.planet-lab.org/PLCAPI/" @@ -87,6 +90,11 @@ class CachedPLC(PLC): def run_or_returncached(*params): cachename = self._param_to_str(name, *params) #print "cachename is %s" % cachename + if hasattr(config, 'refresh'): + refresh = config.refresh + else: + refresh = False + if 'Get' in name: if not database.cachedRecently(cachename): load_old_cache = False @@ -114,6 +122,10 @@ class CachedPLC(PLC): def getAPI(url): return xmlrpclib.Server(url, verbose=False, allow_none=True) +def getNodeAPI(session): + nodeauth = Auth(session=session) + return PLC(nodeauth.auth, auth.server) + def getAuthAPI(): return PLC(auth.auth, auth.server) @@ -150,7 +162,7 @@ def getSliceUserEmails(loginbase): """ For the given site, return all user email addresses that have the 'tech' role. """ - #api = getAuthAPI() + api = getAuthAPI() # get site details. s = api.GetSites(loginbase)[0] # get people at site @@ -207,7 +219,10 @@ def getpcu(nodename): anon = {'AuthMethod': "anonymous"} nodeinfo = api.GetNodes(auth.auth, {"hostname": nodename}, ["pcu_ids", "ports"])[0] if nodeinfo['pcu_ids']: + print nodeinfo sitepcu = api.GetPCUs(auth.auth, nodeinfo['pcu_ids'])[0] + print sitepcu + print nodeinfo["ports"] sitepcu[nodename] = nodeinfo["ports"][0] return sitepcu else: