1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """Ganeti exception handling"""
23
24
25
26
27
28 ECODE_RESOLVER = "resolver_error"
29
30 ECODE_NORES = "insufficient_resources"
31
32 ECODE_INVAL = "wrong_input"
33
34 ECODE_STATE = "wrong_state"
35
36 ECODE_NOENT = "unknown_entity"
37
38 ECODE_EXISTS = "already_exists"
39
40 ECODE_NOTUNIQUE = "resource_not_unique"
41
42 ECODE_FAULT = "internal_error"
43
44 ECODE_ENVIRON = "environment_error"
45
46
47 ECODE_ALL = frozenset([
48 ECODE_RESOLVER,
49 ECODE_NORES,
50 ECODE_INVAL,
51 ECODE_STATE,
52 ECODE_NOENT,
53 ECODE_EXISTS,
54 ECODE_NOTUNIQUE,
55 ECODE_FAULT,
56 ECODE_ENVIRON,
57 ])
58
59
61 """Base exception for Ganeti.
62
63 """
64 pass
65
66
68 """LVM-related exception.
69
70 This exception codifies problems with LVM setup.
71
72 """
73 pass
74
75
77 """Lock error exception.
78
79 This signifies problems in the locking subsystem.
80
81 """
82 pass
83
84
86 """Hypervisor-related exception.
87
88 This is raised in case we can't communicate with the hypervisor
89 properly.
90
91 """
92 pass
93
94
96 """Programming-related error.
97
98 This is raised in cases we determine that the calling conventions
99 have been violated, meaning we got some desynchronisation between
100 parts of our code. It signifies a real programming bug.
101
102 """
103 pass
104
105
107 """Block-device related exception.
108
109 This is raised in case we can't setup the instance's block devices
110 properly.
111
112 """
113 pass
114
115
117 """Configuration related exception.
118
119 Things like having an instance with a primary node that doesn't
120 exist in the config or such raise this exception.
121
122 """
123 pass
124
125
127 """Version mismatch in the configuration file.
128
129 The error has two arguments: the expected and the actual found
130 version.
131
132 """
133 pass
134
135
137 """Errors reserving a resource.
138
139 """
140
141
143 """Programming-related error on remote call.
144
145 This is raised when an unhandled error occurs in a call to a
146 remote node. It usually signifies a real programming bug.
147
148 """
149 pass
150
151
153 """Error authenticating a remote message.
154
155 This is raised when the hmac signature on a message doesn't verify correctly
156 to the message itself. It can happen because of network unreliability or
157 because of spurious traffic.
158
159 """
160 pass
161
162
164 """A passed parameter to a command is invalid.
165
166 This is raised when the parameter passed to a request function is
167 invalid. Correct code should have verified this before passing the
168 request structure.
169
170 The argument to this exception should be the parameter name.
171
172 """
173 pass
174
175
177 """Prerequisites for the OpCode are not fulfilled.
178
179 This exception will have either one or two arguments. For the
180 two-argument construction, the second argument should be one of the
181 ECODE_* codes.
182
183 """
184
185
187 """Error during OpCode execution.
188
189 """
190
191
193 """Issue with OpCode result.
194
195 """
196
197
199 """Unknown opcode submitted.
200
201 This signifies a mismatch between the definitions on the client and
202 server side.
203
204 """
205
206
208 """Submitted job lost.
209
210 The job was submitted but it cannot be found in the current job
211 list.
212
213 """
214
215
217 """Job file could not be properly decoded/restored.
218
219 """
220
221
223 """Host name cannot be resolved.
224
225 This is not a normal situation for Ganeti, as we rely on having a
226 working resolver.
227
228 The non-resolvable hostname is available as the first element of the
229 args tuple; the other two elements of the tuple are the first two
230 args of the socket.gaierror exception (error code and description).
231
232 """
233
234
236 """A generic hook failure.
237
238 This signifies usually a setup misconfiguration.
239
240 """
241
242
244 """A required hook has failed.
245
246 This caused an abort of the operation in the initial phase. This
247 exception always has an attribute args which is a list of tuples of:
248 - node: the source node on which this hooks has failed
249 - script: the name of the script which aborted the run
250
251 """
252
253
255 """Unable to parse size unit.
256
257 """
258
259
261 """Generic parse error.
262
263 Raised when unable to parse user input.
264
265 """
266
267
269 """Unable to enforce data type.
270
271 """
272
273
275 """Invalid SSH key.
276
277 """
278
279
281 """Generic tag error.
282
283 The argument to this exception will show the exact error.
284
285 """
286
287
289 """External command error.
290
291 """
292
293
295 """Storage-related exception.
296
297 """
298
299
301 """Error raised when there is a failure setting up an inotify watcher.
302
303 """
304
305
307 """Signal Ganeti that it must quit.
308
309 This is not necessarily an error (and thus not a subclass of
310 GenericError), but it's an exceptional circumstance and it is thus
311 treated. This instance should be instantiated with two values. The
312 first one will specify the return code to the caller, and the second
313 one will be the returned result (either as an error or as a normal
314 result). Usually only the leave cluster rpc call should return
315 status True (as there it's expected we quit), every other call will
316 return status False (as a critical error was encountered).
317
318 Examples::
319
320 # Return a result of "True" to the caller, but quit ganeti afterwards
321 raise QuitGanetiException(True, None)
322 # Send an error to the caller, and quit ganeti
323 raise QuitGanetiException(False, "Fatal safety violation, shutting down")
324
325 """
326
327
329 """Job queue error.
330
331 """
332
333
335 """Job queue is marked for drain error.
336
337 This is raised when a job submission attempt is made but the queue
338 is marked for drain.
339
340 """
341
342
344 """Job queue full error.
345
346 Raised when job queue size reached its hard limit.
347
348 """
349
350
352 """A request error in Ganeti confd.
353
354 Events that should make confd abort the current request and proceed serving
355 different ones.
356
357 """
358
359
361 """A magic fourcc error in Ganeti confd.
362
363 Errors processing the fourcc in ganeti confd datagrams.
364
365 """
366
367
369 """A magic fourcc error in Ganeti confd.
370
371 Errors in the confd client library.
372
373 """
374
375
377 """UDP payload too big.
378
379 """
380
381
383 """python ctypes module is not found in the system.
384
385 """
386
387
389 """Generic IP address error.
390
391 """
392
393
395 """LUXI error.
396
397 """
398
399
401 """Error while parsing query filter.
402
403 """
405 """Returns a list of strings with details about the error.
406
407 """
408 try:
409 (_, inner) = self.args
410 except IndexError:
411 return None
412
413 return [str(inner.line),
414 (" " * (inner.column - 1)) + "^",
415 str(inner)]
416
417
418
419
420
422 """Return the class of an exception.
423
424 Given the class name, return the class itself.
425
426 @type name: str
427 @param name: the exception name
428 @rtype: class
429 @return: the actual class, or None if not found
430
431 """
432 item = globals().get(name, None)
433 if item is not None:
434 if not (isinstance(item, type(Exception)) and
435 issubclass(item, GenericError)):
436 item = None
437 return item
438
439
441 """Encodes an exception into a format that L{MaybeRaise} will recognise.
442
443 The passed L{err} argument will be formatted as a tuple (exception
444 name, arguments) that the MaybeRaise function will recognise.
445
446 @type err: GenericError child
447 @param err: usually a child of GenericError (but any exception
448 will be accepted)
449 @rtype: tuple
450 @return: tuple of (exception name, exception arguments)
451
452 """
453 return (err.__class__.__name__, err.args)
454
455
457 """If this looks like an encoded Ganeti exception, return it.
458
459 This function tries to parse the passed argument and if it looks
460 like an encoding done by EncodeException, it will return the class
461 object and arguments.
462
463 """
464 tlt = (tuple, list)
465 if (isinstance(result, tlt) and len(result) == 2 and
466 isinstance(result[1], tlt)):
467
468 errcls = GetErrorClass(result[0])
469 if errcls:
470 return (errcls, tuple(result[1]))
471
472 return None
473
474
476 """If this looks like an encoded Ganeti exception, raise it.
477
478 This function tries to parse the passed argument and if it looks
479 like an encoding done by EncodeException, it will re-raise it.
480
481 """
482 error = GetEncodedError(result)
483 if error:
484 (errcls, args) = error
485
486 raise errcls(*args)
487