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 #----------------------------------------------------------------------
27 from sfa.util.genicode import GENICODE
28 from sfa.util.py23 import xmlrpc_client
31 class SfaFault(xmlrpc_client.Fault):
33 def __init__(self, faultCode, faultString, extra=None):
35 faultString += ": " + str(extra)
36 xmlrpc_client.Fault.__init__(self, faultCode, faultString)
39 class Forbidden(SfaFault):
41 def __init__(self, extra=None):
42 faultString = "FORBIDDEN"
43 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
46 class BadArgs(SfaFault):
48 def __init__(self, extra=None):
49 faultString = "BADARGS"
50 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
53 class CredentialMismatch(SfaFault):
55 def __init__(self, extra=None):
56 faultString = "Credential mismatch"
57 SfaFault.__init__(self, GENICODE.CREDENTIAL_MISMATCH,
61 class SfaInvalidAPIMethod(SfaFault):
63 def __init__(self, method, interface=None, extra=None):
64 faultString = "Invalid method " + method
66 faultString += " for interface " + interface
67 SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)
70 class SfaInvalidArgumentCount(SfaFault):
72 def __init__(self, got, min, max=min, extra=None):
74 expected = "%d-%d" % (min, max)
77 faultString = "Expected %s arguments, got %d" % \
79 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
82 class SfaInvalidArgument(SfaFault):
84 def __init__(self, extra=None, name=None):
86 faultString = "Invalid %s value" % name
88 faultString = "Invalid argument"
89 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
92 class SfaAuthenticationFailure(SfaFault):
94 def __init__(self, extra=None):
95 faultString = "Failed to authenticate call"
96 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
99 class SfaDBError(SfaFault):
101 def __init__(self, extra=None):
102 faultString = "Database error"
103 SfaFault.__init__(self, GENICODE.DBERROR, faultString, extra)
106 class SfaPermissionDenied(SfaFault):
108 def __init__(self, extra=None):
109 faultString = "Permission denied"
110 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
113 class SfaNotImplemented(SfaFault):
115 def __init__(self, interface=None, extra=None):
116 faultString = "Not implemented"
118 faultString += " at interface " + interface
119 SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)
122 class SfaAPIError(SfaFault):
124 def __init__(self, extra=None):
125 faultString = "Internal SFA API error"
126 SfaFault.__init__(self, GENICODE.SERVERERROR, faultString, extra)
129 class MalformedHrnException(SfaFault):
131 def __init__(self, value, extra=None):
133 faultString = "Malformed HRN: %(value)s" % locals()
134 SfaFault.__init__(self, GENICODE.ERROR, extra)
137 return repr(self.value)
140 class TreeException(SfaFault):
142 def __init__(self, value, extra=None):
144 faultString = "Tree Exception: %(value)s, " % locals()
145 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
148 return repr(self.value)
151 class SearchFailed(SfaFault):
153 def __init__(self, value, extra=None):
155 faultString = "%s does not exist here " % self.value
156 SfaFault.__init__(self, GENICODE.SEARCHFAILED, faultString, extra)
159 return repr(self.value)
162 class NonExistingRecord(SfaFault):
164 def __init__(self, value, extra=None):
166 faultString = "Non exsiting record %(value)s, " % locals()
167 SfaFault.__init__(self, GENICODE.SEARCHFAILED, faultString, extra)
170 return repr(self.value)
173 class ExistingRecord(SfaFault):
175 def __init__(self, value, extra=None):
177 faultString = "Existing record: %(value)s, " % locals()
178 SfaFault.__init__(self, GENICODE.REFUSED, faultString, extra)
181 return repr(self.value)
184 class InvalidRPCParams(SfaFault):
186 def __init__(self, value, extra=None):
188 faultString = "Invalid RPC Params: %(value)s, " % locals()
189 SfaFault.__init__(self, GENICODE.RPCERROR, faultString, extra)
192 return repr(self.value)
194 # SMBAKER exceptions follow
197 class ConnectionKeyGIDMismatch(SfaFault):
199 def __init__(self, value, extra=None):
201 faultString = "Connection Key GID mismatch: %(value)s" % locals()
202 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
205 return repr(self.value)
208 class MissingCallerGID(SfaFault):
210 def __init__(self, value, extra=None):
212 faultString = "Missing Caller GID: %(value)s" % locals()
213 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
216 return repr(self.value)
219 class RecordNotFound(SfaFault):
221 def __init__(self, value, extra=None):
223 faultString = "Record not found: %(value)s" % locals()
224 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
227 return repr(self.value)
230 class UnknownSfaType(SfaFault):
232 def __init__(self, value, extra=None):
234 faultString = "Unknown SFA Type: %(value)s" % locals()
235 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
238 return repr(self.value)
241 class MissingAuthority(SfaFault):
243 def __init__(self, value, extra=None):
245 faultString = "Missing authority: %(value)s" % locals()
246 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
249 return repr(self.value)
252 class PlanetLabRecordDoesNotExist(SfaFault):
254 def __init__(self, value, extra=None):
256 faultString = "PlanetLab record does not exist : %(value)s" % locals()
257 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
260 return repr(self.value)
263 class PermissionError(SfaFault):
265 def __init__(self, value, extra=None):
267 faultString = "Permission error: %(value)s" % locals()
268 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
271 return repr(self.value)
274 class InsufficientRights(SfaFault):
276 def __init__(self, value, extra=None):
278 faultString = "Insufficient rights: %(value)s" % locals()
279 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
282 return repr(self.value)
285 class MissingDelegateBit(SfaFault):
287 def __init__(self, value, extra=None):
289 faultString = "Missing delegate bit: %(value)s" % locals()
290 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
293 return repr(self.value)
296 class ChildRightsNotSubsetOfParent(SfaFault):
298 def __init__(self, value, extra=None):
300 faultString = "Child rights not subset of parent: %(value)s" % locals()
301 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
304 return repr(self.value)
307 class CertMissingParent(SfaFault):
309 def __init__(self, value, extra=None):
311 faultString = "Cert missing parent: %(value)s" % locals()
312 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
315 return repr(self.value)
318 class CertNotSignedByParent(SfaFault):
320 def __init__(self, value, extra=None):
322 faultString = "Cert not signed by parent: %(value)s" % locals()
323 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
326 return repr(self.value)
329 class GidParentHrn(SfaFault):
331 def __init__(self, value, extra=None):
333 faultString = "Cert URN is not an extension of its parent: %(value)s" % locals(
335 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
338 return repr(self.value)
341 class GidInvalidParentHrn(SfaFault):
343 def __init__(self, value, extra=None):
345 faultString = "GID invalid parent hrn: %(value)s" % locals()
346 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
349 return repr(self.value)
352 class SliverDoesNotExist(SfaFault):
354 def __init__(self, value, extra=None):
356 faultString = "Sliver does not exist : %(value)s" % locals()
357 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
360 return repr(self.value)
363 class BadRequestHash(xmlrpc_client.Fault):
365 def __init__(self, hash=None, extra=None):
366 faultString = "bad request hash: " + str(hash)
367 xmlrpc_client.Fault.__init__(self, GENICODE.ERROR, faultString)
370 class MissingTrustedRoots(SfaFault):
372 def __init__(self, value, extra=None):
374 faultString = "Trusted root directory does not exist: %(value)s" % locals(
376 SfaFault.__init__(self, GENICODE.SERVERERROR, faultString, extra)
379 return repr(self.value)
382 class MissingSfaInfo(SfaFault):
384 def __init__(self, value, extra=None):
386 faultString = "Missing information: %(value)s" % locals()
387 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
390 return repr(self.value)
393 class InvalidRSpec(SfaFault):
395 def __init__(self, value, extra=None):
397 faultString = "Invalid RSpec: %(value)s" % locals()
398 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
401 return repr(self.value)
404 class InvalidRSpecVersion(SfaFault):
406 def __init__(self, value, extra=None):
408 faultString = "Invalid RSpec version: %(value)s" % locals()
409 SfaFault.__init__(self, GENICODE.BADVERSION, faultString, extra)
412 return repr(self.value)
415 class UnsupportedRSpecVersion(SfaFault):
417 def __init__(self, value, extra=None):
419 faultString = "Unsupported RSpec version: %(value)s" % locals()
420 SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)
423 return repr(self.value)
426 class InvalidRSpecElement(SfaFault):
428 def __init__(self, value, extra=None):
430 faultString = "Invalid RSpec Element: %(value)s" % locals()
431 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
434 return repr(self.value)
437 class InvalidXML(SfaFault):
439 def __init__(self, value, extra=None):
441 faultString = "Invalid XML Document: %(value)s" % locals()
442 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
445 return repr(self.value)
448 class AccountNotEnabled(SfaFault):
450 def __init__(self, extra=None):
451 faultString = "Account Disabled"
452 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
455 return repr(self.value)
458 class CredentialNotVerifiable(SfaFault):
460 def __init__(self, value=None, extra=None):
462 faultString = "Unable to verify credential" % locals()
464 faultString += ": %s" % value
466 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
469 return repr(self.value)
472 class CertExpired(SfaFault):
474 def __init__(self, value, extra=None):
476 faultString = "%s cert is expired" % value
477 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
480 class SfatablesRejected(SfaFault):
482 def __init__(self, value, extra=None):
484 faultString = "%s rejected by sfatables"
485 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
488 class UnsupportedOperation(SfaFault):
490 def __init__(self, value, extra=None):
492 faultString = "Unsupported operation: %s" % value
493 SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)