+
+class Auth:
+ def __init__(self):
+ self.auth = {'AuthMethod': "anonymous"}
+
+# NOTE: this host is used by default when there are no auth files.
+XMLRPC_SERVER="https://boot.planet-lab.org/PLCAPI/"
+
+# NOTE: by default, use anonymous access, but if auth files are
+# configured, use them, with their auth definitions.
+auth = Auth()
+try:
+ from monitor import config
+ auth.auth = {'Username' : config.API_AUTH_USER,
+ 'AuthMethod' : 'password',
+ 'AuthString' : config.API_AUTH_PASSWORD}
+ auth.server = config.API_SERVER
+except:
+ try:
+ import auth
+ auth.server = auth.plc
+ except:
+ auth = Auth()
+ auth.server = XMLRPC_SERVER
+
+api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
+
+class PLC:
+ def __init__(self, auth, url):
+ self.auth = auth
+ self.url = url
+ self.api = xmlrpclib.Server(self.url, verbose=False, allow_none=True)
+
+ def __getattr__(self, name):
+ method = getattr(self.api, name)
+ if method is None:
+ raise AssertionError("method does not exist")
+
+ return lambda *params : method(self.auth, *params)
+
+ def __repr__(self):
+ return self.api.__repr__()
+
+def getAPI(url):
+ return xmlrpclib.Server(url, verbose=False, allow_none=True)
+
+def getAuthAPI():
+ return PLC(auth.auth, auth.server)
+
+
+def getTechEmails(loginbase):
+ """
+ For the given site, return all user email addresses that have the 'tech' role.
+ """
+ api = getAuthAPI()
+ # get site details.
+ s = api.GetSites(loginbase)[0]
+ # 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) ]
+ return emails
+
+def getPIEmails(loginbase):
+ """
+ For the given site, return all user email addresses that have the 'tech' role.
+ """
+ api = getAuthAPI()
+ # get site details.
+ s = api.GetSites(loginbase)[0]
+ # 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) ]
+ return emails
+
+def getSliceUserEmails(loginbase):
+ """
+ For the given site, return all user email addresses that have the 'tech' role.
+ """
+ #api = getAuthAPI()
+ # get site details.
+ s = api.GetSites(loginbase)[0]
+ # get people at site
+ slices = api.GetSlices(s['slice_ids'])
+ people = []
+ 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) ]
+ unique_emails = [ x for x in set(emails) ]
+ return unique_emails
+
+'''
+Returns list of nodes in dbg as reported by PLC
+'''
+def nodesDbg():