6 from sfa.util.genicode import GENICODE
8 class SfaFault(xmlrpclib.Fault):
9 def __init__(self, faultCode, faultString, extra = None):
11 faultString += ": " + str(extra)
12 xmlrpclib.Fault.__init__(self, faultCode, faultString)
14 class SfaInvalidAPIMethod(SfaFault):
15 def __init__(self, method, interface = None, extra = None):
16 faultString = "Invalid method " + method
18 faultString += " for interface " + interface
19 SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)
21 class SfaInvalidArgumentCount(SfaFault):
22 def __init__(self, got, min, max = min, extra = None):
24 expected = "%d-%d" % (min, max)
27 faultString = "Expected %s arguments, got %d" % \
29 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
31 class SfaInvalidArgument(SfaFault):
32 def __init__(self, extra = None, name = None):
34 faultString = "Invalid %s value" % name
36 faultString = "Invalid argument"
37 SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra)
39 class SfaAuthenticationFailure(SfaFault):
40 def __init__(self, extra = None):
41 faultString = "Failed to authenticate call"
42 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
44 class SfaDBError(SfaFault):
45 def __init__(self, extra = None):
46 faultString = "Database error"
47 SfaFault.__init__(self, GENICODE.DBERROR, faultString, extra)
49 class SfaPermissionDenied(SfaFault):
50 def __init__(self, extra = None):
51 faultString = "Permission denied"
52 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
54 class SfaNotImplemented(SfaFault):
55 def __init__(self, interface=None, extra = None):
56 faultString = "Not implemented"
58 faultString += " at interface " + interface
59 SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)
61 class SfaAPIError(SfaFault):
62 def __init__(self, extra = None):
63 faultString = "Internal API error"
64 SfaFault.__init__(self, GENICODE.SERVERERROR, faultString, extra)
66 class MalformedHrnException(SfaFault):
67 def __init__(self, value, extra = None):
69 faultString = "Malformed HRN: %(value)s" % locals()
70 SfaFault.__init__(self, GENICODE.ERROR, extra)
72 return repr(self.value)
74 class TreeException(SfaFault):
75 def __init__(self, value, extra = None):
77 faultString = "Tree Exception: %(value)s, " % locals()
78 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
80 return repr(self.value)
82 class NonExistingRecord(SfaFault):
83 def __init__(self, value, extra = None):
85 faultString = "Non exsiting record %(value)s, " % locals()
86 SfaFault.__init__(self, GENICODE.SEARCHFAILED, faultString, extra)
88 return repr(self.value)
90 class ExistingRecord(SfaFault):
91 def __init__(self, value, extra = None):
93 faultString = "Existing record: %(value)s, " % locals()
94 SfaFault.__init__(self, GENICODE.REFUSED, faultString, extra)
96 return repr(self.value)
99 class InvalidRPCParams(SfaFault):
100 def __init__(self, value, extra = None):
102 faultString = "Invalid RPC Params: %(value)s, " % locals()
103 SfaFault.__init__(self, GENICODE.RPCERROR, faultString, extra)
105 return repr(self.value)
107 # SMBAKER exceptions follow
109 class ConnectionKeyGIDMismatch(SfaFault):
110 def __init__(self, value, extra = None):
112 faultString = "Connection Key GID mismatch: %(value)s" % locals()
113 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
115 return repr(self.value)
117 class MissingCallerGID(SfaFault):
118 def __init__(self, value, extra = None):
120 faultString = "Missing Caller GID: %(value)s" % locals()
121 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
123 return repr(self.value)
125 class RecordNotFound(SfaFault):
126 def __init__(self, value, extra = None):
128 faultString = "Record not found: %(value)s" % locals()
129 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
131 return repr(self.value)
133 class UnknownSfaType(SfaFault):
134 def __init__(self, value, extra = None):
136 faultString = "Unknown SFA Type: %(value)s" % locals()
137 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
139 return repr(self.value)
141 class MissingAuthority(SfaFault):
142 def __init__(self, value, extra = None):
144 faultString = "Missing authority: %(value)s" % locals()
145 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
147 return repr(self.value)
149 class PlanetLabRecordDoesNotExist(SfaFault):
150 def __init__(self, value, extra = None):
152 faultString = "PlanetLab record does not exist : %(value)s" % locals()
153 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
155 return repr(self.value)
157 class PermissionError(SfaFault):
158 def __init__(self, value, extra = None):
160 faultString = "Permission error: %(value)s" % locals()
161 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
163 return repr(self.value)
165 class InsufficientRights(SfaFault):
166 def __init__(self, value, extra = None):
168 faultString = "Insufficient rights: %(value)s" % locals()
169 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
171 return repr(self.value)
173 class MissingDelegateBit(SfaFault):
174 def __init__(self, value, extra = None):
176 faultString = "Missing delegate bit: %(value)s" % locals()
177 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
179 return repr(self.value)
181 class ChildRightsNotSubsetOfParent(SfaFault):
182 def __init__(self, value, extra = None):
184 faultString = "Child rights not subset of parent: %(value)s" % locals()
185 SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra)
187 return repr(self.value)
189 class CertMissingParent(SfaFault):
190 def __init__(self, value, extra = None):
192 faultString = "Cert missing parent: %(value)s" % locals()
193 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
195 return repr(self.value)
197 class CertNotSignedByParent(SfaFault):
198 def __init__(self, value, extra = None):
200 faultString = "Cert not signed by parent: %(value)s" % locals()
201 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
203 return repr(self.value)
205 class GidParentHrn(SfaFault):
206 def __init__(self, value, extra = None):
208 faultString = "Cert URN is not an extension of its parent: %(value)s" % locals()
209 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
211 return repr(self.value)
213 class GidInvalidParentHrn(SfaFault):
214 def __init__(self, value, extra = None):
216 faultString = "GID invalid parent hrn: %(value)s" % locals()
217 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
219 return repr(self.value)
221 class SliverDoesNotExist(SfaFault):
222 def __init__(self, value, extra = None):
224 faultString = "Sliver does not exist : %(value)s" % locals()
225 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
227 return repr(self.value)
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)
234 class MissingTrustedRoots(SfaFault):
235 def __init__(self, value, extra = None):
237 faultString = "Trusted root directory does not exist: %(value)s" % locals()
238 SfaFault.__init__(self, GENICODE.SERVERERROR, faultString, extra)
240 return repr(self.value)
242 class MissingSfaInfo(SfaFault):
243 def __init__(self, value, extra = None):
245 faultString = "Missing information: %(value)s" % locals()
246 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
248 return repr(self.value)
250 class InvalidRSpec(SfaFault):
251 def __init__(self, value, extra = None):
253 faultString = "Invalid RSpec: %(value)s" % locals()
254 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
256 return repr(self.value)
258 class InvalidRSpecVersion(SfaFault):
259 def __init__(self, value, extra = None):
261 faultString = "Invalid RSpec version: %(value)s" % locals()
262 SfaFault.__init__(self, GENICODE.BADVERSION, faultString, extra)
264 return repr(self.value)
266 class UnsupportedRSpecVersion(SfaFault):
267 def __init__(self, value, extra = None):
269 faultString = "Unsupported RSpec version: %(value)s" % locals()
270 SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)
272 return repr(self.value)
274 class InvalidRSpecElement(SfaFault):
275 def __init__(self, value, extra = None):
277 faultString = "Invalid RSpec Element: %(value)s" % locals()
278 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
280 return repr(self.value)
282 class InvalidXML(SfaFault):
283 def __init__(self, value, extra = None):
285 faultString = "Invalid XML Document: %(value)s" % locals()
286 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
288 return repr(self.value)
290 class AccountNotEnabled(SfaFault):
291 def __init__(self, extra = None):
292 faultString = "Account Disabled"
293 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
295 return repr(self.value)
297 class CredentialNotVerifiable(SfaFault):
298 def __init__(self, value, extra = None):
300 faultString = "Unable to verify credential: %(value)s, " %locals()
301 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)
303 return repr(self.value)
305 class CertExpired(SfaFault):
306 def __init__(self, value, extra=None):
308 faultString = "%s cert is expired" % value
309 SfaFault.__init__(self, GENICODE.ERROR, faultString, extra)