X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=monitor%2Fwrapper%2Fplc.py;h=f44abefebed06010ac14a581640ea8bec02b5e13;hb=d37f2dbb7d89f898f2ad280472b1d71420b50612;hp=8f70c1f6c0bf654e9a8e0daa0dd3649d69f272b7;hpb=16b7bc48471b0695e72320fbcf761db695af032e;p=monitor.git diff --git a/monitor/wrapper/plc.py b/monitor/wrapper/plc.py index 8f70c1f..f44abef 100644 --- a/monitor/wrapper/plc.py +++ b/monitor/wrapper/plc.py @@ -14,6 +14,11 @@ import time import traceback from monitor import database +# note: this needs to be consistent with the value in PLEWWW/planetlab/includes/plc_functions.php +PENDING_CONSORTIUM_ID = 0 +# not used in monitor +#APPROVED_CONSORTIUM_ID = 999999 + try: from monitor import config debug = config.debug @@ -71,7 +76,7 @@ class PLC: try: return lambda *params : method(self.auth, *params) - except ProtocolError: + except xmlrpclib.ProtocolError: traceback.print_exc() global_error_count += 1 if global_error_count >= 10: @@ -84,7 +89,6 @@ class PLC: def __repr__(self): return self.api.__repr__() -api = PLC(auth.auth, auth.server) class CachedPLC(PLC): @@ -117,12 +121,12 @@ class CachedPLC(PLC): except: print "Call %s FAILED: Using old cached data" % cachename load_old_cache = True - + if load_old_cache: values = database.dbLoad(cachename) else: database.dbDump(cachename, values) - + return values else: values = database.dbLoad(cachename) @@ -132,6 +136,9 @@ class CachedPLC(PLC): return run_or_returncached +api = PLC(auth.auth, auth.server) +cacheapi = CachedPLC(auth.auth, auth.server) + def getAPI(url): return xmlrpclib.Server(url, verbose=False, allow_none=True) @@ -140,12 +147,22 @@ def getNodeAPI(session): nodeauth = Auth(session=session) return PLC(nodeauth.auth, auth.server) -def getAuthAPI(): - return PLC(auth.auth, auth.server) +def getAuthAPI(url=None): + if url: + return PLC(auth.auth, url) + else: + return PLC(auth.auth, auth.server) def getCachedAuthAPI(): return CachedPLC(auth.auth, auth.server) +def getSessionAPI(session, server): + nodeauth = Auth(session=session) + return PLC(nodeauth.auth, server) +def getUserAPI(username, password, server): + auth = Auth(username,password) + return PLC(auth.auth, server) + def getTechEmails(loginbase): """ For the given site, return all user email addresses that have the 'tech' role. @@ -312,6 +329,22 @@ def getNodes(filter=None, fields=None): #'last_updated', 'peer_node_id', 'ssh_rsa_key' ]) return nodes + +# Check if the site is a pending site that needs to be approved. +def isPendingSite(loginbase): + api = xmlrpclib.Server(auth.server, verbose=False) + try: + site = api.GetSites(auth.auth, loginbase)[0] + except Exception, exc: + login.info("ERROR: No site %s" % loginbase) + return False + + if not site['enabled'] and site['ext_consortium_id'] == PENDING_CONSORTIUM_ID: + return True + + return False + + ''' Sets boot state of a node. ''' @@ -388,6 +421,7 @@ def enableSiteSlices(loginbase): def enableSlices(nodename): api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True) + for slice in slices(siteId(nodename)): logger.info("Enabling slices %s" % slice) try: @@ -405,6 +439,7 @@ def enableSlices(nodename): logger.info("enableSlices: %s" % exc) print "exception: %s" % exc + #I'm commenting this because this really should be a manual process. #''' #Enable suspended site slices. @@ -416,6 +451,12 @@ def enableSlices(nodename): # api.SliceAttributeAdd(auth.auth, slice, "plc_slice_state", {"state" : "suspended"}) # def enableSiteSliceCreation(loginbase): + if isPendingSite(loginbase): + msg = "INFO: enableSiteSliceCreation: Pending Site (%s)" % loginbase + print msg + logger.info(msg) + return + api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True) try: logger.info("Enabling slice creation for site %s" % loginbase) @@ -430,10 +471,7 @@ def enableSliceCreation(nodename): api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True) try: loginbase = siteId(nodename) - logger.info("Enabling slice creation for site %s" % loginbase) - if not debug: - logger.info("\tcalling UpdateSite(%s, enabled=True)" % loginbase) - api.UpdateSite(auth.auth, loginbase, {'enabled': True}) + enableSiteSliceCreation(loginbase) except Exception, exc: print "ERROR: enableSliceCreation: %s" % exc logger.info("ERROR: enableSliceCreation: %s" % exc) @@ -441,13 +479,20 @@ def enableSliceCreation(nodename): ''' Removes site's ability to create slices. Returns previous max_slices ''' -def removeSiteSliceCreation(sitename): - print "removeSiteSliceCreation(%s)" % sitename +def removeSiteSliceCreation(loginbase): + print "removeSiteSliceCreation(%s)" % loginbase + + if isPendingSite(loginbase): + msg = "INFO: removeSiteSliceCreation: Pending Site (%s)" % loginbase + print msg + logger.info(msg) + return + api = xmlrpclib.Server(auth.server, verbose=False) try: - logger.info("Removing slice creation for site %s" % sitename) + logger.info("Removing slice creation for site %s" % loginbase) if not debug: - api.UpdateSite(auth.auth, sitename, {'enabled': False}) + api.UpdateSite(auth.auth, loginbase, {'enabled': False}) except Exception, exc: logger.info("removeSiteSliceCreation: %s" % exc) @@ -459,12 +504,7 @@ def removeSliceCreation(nodename): api = xmlrpclib.Server(auth.server, verbose=False) try: loginbase = siteId(nodename) - #numslices = api.GetSites(auth.auth, {"login_base": loginbase}, - # ["max_slices"])[0]['max_slices'] - logger.info("Removing slice creation for site %s" % loginbase) - if not debug: - #api.UpdateSite(auth.auth, loginbase, {'max_slices': 0}) - api.UpdateSite(auth.auth, loginbase, {'enabled': False}) + removeSiteSliceCreation(loginbase) except Exception, exc: logger.info("removeSliceCreation: %s" % exc)