Statistics
| Branch: | Tag: | Revision:

root / lib / errors.py @ 75e914fb

History | View | Annotate | Download (6.1 kB)

1 2f31098c Iustin Pop
#
2 a8083063 Iustin Pop
#
3 a8083063 Iustin Pop
4 a8083063 Iustin Pop
# Copyright (C) 2006, 2007 Google Inc.
5 a8083063 Iustin Pop
#
6 a8083063 Iustin Pop
# This program is free software; you can redistribute it and/or modify
7 a8083063 Iustin Pop
# it under the terms of the GNU General Public License as published by
8 a8083063 Iustin Pop
# the Free Software Foundation; either version 2 of the License, or
9 a8083063 Iustin Pop
# (at your option) any later version.
10 a8083063 Iustin Pop
#
11 a8083063 Iustin Pop
# This program is distributed in the hope that it will be useful, but
12 a8083063 Iustin Pop
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 a8083063 Iustin Pop
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 a8083063 Iustin Pop
# General Public License for more details.
15 a8083063 Iustin Pop
#
16 a8083063 Iustin Pop
# You should have received a copy of the GNU General Public License
17 a8083063 Iustin Pop
# along with this program; if not, write to the Free Software
18 a8083063 Iustin Pop
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 a8083063 Iustin Pop
# 02110-1301, USA.
20 a8083063 Iustin Pop
21 a8083063 Iustin Pop
22 a8083063 Iustin Pop
"""Ganeti exception handling"""
23 a8083063 Iustin Pop
24 a8083063 Iustin Pop
25 a8083063 Iustin Pop
class GenericError(Exception):
26 a8083063 Iustin Pop
  """Base exception for Ganeti.
27 a8083063 Iustin Pop

28 a8083063 Iustin Pop
  """
29 a8083063 Iustin Pop
  pass
30 a8083063 Iustin Pop
31 a8083063 Iustin Pop
32 a8083063 Iustin Pop
class LVMError(GenericError):
33 a8083063 Iustin Pop
  """LVM-related exception.
34 a8083063 Iustin Pop

35 a8083063 Iustin Pop
  This exception codifies problems with LVM setup.
36 a8083063 Iustin Pop

37 a8083063 Iustin Pop
  """
38 a8083063 Iustin Pop
  pass
39 a8083063 Iustin Pop
40 a8083063 Iustin Pop
41 a8083063 Iustin Pop
class LockError(GenericError):
42 a8083063 Iustin Pop
  """Lock error exception.
43 a8083063 Iustin Pop

44 a8083063 Iustin Pop
  This signifies problems in the locking subsystem.
45 a8083063 Iustin Pop

46 a8083063 Iustin Pop
  """
47 a8083063 Iustin Pop
  pass
48 a8083063 Iustin Pop
49 a8083063 Iustin Pop
50 a8083063 Iustin Pop
class HypervisorError(GenericError):
51 a8083063 Iustin Pop
  """Hypervisor-related exception.
52 a8083063 Iustin Pop

53 a8083063 Iustin Pop
  This is raised in case we can't communicate with the hypervisor
54 a8083063 Iustin Pop
  properly.
55 a8083063 Iustin Pop

56 a8083063 Iustin Pop
  """
57 a8083063 Iustin Pop
  pass
58 a8083063 Iustin Pop
59 a8083063 Iustin Pop
60 a8083063 Iustin Pop
class ProgrammerError(GenericError):
61 a8083063 Iustin Pop
  """Programming-related error.
62 a8083063 Iustin Pop

63 a8083063 Iustin Pop
  This is raised in cases we determine that the calling conventions
64 a8083063 Iustin Pop
  have been violated, meaning we got some desynchronisation between
65 a8083063 Iustin Pop
  parts of our code. It signifies a real programming bug.
66 a8083063 Iustin Pop

67 a8083063 Iustin Pop
  """
68 a8083063 Iustin Pop
  pass
69 a8083063 Iustin Pop
70 a8083063 Iustin Pop
71 a8083063 Iustin Pop
class BlockDeviceError(GenericError):
72 a8083063 Iustin Pop
  """Block-device related exception.
73 a8083063 Iustin Pop

74 a8083063 Iustin Pop
  This is raised in case we can't setup the instance's block devices
75 a8083063 Iustin Pop
  properly.
76 a8083063 Iustin Pop

77 a8083063 Iustin Pop
  """
78 a8083063 Iustin Pop
  pass
79 a8083063 Iustin Pop
80 a8083063 Iustin Pop
81 a8083063 Iustin Pop
class ConfigurationError(GenericError):
82 a8083063 Iustin Pop
  """Configuration related exception.
83 a8083063 Iustin Pop

84 a8083063 Iustin Pop
  Things like having an instance with a primary node that doesn't
85 a8083063 Iustin Pop
  exist in the config or such raise this exception.
86 a8083063 Iustin Pop

87 a8083063 Iustin Pop
  """
88 a8083063 Iustin Pop
  pass
89 a8083063 Iustin Pop
90 a8083063 Iustin Pop
91 a8083063 Iustin Pop
class RemoteError(GenericError):
92 a8083063 Iustin Pop
  """Programming-related error on remote call.
93 a8083063 Iustin Pop

94 a8083063 Iustin Pop
  This is raised when an unhandled error occurs in a call to a
95 a8083063 Iustin Pop
  remote node.  It usually signifies a real programming bug.
96 a8083063 Iustin Pop

97 a8083063 Iustin Pop
  """
98 a8083063 Iustin Pop
  pass
99 a8083063 Iustin Pop
100 a8083063 Iustin Pop
101 a8083063 Iustin Pop
class InvalidOS(GenericError):
102 a8083063 Iustin Pop
  """Missing OS on node.
103 a8083063 Iustin Pop

104 a8083063 Iustin Pop
  This is raised when an OS exists on the master (or is otherwise
105 a8083063 Iustin Pop
  requested to the code) but not on the target node.
106 a8083063 Iustin Pop

107 305a7297 Guido Trotter
  This exception has three arguments:
108 a8083063 Iustin Pop
    - the name of the os
109 305a7297 Guido Trotter
    - the source directory, if any
110 a8083063 Iustin Pop
    - the reason why we consider this an invalid OS (text of error message)
111 a8083063 Iustin Pop

112 a8083063 Iustin Pop
  """
113 a8083063 Iustin Pop
114 a8083063 Iustin Pop
115 a8083063 Iustin Pop
class ParameterError(GenericError):
116 a8083063 Iustin Pop
  """A passed parameter to a command is invalid.
117 a8083063 Iustin Pop

118 a8083063 Iustin Pop
  This is raised when the parameter passed to a request function is
119 a8083063 Iustin Pop
  invalid. Correct code should have verified this before passing the
120 a8083063 Iustin Pop
  request structure.
121 a8083063 Iustin Pop

122 a8083063 Iustin Pop
  The argument to this exception should be the parameter name.
123 a8083063 Iustin Pop

124 a8083063 Iustin Pop
  """
125 a8083063 Iustin Pop
  pass
126 a8083063 Iustin Pop
127 a8083063 Iustin Pop
128 a8083063 Iustin Pop
class OpPrereqError(GenericError):
129 a8083063 Iustin Pop
  """Prerequisites for the OpCode are not fulfilled.
130 a8083063 Iustin Pop

131 a8083063 Iustin Pop
  """
132 a8083063 Iustin Pop
133 098c0958 Michael Hanselmann
134 a8083063 Iustin Pop
class OpExecError(GenericError):
135 a8083063 Iustin Pop
  """Error during OpCode execution.
136 a8083063 Iustin Pop

137 a8083063 Iustin Pop
  """
138 a8083063 Iustin Pop
139 098c0958 Michael Hanselmann
140 5c947f38 Iustin Pop
class OpRetryError(OpExecError):
141 5c947f38 Iustin Pop
  """Error during OpCode execution, action can be retried.
142 5c947f38 Iustin Pop

143 5c947f38 Iustin Pop
  """
144 5c947f38 Iustin Pop
145 5c947f38 Iustin Pop
146 a8083063 Iustin Pop
class OpCodeUnknown(GenericError):
147 a8083063 Iustin Pop
  """Unknown opcode submitted.
148 a8083063 Iustin Pop

149 a8083063 Iustin Pop
  This signifies a mismatch between the definitions on the client and
150 a8083063 Iustin Pop
  server side.
151 a8083063 Iustin Pop

152 a8083063 Iustin Pop
  """
153 a8083063 Iustin Pop
154 098c0958 Michael Hanselmann
155 685ee993 Iustin Pop
class JobLost(GenericError):
156 685ee993 Iustin Pop
  """Submitted job lost.
157 685ee993 Iustin Pop

158 685ee993 Iustin Pop
  The job was submitted but it cannot be found in the current job
159 685ee993 Iustin Pop
  list.
160 685ee993 Iustin Pop

161 685ee993 Iustin Pop
  """
162 685ee993 Iustin Pop
163 685ee993 Iustin Pop
164 89e1fc26 Iustin Pop
class ResolverError(GenericError):
165 89e1fc26 Iustin Pop
  """Host name cannot be resolved.
166 89e1fc26 Iustin Pop

167 89e1fc26 Iustin Pop
  This is not a normal situation for Ganeti, as we rely on having a
168 89e1fc26 Iustin Pop
  working resolver.
169 89e1fc26 Iustin Pop

170 89e1fc26 Iustin Pop
  The non-resolvable hostname is available as the first element of the
171 89e1fc26 Iustin Pop
  args tuple; the other two elements of the tuple are the first two
172 89e1fc26 Iustin Pop
  args of the socket.gaierror exception (error code and description).
173 89e1fc26 Iustin Pop

174 89e1fc26 Iustin Pop
  """
175 89e1fc26 Iustin Pop
176 89e1fc26 Iustin Pop
177 a8083063 Iustin Pop
class HooksFailure(GenericError):
178 a8083063 Iustin Pop
  """A generic hook failure.
179 a8083063 Iustin Pop

180 a8083063 Iustin Pop
  This signifies usually a setup misconfiguration.
181 a8083063 Iustin Pop

182 a8083063 Iustin Pop
  """
183 a8083063 Iustin Pop
184 098c0958 Michael Hanselmann
185 a8083063 Iustin Pop
class HooksAbort(HooksFailure):
186 a8083063 Iustin Pop
  """A required hook has failed.
187 a8083063 Iustin Pop

188 a8083063 Iustin Pop
  This caused an abort of the operation in the initial phase. This
189 a8083063 Iustin Pop
  exception always has an attribute args which is a list of tuples of:
190 a8083063 Iustin Pop
    - node: the source node on which this hooks has failed
191 a8083063 Iustin Pop
    - script: the name of the script which aborted the run
192 a8083063 Iustin Pop

193 a8083063 Iustin Pop
  """
194 a8083063 Iustin Pop
195 098c0958 Michael Hanselmann
196 a8083063 Iustin Pop
class UnitParseError(GenericError):
197 a8083063 Iustin Pop
  """Unable to parse size unit.
198 a8083063 Iustin Pop

199 a8083063 Iustin Pop
  """
200 a8083063 Iustin Pop
201 a5728081 Guido Trotter
class TypeEnforcementError(GenericError):
202 a5728081 Guido Trotter
  """Unable to enforce data type.
203 a5728081 Guido Trotter

204 a5728081 Guido Trotter
  """
205 a8083063 Iustin Pop
206 a8083063 Iustin Pop
class SshKeyError(GenericError):
207 a8083063 Iustin Pop
  """Invalid SSH key.
208 b0059682 Guido Trotter

209 a8083063 Iustin Pop
  """
210 5c947f38 Iustin Pop
211 5c947f38 Iustin Pop
212 5c947f38 Iustin Pop
class TagError(GenericError):
213 5c947f38 Iustin Pop
  """Generic tag error.
214 5c947f38 Iustin Pop

215 5c947f38 Iustin Pop
  The argument to this exception will show the exact error.
216 5c947f38 Iustin Pop

217 5c947f38 Iustin Pop
  """
218 7bca53e4 Michael Hanselmann
219 7bca53e4 Michael Hanselmann
220 7bca53e4 Michael Hanselmann
class CommandError(GenericError):
221 7bca53e4 Michael Hanselmann
  """External command error.
222 7bca53e4 Michael Hanselmann

223 7bca53e4 Michael Hanselmann
  """
224 e50bdd68 Guido Trotter
225 e50bdd68 Guido Trotter
226 e50bdd68 Guido Trotter
class QuitGanetiException(Exception):
227 e50bdd68 Guido Trotter
  """Signal that Ganeti that it must quit.
228 e50bdd68 Guido Trotter

229 e50bdd68 Guido Trotter
  This is not necessarily an error (and thus not a subclass of GenericError),
230 e50bdd68 Guido Trotter
  but it's an exceptional circumstance and it is thus treated. This instance
231 9f9c8ee2 Guido Trotter
  should be instantiated with two values. The first one will specify whether an
232 9f9c8ee2 Guido Trotter
  error should returned to the caller, and the second one will be the returned
233 9f9c8ee2 Guido Trotter
  result (either as an error or as a normal result).
234 e50bdd68 Guido Trotter

235 c41eea6e Iustin Pop
  Examples::
236 c41eea6e Iustin Pop

237 e50bdd68 Guido Trotter
    # Return a result of "True" to the caller, but quit ganeti afterwards
238 9f9c8ee2 Guido Trotter
    raise QuitGanetiException(False, True)
239 e50bdd68 Guido Trotter
    # Send an error to the caller, and quit ganeti
240 9f9c8ee2 Guido Trotter
    raise QuitGanetiException(True, "Fatal safety violation, shutting down")
241 e50bdd68 Guido Trotter

242 e50bdd68 Guido Trotter
  """
243 e50bdd68 Guido Trotter
244 f1da30e6 Michael Hanselmann
245 d11bda8d Iustin Pop
class JobQueueError(GenericError):
246 f1da30e6 Michael Hanselmann
  """Job queue error.
247 f1da30e6 Michael Hanselmann

248 f1da30e6 Michael Hanselmann
  """
249 6797ec29 Iustin Pop
250 6797ec29 Iustin Pop
251 686d7433 Iustin Pop
class JobQueueDrainError(JobQueueError):
252 686d7433 Iustin Pop
  """Job queue is marked for drain error.
253 686d7433 Iustin Pop

254 686d7433 Iustin Pop
  This is raised when a job submission attempt is made but the queue
255 686d7433 Iustin Pop
  is marked for drain.
256 686d7433 Iustin Pop

257 686d7433 Iustin Pop
  """
258 686d7433 Iustin Pop
259 686d7433 Iustin Pop
260 f87b405e Michael Hanselmann
class JobQueueFull(JobQueueError):
261 f87b405e Michael Hanselmann
  """Job queue full error.
262 f87b405e Michael Hanselmann

263 f87b405e Michael Hanselmann
  Raised when job queue size reached its hard limit.
264 f87b405e Michael Hanselmann

265 f87b405e Michael Hanselmann
  """
266 f87b405e Michael Hanselmann
267 f87b405e Michael Hanselmann
268 6797ec29 Iustin Pop
# errors should be added above
269 6797ec29 Iustin Pop
270 6797ec29 Iustin Pop
271 6797ec29 Iustin Pop
def GetErrorClass(name):
272 6797ec29 Iustin Pop
  """Return the class of an exception.
273 6797ec29 Iustin Pop

274 6797ec29 Iustin Pop
  Given the class name, return the class itself.
275 6797ec29 Iustin Pop

276 6797ec29 Iustin Pop
  @type name: str
277 6797ec29 Iustin Pop
  @param name: the exception name
278 6797ec29 Iustin Pop
  @rtype: class
279 6797ec29 Iustin Pop
  @return: the actual class, or None if not found
280 6797ec29 Iustin Pop

281 6797ec29 Iustin Pop
  """
282 6797ec29 Iustin Pop
  item = globals().get(name, None)
283 6797ec29 Iustin Pop
  if item is not None:
284 6797ec29 Iustin Pop
    if not (isinstance(item, type(Exception)) and
285 6797ec29 Iustin Pop
            issubclass(item, GenericError)):
286 6797ec29 Iustin Pop
      item = None
287 6797ec29 Iustin Pop
  return item