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