4 # Copyright (C) 2006, 2007 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 """Ganeti exception handling"""
25 class GenericError(Exception):
26 """Base exception for Ganeti.
32 class LVMError(GenericError):
33 """LVM-related exception.
35 This exception codifies problems with LVM setup.
41 class LockError(GenericError):
42 """Lock error exception.
44 This signifies problems in the locking subsystem.
50 class HypervisorError(GenericError):
51 """Hypervisor-related exception.
53 This is raised in case we can't communicate with the hypervisor
60 class ProgrammerError(GenericError):
61 """Programming-related error.
63 This is raised in cases we determine that the calling conventions
64 have been violated, meaning we got some desynchronisation between
65 parts of our code. It signifies a real programming bug.
71 class BlockDeviceError(GenericError):
72 """Block-device related exception.
74 This is raised in case we can't setup the instance's block devices
81 class ConfigurationError(GenericError):
82 """Configuration related exception.
84 Things like having an instance with a primary node that doesn't
85 exist in the config or such raise this exception.
91 class RemoteError(GenericError):
92 """Programming-related error on remote call.
94 This is raised when an unhandled error occurs in a call to a
95 remote node. It usually signifies a real programming bug.
101 class InvalidOS(GenericError):
102 """Missing OS on node.
104 This is raised when an OS exists on the master (or is otherwise
105 requested to the code) but not on the target node.
107 This exception has three arguments:
109 - the source directory, if any
110 - the reason why we consider this an invalid OS (text of error message)
115 class ParameterError(GenericError):
116 """A passed parameter to a command is invalid.
118 This is raised when the parameter passed to a request function is
119 invalid. Correct code should have verified this before passing the
122 The argument to this exception should be the parameter name.
128 class OpPrereqError(GenericError):
129 """Prerequisites for the OpCode are not fulfilled.
134 class OpExecError(GenericError):
135 """Error during OpCode execution.
140 class OpRetryError(OpExecError):
141 """Error during OpCode execution, action can be retried.
146 class OpCodeUnknown(GenericError):
147 """Unknown opcode submitted.
149 This signifies a mismatch between the definitions on the client and
155 class JobLost(GenericError):
156 """Submitted job lost.
158 The job was submitted but it cannot be found in the current job
164 class ResolverError(GenericError):
165 """Host name cannot be resolved.
167 This is not a normal situation for Ganeti, as we rely on having a
170 The non-resolvable hostname is available as the first element of the
171 args tuple; the other two elements of the tuple are the first two
172 args of the socket.gaierror exception (error code and description).
177 class HooksFailure(GenericError):
178 """A generic hook failure.
180 This signifies usually a setup misconfiguration.
185 class HooksAbort(HooksFailure):
186 """A required hook has failed.
188 This caused an abort of the operation in the initial phase. This
189 exception always has an attribute args which is a list of tuples of:
190 - node: the source node on which this hooks has failed
191 - script: the name of the script which aborted the run
196 class UnitParseError(GenericError):
197 """Unable to parse size unit.
202 class SshKeyError(GenericError):
208 class TagError(GenericError):
209 """Generic tag error.
211 The argument to this exception will show the exact error.
216 class CommandError(GenericError):
217 """External command error.
222 class QuitGanetiException(Exception):
223 """Signal that Ganeti that it must quit.
225 This is not necessarily an error (and thus not a subclass of GenericError),
226 but it's an exceptional circumstance and it is thus treated. This instance
227 should be instantiated with two values. The first one will specify whether an
228 error should returned to the caller, and the second one will be the returned
229 result (either as an error or as a normal result).
233 # Return a result of "True" to the caller, but quit ganeti afterwards
234 raise QuitGanetiException(False, True)
235 # Send an error to the caller, and quit ganeti
236 raise QuitGanetiException(True, "Fatal safety violation, shutting down")
241 class JobQueueError(GenericError):
247 class JobQueueDrainError(JobQueueError):
248 """Job queue is marked for drain error.
250 This is raised when a job submission attempt is made but the queue
256 class JobQueueFull(JobQueueError):
257 """Job queue full error.
259 Raised when job queue size reached its hard limit.
264 # errors should be added above
267 def GetErrorClass(name):
268 """Return the class of an exception.
270 Given the class name, return the class itself.
273 @param name: the exception name
275 @return: the actual class, or None if not found
278 item = globals().get(name, None)
280 if not (isinstance(item, type(Exception)) and
281 issubclass(item, GenericError)):