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