Merge branch 'master' of ssh://git.planet-lab.org/git/sfa
[sfa.git] / sfa / plc / 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 # SFA on a different machine than PLC.
8
9 ### $Id$
10 ### $URL$
11
12 import xmlrpclib
13
14 class RemoteShell:
15     def __init__(self,logger):
16         self.servers = {}
17         self.logger=logger
18
19     def call(self, name, pl_auth, *args):
20
21         key = pl_auth["Url"] + "#" + pl_auth["Username"]
22
23         if not (key in self.servers):
24             self.logger.info("Connecting to PLCAPI at url %s"%pl_auth['Url'])
25             server = xmlrpclib.Server(pl_auth["Url"], verbose = 0, allow_none=True)
26             #server.AdmAuthCheck(pl_auth)
27             server.AuthCheck(pl_auth)
28             self.servers[key] = server
29
30         server = self.servers[key]
31
32         arglist = ["pl_auth"]
33         for arg in args:
34             arglist.append(repr(arg))
35
36         str = "server." + name + "(" + ",".join(arglist) + ")"
37         result = eval(str)
38
39         return result
40
41     # TODO: there's probably an automatic way to import all these stubs
42
43     def AddInitScript(self, pl_auth, *args):
44         return self.call("AddInitScript", pl_auth, *args)
45
46     def AddNode(self, pl_auth, *args):
47         return self.call("AddNode", pl_auth, *args)
48
49     def AddPerson(self, pl_auth, *args):
50         return self.call("AddPerson", pl_auth, *args)
51
52     def AddPersonToSlice(self, pl_auth, *args):
53         return self.call("AddPersonToSlice", pl_auth, *args)
54
55     def AddSite(self, pl_auth, *args):
56         return self.call("AddSite", pl_auth, *args)
57
58     def AddSlice(self, pl_auth, *args):
59         return self.call("AddSlice", pl_auth, *args)
60
61     def DeleteNode(self, pl_auth, *args):
62         return self.call("DeleteNode", pl_auth, *args)
63
64     def DeletePerson(self, pl_auth, *args):
65         return self.call("DeletePerson", pl_auth, *args)
66
67     def DeletePersonFromSlice(self, pl_auth, *args):
68         return self.call("DeletePersonFromSlice", pl_auth, *args)
69
70     def DeleteSite(self, pl_auth, *args):
71         return self.call("DeleteSite", pl_auth, *args)
72
73     def DeleteSlice(self, pl_auth, *args):
74         return self.call("DeleteSlice", pl_auth, *args)
75
76     def GetInitScripts(self, pl_auth, *args):
77         return self.call("GetInitScripts", pl_auth, *args)
78
79     def GetKeys(self, pl_auth, *args):
80         return self.call("GetKeys", pl_auth, *args)
81
82     def GetNodes(self, pl_auth, *args):
83         return self.call("GetNodes", pl_auth, *args)
84
85     def GetPersons(self, pl_auth, *args):
86         return self.call("GetPersons", pl_auth, *args)
87
88     def GetSites(self, pl_auth, *args):
89         return self.call("GetSites", pl_auth, *args)
90
91     def GetSliceAttributes(self, pl_auth, *args):
92         return self.call("GetSliceAttributes", pl_auth, *args)
93
94     def GetSlices(self, pl_auth, *args):
95         return self.call("GetSlices", pl_auth, *args)
96
97     def UpdateNode(self, pl_auth, *args):
98         return self.call("UpdateNode", pl_auth, *args)
99
100     def UpdatePerson(self, pl_auth, *args):
101         return self.call("UpdatePerson", pl_auth, *args)
102
103     def UpdateSite(self, pl_auth, *args):
104         return self.call("UpdateSite", pl_auth, *args)
105
106     def UpdateSlice(self, pl_auth, *args):
107         return self.call("UpdateSlice", pl_auth, *args)
108
109