check in missing files
[sfa.git] / util / remoteshell.py
1 # remoteshell.py
2 #
3 # interface to the PLC api via xmlrpc
4 #
5 # RemoteShell() exports an API that looks identical to that exported by
6 # PLC.Shell.Shell(). It's meant to be a drop in replacement for running
7 # geniwrapper on a different machine than PLC.
8
9 import xmlrpclib
10
11 class RemoteShell:
12     def __init__(self):
13         self.servers = {}
14
15     def get_default_opts(self):
16         dict = {}
17         dict['Role'] = "user"
18         dict['Url'] = "https://www.planet-lab.org:443/PLCAPI/"
19         return dict
20
21     def call(self, name, pl_auth, *args):
22         auth_opts = self.get_default_opts().copy()
23         auth_opts.update(pl_auth)
24
25         url = auth_opts["Url"]
26         key = url + "#" + auth_opts["Username"]
27
28         if not (key in self.servers):
29             server = xmlrpclib.Server(url, verbose = 0, allow_none=True)
30             server.AdmAuthCheck(auth_opts)
31             self.servers[key] = server
32
33         server = self.servers[key]
34
35         arglist = ["auth_opts"]
36         for arg in args:
37             arglist.append(repr(arg))
38
39         result = eval("server." + name + "(" + ",".join(arglist) + ")")
40
41         return result
42
43     # TODO: there's probably an automatic way to import all these stubs
44
45     def AddInitScript(self, pl_auth, *args):
46         return self.call("AddInitScript", pl_auth, *args)
47
48     def AddNode(self, pl_auth, *args):
49         return self.call("AddNode", pl_auth, *args)
50
51     def AddPerson(self, pl_auth, *args):
52         return self.call("AddPerson", pl_auth, *args)
53
54     def AddSite(self, pl_auth, *args):
55         return self.call("AddSite", pl_auth, *args)
56
57     def AddSlice(self, pl_auth, *args):
58         return self.call("AddSlice", pl_auth, *args)
59
60     def DeleteNode(self, pl_auth, *args):
61         return self.call("DeleteNode", pl_auth, *args)
62
63     def DeletePerson(self, pl_auth, *args):
64         return self.call("DeletePerson", pl_auth, *args)
65
66     def DeleteSite(self, pl_auth, *args):
67         return self.call("DeleteSite", pl_auth, *args)
68
69     def DeleteSlice(self, pl_auth, *args):
70         return self.call("DeleteSlice", pl_auth, *args)
71
72     def GetInitScripts(self, pl_auth, *args):
73         return self.call("GetInitScripts", pl_auth, *args)
74
75     def GetKeys(self, pl_auth, *args):
76         return self.call("GetKeys", pl_auth, *args)
77
78     def GetNodes(self, pl_auth, *args):
79         return self.call("GetNodes", pl_auth, *args)
80
81     def GetPersons(self, pl_auth, *args):
82         return self.call("GetPersons", pl_auth, *args)
83
84     def GetSites(self, pl_auth, *args):
85         return self.call("GetSites", pl_auth, *args)
86
87     def GetSliceAttributes(self, pl_auth, *args):
88         return self.call("GetSliceAttributes", pl_auth, *args)
89
90     def GetSlices(self, pl_auth, *args):
91         return self.call("GetSlices", pl_auth, *args)
92
93     def UpdateNode(self, pl_auth, *args):
94         return self.call("UpdateNode", pl_auth, *args)
95
96     def UpdatePerson(self, pl_auth, *args):
97         return self.call("UpdatePerson", pl_auth, *args)
98
99     def UpdateSite(self, pl_auth, *args):
100         return self.call("UpdateSite", pl_auth, *args)
101
102     def UpdateSlice(self, pl_auth, *args):
103         return self.call("UpdateSlice", pl_auth, *args)
104
105