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