b8dee9e3aef55a0807d6f2849ca3669153dbc7db
[sfa.git] / sfa / util / faults.py
1 #
2 # GeniAPI XML-RPC faults
3 #
4 #
5
6 ### $Id$
7 ### $URL$
8
9 import xmlrpclib
10
11 class GeniFault(xmlrpclib.Fault):
12     def __init__(self, faultCode, faultString, extra = None):
13         if extra:
14             faultString += ": " + extra
15         xmlrpclib.Fault.__init__(self, faultCode, faultString)
16
17 class GeniInvalidAPIMethod(GeniFault):
18     def __init__(self, method, interface = None, extra = None):
19         faultString = "Invalid method " + method
20         if interface:
21             faultString += " for interface " + interface
22         GeniFault.__init__(self, 100, faultString, extra)
23
24 class GeniInvalidArgumentCount(GeniFault):
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         GeniFault.__init__(self, 101, faultString, extra)
33
34 class GeniInvalidArgument(GeniFault):
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         GeniFault.__init__(self, 102, faultString, extra)
41
42 class GeniAuthenticationFailure(GeniFault):
43     def __init__(self, extra = None):
44         faultString = "Failed to authenticate call"
45         GeniFault.__init__(self, 103, faultString, extra)
46
47 class GeniDBError(GeniFault):
48     def __init__(self, extra = None):
49         faultString = "Database error"
50         GeniFault.__init__(self, 106, faultString, extra)
51
52 class GeniPermissionDenied(GeniFault):
53     def __init__(self, extra = None):
54         faultString = "Permission denied"
55         GeniFault.__init__(self, 108, faultString, extra)
56
57 class GeniNotImplemented(GeniFault):
58     def __init__(self, extra = None):
59         faultString = "Not fully implemented"
60         GeniFault.__init__(self, 109, faultString, extra)
61
62 class GeniAPIError(GeniFault):
63     def __init__(self, extra = None):
64         faultString = "Internal API error"
65         GeniFault.__init__(self, 111, faultString, extra)
66
67 class MalformedHrnException(GeniFault):
68     def __init__(self, value, extra = None):
69         self.value = value
70         faultString = "Malformed HRN: %(value)s" % locals()
71         GeniFault.__init__(self, 102, faultString, extra)
72     def __str__(self):
73         return repr(self.value)
74
75 class TreeException(GeniFault):
76     def __init__(self, value, extra = None):
77         self.value = value
78         faultString = "Tree Exception: %(value)s, " % locals()
79         GeniFault.__init__(self, 111, faultString, extra)
80     def __str__(self):
81         return repr(self.value)
82
83 class NonexistingRecord(GeniFault):
84     def __init__(self, value, extra = None):
85         self.value = value
86         faultString = "Non exsiting record %(value)s, " % locals()
87         GeniFault.__init__(self, 111, faultString, extra)
88     def __str__(self):
89         return repr(self.value)
90
91 class ExistingRecord(GeniFault):
92     def __init__(self, value, extra = None):
93         self.value = value
94         faultString = "Existing record: %(value)s, " % locals()
95         GeniFault.__init__(self, 111, faultString, extra)
96     def __str__(self):
97         return repr(self.value)
98         
99 class NonexistingCredType(GeniFault):
100     def __init__(self, value, extra = None):
101         self.value = value
102         faultString = "Non existing record: %(value)s, " % locals()
103         GeniFault.__init__(self, 111, faultString, extra)
104     def __str__(self):
105         return repr(self.value)
106
107 class NonexistingFile(GeniFault):
108     def __init__(self, value):
109         self.value = value
110         faultString = "Non existing file: %(value)s, " % locals()
111         GeniFault.__init__(self, 111, faultString, extra)
112     def __str__(self):
113         return repr(self.value)
114
115 class InvalidRPCParams(GeniFault):
116     def __init__(self, value):
117         self.value = value
118         faultString = "Invalid RPC Params: %(value)s, " % locals()
119         GeniFault.__init__(self, 102, faultString, extra)
120     def __str__(self):
121         return repr(self.value)
122
123 # SMBAKER exceptions follow
124
125 class ConnectionKeyGIDMismatch(GeniFault):
126     def __init__(self, value, extra = None):
127         self.value = value
128         faultString = "Connection Key GID mismatch: %(value)s" % locals()
129         GeniFault.__init__(self, 102, faultString, extra) 
130     def __str__(self):
131         return repr(self.value)
132
133 class MissingCallerGID(GeniFault):
134     def __init__(self, value, extra = None):
135         self.value = value
136         faultString = "Missing Caller GID: %(value)s" % locals()
137         GeniFault.__init__(self, 102, faultString, extra) 
138     def __str__(self):
139         return repr(self.value)
140
141 class RecordNotFound(GeniFault):
142     def __init__(self, value, extra = None):
143         self.value = value
144         faultString = "Record not found: %(value)s" % locals()
145         GeniFault.__init__(self, 102, faultString, extra)
146     #def __str__(self):
147     #    return repr(self.value)
148
149 class UnknownGeniType(GeniFault):
150     def __init__(self, value, extra = None):
151         self.value = value
152         faultString = "Unknown Geni Type: %(value)s" % locals()
153         GeniFault.__init__(self, 102, faultString, extra)
154     def __str__(self):
155         return repr(self.value)
156
157 class MissingAuthority(GeniFault):
158     def __init__(self, value, extra = None):
159         self.value = value
160         faultString = "Missing authority: %(value)s" % locals()
161         GeniFault.__init__(self, 102, faultString, extra)
162     def __str__(self):
163         return repr(self.value)
164
165 class PlanetLabRecordDoesNotExist(GeniFault):
166     def __init__(self, value, extra = None):
167         self.value = value
168         faultString = "PlanetLab record does not exist : %(value)s" % locals()
169         GeniFault.__init__(self, 102, faultString, extra)
170     def __str__(self):
171         return repr(self.value)
172
173 class PermissionError(GeniFault):
174     def __init__(self, value, extra = None):
175         self.value = value
176         faultString = "Permission error: %(value)s" % locals()
177         GeniFault.__init__(self, 108, faultString, extra)
178     def __str__(self):
179         return repr(self.value)
180
181 class InsufficientRights(GeniFault):
182     def __init__(self, value, extra = None):
183         self.value = value
184         faultString = "Insufficient rights: %(value)s" % locals()
185         GeniFault.__init__(self, 108, faultString, extra)
186     def __str__(self):
187         return repr(self.value)
188
189 class MissingDelegateBit(GeniFault):
190     def __init__(self, value, extra = None):
191         self.value = value
192         faultString = "Missing delegate bit: %(value)s" % locals()
193         GeniFault.__init__(self, 108, faultString, extra)
194     def __str__(self):
195         return repr(self.value)
196
197 class ChildRightsNotSubsetOfParent(GeniFault):
198     def __init__(self, value, extra = None):
199         self.value = value
200         faultString = "Child rights not subset of parent: %(value)s" % locals()
201         GeniFault.__init__(self, 103, faultString, extra)
202     def __str__(self):
203         return repr(self.value)
204
205 class CertMissingParent(GeniFault):
206     def __init__(self, value, extra = None):
207         self.value = value
208         faultString = "Cert missing parent: %(value)s" % locals()
209         GeniFault.__init__(self, 103, faultString, extra)
210     def __str__(self):
211         return repr(self.value)
212
213 class CertNotSignedByParent(GeniFault):
214     def __init__(self, value, extra = None):
215         self.value = value
216         faultString = "Cert not signed by parent: %(value)s" % locals()
217         GeniFault.__init__(self, 103, faultString, extra)
218     def __str__(self):
219         return repr(self.value)
220
221 class GidInvalidParentHrn(GeniFault):
222     def __init__(self, value, extra = None):
223         self.value = value
224         faultString = "GID invalid parent hrn: %(value)s" % locals()
225         GeniFault.__init__(self, 102, faultString, extra)
226     def __str__(self):
227         return repr(self.value)
228
229 class SliverDoesNotExist(GeniFault):
230     def __init__(self, value, extra = None):
231         self.value = value
232         faultString = "Sliver does not exist : %(value)s" % locals()
233         GeniFault.__init__(self, 102, faultString, extra)
234     def __str__(self):
235         return repr(self.value)
236
237 class BadRequestHash(xmlrpclib.Fault):
238    def __init__(self, hash = None):
239         faultString = "bad request hash: " + str(hash)
240         xmlrpclib.Fault.__init__(self, 902, faultString)
241
242 class MissingTrustedRoots(GeniFault):
243     def __init__(self, value, extra = None):
244         self.value = value
245         faultString = "Trusted root directory does not exist: %(value)s" % locals()
246         GeniFault.__init__(self, 102, faultString, extra) 
247     def __str__(self):
248         return repr(self.value)