Merge branch 'master' of ssh://git.onelab.eu/git/sfa
[sfa.git] / sfa / util / faults.py
1 #
2 # SFA API faults
3 #
4
5 import xmlrpclib
6 from sfa.util.genicode import GENICODE
7
8 class SfaFault(xmlrpclib.Fault):
9     def __init__(self, faultCode, faultString, extra = None):
10         if extra:
11             faultString += ": " + str(extra)
12         xmlrpclib.Fault.__init__(self, faultCode, faultString)
13
14 class SfaInvalidAPIMethod(SfaFault):
15     def __init__(self, method, interface = None, extra = None):
16         faultString = "Invalid method " + method
17         if interface:
18             faultString += " for interface " + interface
19         SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)
20
21 class SfaInvalidArgumentCount(SfaFault):
22     def __init__(self, got, min, max = min, extra = None):
23         if min != max:
24             expected = "%d-%d" % (min, max)
25         else:
26             expected = "%d" % min
27         faultString = "Expected %s arguments, got %d" % \
28                       (expected, got)
29         SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
30
31 class SfaInvalidArgument(SfaFault):
32     def __init__(self, extra = None, name = None):
33         if name is not None:
34             faultString = "Invalid %s value" % name
35         else:
36             faultString = "Invalid argument"
37         SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
38
39 class SfaAuthenticationFailure(SfaFault):
40     def __init__(self, extra = None):
41         faultString = "Failed to authenticate call"
42         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
43
44 class SfaDBError(SfaFault):
45     def __init__(self, extra = None):
46         faultString = "Database error"
47         SfaFault.__init__(self, GENICODE.DBERROR, faultString, extra)
48
49 class SfaPermissionDenied(SfaFault):
50     def __init__(self, extra = None):
51         faultString = "Permission denied"
52         SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
53
54 class SfaNotImplemented(SfaFault):
55     def __init__(self, interface=None, extra = None):
56         faultString = "Not implemented"
57         if interface:
58             faultString += " at interface " + interface 
59         SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)
60
61 class SfaAPIError(SfaFault):
62     def __init__(self, extra = None):
63         faultString = "Internal API error"
64         SfaFault.__init__(self, GENICODE.SERVERERROR, faultString, extra)
65
66 class MalformedHrnException(SfaFault):
67     def __init__(self, value, extra = None):
68         self.value = value
69         faultString = "Malformed HRN: %(value)s" % locals()
70         SfaFault.__init__(self, GENICODE.ERROR, extra)
71     def __str__(self):
72         return repr(self.value)
73
74 class TreeException(SfaFault):
75     def __init__(self, value, extra = None):
76         self.value = value
77         faultString = "Tree Exception: %(value)s, " % locals()
78         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
79     def __str__(self):
80         return repr(self.value)
81
82 class NonExistingRecord(SfaFault):
83     def __init__(self, value, extra = None):
84         self.value = value
85         faultString = "Non exsiting record %(value)s, " % locals()
86         SfaFault.__init__(self, GENICODE.SEARCHFAILED, faultString, extra)
87     def __str__(self):
88         return repr(self.value)
89
90 class ExistingRecord(SfaFault):
91     def __init__(self, value, extra = None):
92         self.value = value
93         faultString = "Existing record: %(value)s, " % locals()
94         SfaFault.__init__(self, GENICODE.REFUSED, faultString, extra)
95     def __str__(self):
96         return repr(self.value)
97
98     
99 class InvalidRPCParams(SfaFault):
100     def __init__(self, value, extra = None):
101         self.value = value
102         faultString = "Invalid RPC Params: %(value)s, " % locals()
103         SfaFault.__init__(self, GENICODE.RPCERROR, faultString, extra)
104     def __str__(self):
105         return repr(self.value)
106
107 # SMBAKER exceptions follow
108
109 class ConnectionKeyGIDMismatch(SfaFault):
110     def __init__(self, value, extra = None):
111         self.value = value
112         faultString = "Connection Key GID mismatch: %(value)s" % locals()
113         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) 
114     def __str__(self):
115         return repr(self.value)
116
117 class MissingCallerGID(SfaFault):
118     def __init__(self, value, extra = None):
119         self.value = value
120         faultString = "Missing Caller GID: %(value)s" % locals()
121         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) 
122     def __str__(self):
123         return repr(self.value)
124
125 class RecordNotFound(SfaFault):
126     def __init__(self, value, extra = None):
127         self.value = value
128         faultString = "Record not found: %(value)s" % locals()
129         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
130     def __str__(self):
131         return repr(self.value)
132
133 class UnknownSfaType(SfaFault):
134     def __init__(self, value, extra = None):
135         self.value = value
136         faultString = "Unknown SFA Type: %(value)s" % locals()
137         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
138     def __str__(self):
139         return repr(self.value)
140
141 class MissingAuthority(SfaFault):
142     def __init__(self, value, extra = None):
143         self.value = value
144         faultString = "Missing authority: %(value)s" % locals()
145         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
146     def __str__(self):
147         return repr(self.value)
148
149 class PlanetLabRecordDoesNotExist(SfaFault):
150     def __init__(self, value, extra = None):
151         self.value = value
152         faultString = "PlanetLab record does not exist : %(value)s" % locals()
153         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
154     def __str__(self):
155         return repr(self.value)
156
157 class PermissionError(SfaFault):
158     def __init__(self, value, extra = None):
159         self.value = value
160         faultString = "Permission error: %(value)s" % locals()
161         SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
162     def __str__(self):
163         return repr(self.value)
164
165 class InsufficientRights(SfaFault):
166     def __init__(self, value, extra = None):
167         self.value = value
168         faultString = "Insufficient rights: %(value)s" % locals()
169         SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
170     def __str__(self):
171         return repr(self.value)
172
173 class MissingDelegateBit(SfaFault):
174     def __init__(self, value, extra = None):
175         self.value = value
176         faultString = "Missing delegate bit: %(value)s" % locals()
177         SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
178     def __str__(self):
179         return repr(self.value)
180
181 class ChildRightsNotSubsetOfParent(SfaFault):
182     def __init__(self, value, extra = None):
183         self.value = value
184         faultString = "Child rights not subset of parent: %(value)s" % locals()
185         SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
186     def __str__(self):
187         return repr(self.value)
188
189 class CertMissingParent(SfaFault):
190     def __init__(self, value, extra = None):
191         self.value = value
192         faultString = "Cert missing parent: %(value)s" % locals()
193         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
194     def __str__(self):
195         return repr(self.value)
196
197 class CertNotSignedByParent(SfaFault):
198     def __init__(self, value, extra = None):
199         self.value = value
200         faultString = "Cert not signed by parent: %(value)s" % locals()
201         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
202     def __str__(self):
203         return repr(self.value)
204     
205 class GidParentHrn(SfaFault):
206     def __init__(self, value, extra = None):
207         self.value = value
208         faultString = "Cert URN is not an extension of its parent: %(value)s" % locals()
209         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
210     def __str__(self):
211         return repr(self.value)
212         
213 class GidInvalidParentHrn(SfaFault):
214     def __init__(self, value, extra = None):
215         self.value = value
216         faultString = "GID invalid parent hrn: %(value)s" % locals()
217         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
218     def __str__(self):
219         return repr(self.value)
220
221 class SliverDoesNotExist(SfaFault):
222     def __init__(self, value, extra = None):
223         self.value = value
224         faultString = "Sliver does not exist : %(value)s" % locals()
225         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
226     def __str__(self):
227         return repr(self.value)
228
229 class BadRequestHash(xmlrpclib.Fault):
230     def __init__(self, hash = None, extra = None):
231         faultString = "bad request hash: " + str(hash)
232         xmlrpclib.Fault.__init__(self, GENICODE.ERROR, faultString)
233
234 class MissingTrustedRoots(SfaFault):
235     def __init__(self, value, extra = None):
236         self.value = value
237         faultString = "Trusted root directory does not exist: %(value)s" % locals()
238         SfaFault.__init__(self, GENICODE.SERVERERROR, faultString, extra) 
239     def __str__(self):
240         return repr(self.value)
241
242 class MissingSfaInfo(SfaFault):
243     def __init__(self, value, extra = None):
244         self.value = value
245         faultString = "Missing information: %(value)s" % locals()
246         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) 
247     def __str__(self):
248         return repr(self.value)
249
250 class InvalidRSpec(SfaFault):
251     def __init__(self, value, extra = None):
252         self.value = value
253         faultString = "Invalid RSpec: %(value)s" % locals()
254         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
255     def __str__(self):
256         return repr(self.value)
257
258 class InvalidRSpecElement(SfaFault):
259     def __init__(self, value, extra = None):
260         self.value = value
261         faultString = "Invalid RSpec Element: %(value)s" % locals()
262         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
263     def __str__(self):
264         return repr(self.value)
265
266 class InvalidXML(SfaFault):
267     def __init__(self, value, extra = None):
268         self.value = value
269         faultString = "Invalid XML Document: %(value)s" % locals()
270         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
271     def __str__(self):
272         return repr(self.value)
273
274 class AccountNotEnabled(SfaFault):
275     def __init__(self,  extra = None):
276         faultString = "Account Disabled"
277         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
278     def __str__(self):
279         return repr(self.value)
280
281 class CredentialNotVerifiable(SfaFault):
282     def __init__(self, value, extra = None):
283         self.value = value
284         faultString = "Unable to verify credential: %(value)s, " %locals()
285         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
286     def __str__(self):
287         return repr(self.value)
288
289 class CertExpired(SfaFault):
290     def __init__(self, value, extra=None):
291         self.value = value
292         faultString = "%s cert is expired" % value
293         SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
294