1 #----------------------------------------------------------------------
2 # Copyright (c) 2008 Board of Trustees, Princeton University
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and/or hardware specification (the "Work") to
6 # deal in the Work without restriction, including without limitation the
7 # rights to use, copy, modify, merge, publish, distribute, sublicense,
8 # and/or sell copies of the Work, and to permit persons to whom the Work
9 # is furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be
12 # included in all copies or substantial portions of the Work.
14 # THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
22 #----------------------------------------------------------------------
28 from xmlrpc.client import Fault as xmlrpcFault
30 from xmlrpclib import Fault as xmlrpcFault
32 from sfa.util.genicode import GENICODE
34 class SfaFault(xmlrpcFault):
35 def __init__(self, faultCode, faultString, extra = None):
37 faultString += ": " + str(extra)
38 xmlrpcFault.__init__(self, faultCode, faultString)
40 class Forbidden(SfaFault):
41 def __init__(self, extra = None):
42 faultString = "FORBIDDEN"
43 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
45 class BadArgs(SfaFault):
46 def __init__(self, extra = None):
47 faultString = "BADARGS"
48 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
51 class CredentialMismatch(SfaFault):
52 def __init__(self, extra = None):
53 faultString = "Credential mismatch"
54 SfaFault.__init__(self, GENICODE.CREDENTIAL_MISMATCH, faultString, extra)
56 class SfaInvalidAPIMethod(SfaFault):
57 def __init__(self, method, interface = None, extra = None):
58 faultString = "Invalid method " + method
60 faultString += " for interface " + interface
61 SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)
63 class SfaInvalidArgumentCount(SfaFault):
64 def __init__(self, got, min, max = min, extra = None):
66 expected = "%d-%d" % (min, max)
69 faultString = "Expected %s arguments, got %d" % \
71 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
73 class SfaInvalidArgument(SfaFault):
74 def __init__(self, extra = None, name = None):
76 faultString = "Invalid %s value" % name
78 faultString = "Invalid argument"
79 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
81 class SfaAuthenticationFailure(SfaFault):
82 def __init__(self, extra = None):
83 faultString = "Failed to authenticate call"
84 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
86 class SfaDBError(SfaFault):
87 def __init__(self, extra = None):
88 faultString = "Database error"
89 SfaFault.__init__(self, GENICODE.DBERROR, faultString, extra)
91 class SfaPermissionDenied(SfaFault):
92 def __init__(self, extra = None):
93 faultString = "Permission denied"
94 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
96 class SfaNotImplemented(SfaFault):
97 def __init__(self, interface=None, extra = None):
98 faultString = "Not implemented"
100 faultString += " at interface " + interface
101 SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)
103 class SfaAPIError(SfaFault):
104 def __init__(self, extra = None):
105 faultString = "Internal SFA API error"
106 SfaFault.__init__(self, GENICODE.SERVERERROR, faultString, extra)
108 class MalformedHrnException(SfaFault):
109 def __init__(self, value, extra = None):
111 faultString = "Malformed HRN: %(value)s" % locals()
112 SfaFault.__init__(self, GENICODE.ERROR, extra)
114 return repr(self.value)
116 class TreeException(SfaFault):
117 def __init__(self, value, extra = None):
119 faultString = "Tree Exception: %(value)s, " % locals()
120 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
122 return repr(self.value)
124 class SearchFailed(SfaFault):
125 def __init__(self, value, extra = None):
127 faultString = "%s does not exist here " % self.value
128 SfaFault.__init__(self, GENICODE.SEARCHFAILED, faultString, extra)
130 return repr(self.value)
132 class NonExistingRecord(SfaFault):
133 def __init__(self, value, extra = None):
135 faultString = "Non exsiting record %(value)s, " % locals()
136 SfaFault.__init__(self, GENICODE.SEARCHFAILED, faultString, extra)
138 return repr(self.value)
140 class ExistingRecord(SfaFault):
141 def __init__(self, value, extra = None):
143 faultString = "Existing record: %(value)s, " % locals()
144 SfaFault.__init__(self, GENICODE.REFUSED, faultString, extra)
146 return repr(self.value)
149 class InvalidRPCParams(SfaFault):
150 def __init__(self, value, extra = None):
152 faultString = "Invalid RPC Params: %(value)s, " % locals()
153 SfaFault.__init__(self, GENICODE.RPCERROR, faultString, extra)
155 return repr(self.value)
157 # SMBAKER exceptions follow
159 class ConnectionKeyGIDMismatch(SfaFault):
160 def __init__(self, value, extra = None):
162 faultString = "Connection Key GID mismatch: %(value)s" % locals()
163 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
165 return repr(self.value)
167 class MissingCallerGID(SfaFault):
168 def __init__(self, value, extra = None):
170 faultString = "Missing Caller GID: %(value)s" % locals()
171 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
173 return repr(self.value)
175 class RecordNotFound(SfaFault):
176 def __init__(self, value, extra = None):
178 faultString = "Record not found: %(value)s" % locals()
179 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
181 return repr(self.value)
183 class UnknownSfaType(SfaFault):
184 def __init__(self, value, extra = None):
186 faultString = "Unknown SFA Type: %(value)s" % locals()
187 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
189 return repr(self.value)
191 class MissingAuthority(SfaFault):
192 def __init__(self, value, extra = None):
194 faultString = "Missing authority: %(value)s" % locals()
195 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
197 return repr(self.value)
199 class PlanetLabRecordDoesNotExist(SfaFault):
200 def __init__(self, value, extra = None):
202 faultString = "PlanetLab record does not exist : %(value)s" % locals()
203 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
205 return repr(self.value)
207 class PermissionError(SfaFault):
208 def __init__(self, value, extra = None):
210 faultString = "Permission error: %(value)s" % locals()
211 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
213 return repr(self.value)
215 class InsufficientRights(SfaFault):
216 def __init__(self, value, extra = None):
218 faultString = "Insufficient rights: %(value)s" % locals()
219 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
221 return repr(self.value)
223 class MissingDelegateBit(SfaFault):
224 def __init__(self, value, extra = None):
226 faultString = "Missing delegate bit: %(value)s" % locals()
227 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
229 return repr(self.value)
231 class ChildRightsNotSubsetOfParent(SfaFault):
232 def __init__(self, value, extra = None):
234 faultString = "Child rights not subset of parent: %(value)s" % locals()
235 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
237 return repr(self.value)
239 class CertMissingParent(SfaFault):
240 def __init__(self, value, extra = None):
242 faultString = "Cert missing parent: %(value)s" % locals()
243 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
245 return repr(self.value)
247 class CertNotSignedByParent(SfaFault):
248 def __init__(self, value, extra = None):
250 faultString = "Cert not signed by parent: %(value)s" % locals()
251 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
253 return repr(self.value)
255 class GidParentHrn(SfaFault):
256 def __init__(self, value, extra = None):
258 faultString = "Cert URN is not an extension of its parent: %(value)s" % locals()
259 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
261 return repr(self.value)
263 class GidInvalidParentHrn(SfaFault):
264 def __init__(self, value, extra = None):
266 faultString = "GID invalid parent hrn: %(value)s" % locals()
267 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
269 return repr(self.value)
271 class SliverDoesNotExist(SfaFault):
272 def __init__(self, value, extra = None):
274 faultString = "Sliver does not exist : %(value)s" % locals()
275 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
277 return repr(self.value)
279 class BadRequestHash(xmlrpcFault):
280 def __init__(self, hash = None, extra = None):
281 faultString = "bad request hash: " + str(hash)
282 xmlrpcFault.__init__(self, GENICODE.ERROR, faultString)
284 class MissingTrustedRoots(SfaFault):
285 def __init__(self, value, extra = None):
287 faultString = "Trusted root directory does not exist: %(value)s" % locals()
288 SfaFault.__init__(self, GENICODE.SERVERERROR, faultString, extra)
290 return repr(self.value)
292 class MissingSfaInfo(SfaFault):
293 def __init__(self, value, extra = None):
295 faultString = "Missing information: %(value)s" % locals()
296 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
298 return repr(self.value)
300 class InvalidRSpec(SfaFault):
301 def __init__(self, value, extra = None):
303 faultString = "Invalid RSpec: %(value)s" % locals()
304 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
306 return repr(self.value)
308 class InvalidRSpecVersion(SfaFault):
309 def __init__(self, value, extra = None):
311 faultString = "Invalid RSpec version: %(value)s" % locals()
312 SfaFault.__init__(self, GENICODE.BADVERSION, faultString, extra)
314 return repr(self.value)
316 class UnsupportedRSpecVersion(SfaFault):
317 def __init__(self, value, extra = None):
319 faultString = "Unsupported RSpec version: %(value)s" % locals()
320 SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)
322 return repr(self.value)
324 class InvalidRSpecElement(SfaFault):
325 def __init__(self, value, extra = None):
327 faultString = "Invalid RSpec Element: %(value)s" % locals()
328 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
330 return repr(self.value)
332 class InvalidXML(SfaFault):
333 def __init__(self, value, extra = None):
335 faultString = "Invalid XML Document: %(value)s" % locals()
336 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
338 return repr(self.value)
340 class AccountNotEnabled(SfaFault):
341 def __init__(self, extra = None):
342 faultString = "Account Disabled"
343 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
345 return repr(self.value)
347 class CredentialNotVerifiable(SfaFault):
348 def __init__(self, value=None, extra = None):
350 faultString = "Unable to verify credential" %locals()
352 faultString += ": %s" % value
354 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
356 return repr(self.value)
358 class CertExpired(SfaFault):
359 def __init__(self, value, extra=None):
361 faultString = "%s cert is expired" % value
362 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
364 class SfatablesRejected(SfaFault):
365 def __init__(self, value, extra=None):
367 faultString = "%s rejected by sfatables"
368 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
370 class UnsupportedOperation(SfaFault):
371 def __init__(self, value, extra=None):
373 faultString = "Unsupported operation: %s" % value
374 SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)