+
+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__()