X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=monitor%2Fwrapper%2Fplc.py;h=8113c57579dabe9a8cc4593625194fbc679fc3b9;hb=db2f841a5e31ce2d95919fee68e729813c600e26;hp=87355faf9c3a37422f9b83fe9b99f66076f34c36;hpb=8868d29303a545901cce2edfa9d69b586421c61f;p=monitor.git diff --git a/monitor/wrapper/plc.py b/monitor/wrapper/plc.py index 87355fa..8113c57 100644 --- a/monitor/wrapper/plc.py +++ b/monitor/wrapper/plc.py @@ -12,7 +12,7 @@ import xml, xmlrpclib import logging import time import traceback -from monitor import database +from datetime import datetime # note: this needs to be consistent with the value in PLEWWW/planetlab/includes/plc_functions.php PENDING_CONSORTIUM_ID = 0 @@ -90,54 +90,7 @@ class PLC: return self.api.__repr__() -class CachedPLC(PLC): - - def _param_to_str(self, name, *params): - fields = len(params) - retstr = "" - retstr += "%s-" % name - for x in params: - retstr += "%s-" % x - return retstr[:-1] - - def __getattr__(self, name): - method = getattr(self.api, name) - if method is None: - raise AssertionError("method does not exist") - - 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 - try: - values = method(self.auth, *params) - 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) - return values - else: - return method(self.auth, *params) - - return run_or_returncached - api = PLC(auth.auth, auth.server) -cacheapi = CachedPLC(auth.auth, auth.server) def getAPI(url): @@ -173,7 +126,11 @@ def getTechEmails(loginbase): # get people at site p = api.GetPersons(s['person_ids']) # pull out those with the right role. - emails = [ person['email'] for person in filter(lambda x: 'tech' in x['roles'], p) ] + emails = [] + for person in filter(lambda x: 'tech' in x['roles'], p): + if not isPersonExempt(person['email']): + emails.append(person['email']) + #emails = [ person['email'] for person in filter(lambda x: 'tech' in x['roles'], p) ] return emails def getPIEmails(loginbase): @@ -186,7 +143,11 @@ def getPIEmails(loginbase): # get people at site p = api.GetPersons(s['person_ids']) # pull out those with the right role. - emails = [ person['email'] for person in filter(lambda x: 'pi' in x['roles'], p) ] + #emails = [ person['email'] for person in filter(lambda x: 'pi' in x['roles'], p) ] + emails = [] + for person in filter(lambda x: 'pi' in x['roles'], p): + if not isPersonExempt(person['email']): + emails.append(person['email']) return emails def getSliceUserEmails(loginbase): @@ -202,7 +163,13 @@ def getSliceUserEmails(loginbase): for slice in slices: people += api.GetPersons(slice['person_ids']) # pull out those with the right role. - emails = [ person['email'] for person in filter(lambda x: 'pi' in x['roles'], people) ] + #emails = [ person['email'] for person in filter(lambda x: 'pi' in x['roles'], people) ] + + emails = [] + for person in people: + if not isPersonExempt(person['email']): + emails.append(person['email']) + unique_emails = [ x for x in set(emails) ] return unique_emails @@ -340,7 +307,7 @@ def isPendingSite(loginbase): try: site = api.GetSites(auth.auth, loginbase)[0] except Exception, exc: - login.info("ERROR: No site %s" % loginbase) + logger.info("ERROR: No site %s" % loginbase) return False if not site['enabled'] and site['ext_consortium_id'] == PENDING_CONSORTIUM_ID: @@ -393,7 +360,8 @@ def suspendSiteSlices(loginbase): logger.info("Suspending slice %s" % slice) try: if not debug: - api.AddSliceAttribute(auth.auth, slice, "enabled", "0") + if not isSliceExempt(slice): + api.AddSliceAttribute(auth.auth, slice, "enabled", "0") except Exception, exc: logger.info("suspendSlices: %s" % exc) @@ -468,11 +436,36 @@ def enableSliceCreation(nodename): loginbase = siteId(nodename) enableSiteSliceCreation(loginbase) +def isTagCurrent(tags): + if len(tags) > 0: + for tag in tags: + until = tag['value'] + if datetime.strptime(until, "%Y%m%d") > datetime.now(): + # NOTE: the 'exempt_until' time is beyond current time + return True + return False + +def isPersonExempt(email): + tags = api.GetPersonTags({'email' : email, 'tagname' : 'exempt_person_until'}) + return isTagCurrent(tags) + +def isNodeExempt(hostname): + tags = api.GetNodeTags({'hostname' : hostname, 'tagname' : 'exempt_node_until'}) + return isTagCurrent(tags) + +def isSliceExempt(slicename): + tags = api.GetSliceTags({'name' : slicename, 'tagname' : 'exempt_slice_until'}) + return isTagCurrent(tags) + +def isSiteExempt(loginbase): + tags = api.GetSiteTags({'login_base' : loginbase, 'tagname' : 'exempt_site_until'}) + return isTagCurrent(tags) + ''' Removes site's ability to create slices. Returns previous max_slices ''' def removeSiteSliceCreation(loginbase): - print "removeSiteSliceCreation(%s)" % loginbase + #print "removeSiteSliceCreation(%s)" % loginbase if isPendingSite(loginbase): msg = "INFO: removeSiteSliceCreation: Pending Site (%s)" % loginbase @@ -484,7 +477,8 @@ def removeSiteSliceCreation(loginbase): try: logger.info("Removing slice creation for site %s" % loginbase) if not debug: - api.UpdateSite(auth.auth, loginbase, {'enabled': False}) + if not isSiteExempt(loginbase): + api.UpdateSite(auth.auth, loginbase, {'enabled': False}) except Exception, exc: logger.info("removeSiteSliceCreation: %s" % exc)