From c281851e75ef61c324124d27fc793e3473d0160e Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Fri, 3 Oct 2008 00:35:23 +0000 Subject: [PATCH] check in missing files --- util/remoteshell.py | 105 ++++++++++++++++++++++++++++++++++++++++++++ util/report.py | 5 +++ util/trustedroot.py | 33 ++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 util/remoteshell.py create mode 100644 util/report.py create mode 100644 util/trustedroot.py diff --git a/util/remoteshell.py b/util/remoteshell.py new file mode 100644 index 00000000..88f101cd --- /dev/null +++ b/util/remoteshell.py @@ -0,0 +1,105 @@ +# remoteshell.py +# +# interface to the PLC api via xmlrpc +# +# RemoteShell() exports an API that looks identical to that exported by +# PLC.Shell.Shell(). It's meant to be a drop in replacement for running +# geniwrapper on a different machine than PLC. + +import xmlrpclib + +class RemoteShell: + def __init__(self): + self.servers = {} + + def get_default_opts(self): + dict = {} + dict['Role'] = "user" + dict['Url'] = "https://www.planet-lab.org:443/PLCAPI/" + return dict + + def call(self, name, pl_auth, *args): + auth_opts = self.get_default_opts().copy() + auth_opts.update(pl_auth) + + url = auth_opts["Url"] + key = url + "#" + auth_opts["Username"] + + if not (key in self.servers): + server = xmlrpclib.Server(url, verbose = 0, allow_none=True) + server.AdmAuthCheck(auth_opts) + self.servers[key] = server + + server = self.servers[key] + + arglist = ["auth_opts"] + for arg in args: + arglist.append(repr(arg)) + + result = eval("server." + name + "(" + ",".join(arglist) + ")") + + return result + + # TODO: there's probably an automatic way to import all these stubs + + def AddInitScript(self, pl_auth, *args): + return self.call("AddInitScript", pl_auth, *args) + + def AddNode(self, pl_auth, *args): + return self.call("AddNode", pl_auth, *args) + + def AddPerson(self, pl_auth, *args): + return self.call("AddPerson", pl_auth, *args) + + def AddSite(self, pl_auth, *args): + return self.call("AddSite", pl_auth, *args) + + def AddSlice(self, pl_auth, *args): + return self.call("AddSlice", pl_auth, *args) + + def DeleteNode(self, pl_auth, *args): + return self.call("DeleteNode", pl_auth, *args) + + def DeletePerson(self, pl_auth, *args): + return self.call("DeletePerson", pl_auth, *args) + + def DeleteSite(self, pl_auth, *args): + return self.call("DeleteSite", pl_auth, *args) + + def DeleteSlice(self, pl_auth, *args): + return self.call("DeleteSlice", pl_auth, *args) + + def GetInitScripts(self, pl_auth, *args): + return self.call("GetInitScripts", pl_auth, *args) + + def GetKeys(self, pl_auth, *args): + return self.call("GetKeys", pl_auth, *args) + + def GetNodes(self, pl_auth, *args): + return self.call("GetNodes", pl_auth, *args) + + def GetPersons(self, pl_auth, *args): + return self.call("GetPersons", pl_auth, *args) + + def GetSites(self, pl_auth, *args): + return self.call("GetSites", pl_auth, *args) + + def GetSliceAttributes(self, pl_auth, *args): + return self.call("GetSliceAttributes", pl_auth, *args) + + def GetSlices(self, pl_auth, *args): + return self.call("GetSlices", pl_auth, *args) + + def UpdateNode(self, pl_auth, *args): + return self.call("UpdateNode", pl_auth, *args) + + def UpdatePerson(self, pl_auth, *args): + return self.call("UpdatePerson", pl_auth, *args) + + def UpdateSite(self, pl_auth, *args): + return self.call("UpdateSite", pl_auth, *args) + + def UpdateSlice(self, pl_auth, *args): + return self.call("UpdateSlice", pl_auth, *args) + + diff --git a/util/report.py b/util/report.py new file mode 100644 index 00000000..28dd79ae --- /dev/null +++ b/util/report.py @@ -0,0 +1,5 @@ +def trace(x): + print x + +def error(x): + print x diff --git a/util/trustedroot.py b/util/trustedroot.py new file mode 100644 index 00000000..b531172a --- /dev/null +++ b/util/trustedroot.py @@ -0,0 +1,33 @@ +import os + +from gid import * + +class TrustedRootList(): + def __init__(self, basedir="."): + self.basedir = os.path.join(basedir, "trusted_roots") + + # create the directory to hold the files + try: + os.makedirs(self.basedir) + # if the path already exists then pass + except OSError, (errno, strerr): + if errno == 17: + pass + + def add_gid(self, gid): + fn = os.path.join(self.basedir, gid.get_hrn() + ".gid") + + gid.save_to_file(fn) + + def get_list(self): + gid_list = [] + + file_list = os.listdir(self.basedir) + for gid_file in file_list: + fn = os.path.join(self.basedir, gid_file) + if os.path.isfile(fn): + gid = GID(filename = fn) + gid_list.append(gid) + + return gid_list + -- 2.43.0