Statistics
| Branch: | Tag: | Revision:

root / lib / errors.py @ 23828f1c

History | View | Annotate | Download (5.9 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 a8083063 Iustin Pop
202 a8083063 Iustin Pop
class SshKeyError(GenericError):
203 a8083063 Iustin Pop
  """Invalid SSH key.
204 b0059682 Guido Trotter

205 a8083063 Iustin Pop
  """
206 5c947f38 Iustin Pop
207 5c947f38 Iustin Pop
208 5c947f38 Iustin Pop
class TagError(GenericError):
209 5c947f38 Iustin Pop
  """Generic tag error.
210 5c947f38 Iustin Pop

211 5c947f38 Iustin Pop
  The argument to this exception will show the exact error.
212 5c947f38 Iustin Pop

213 5c947f38 Iustin Pop
  """
214 7bca53e4 Michael Hanselmann
215 7bca53e4 Michael Hanselmann
216 7bca53e4 Michael Hanselmann
class CommandError(GenericError):
217 7bca53e4 Michael Hanselmann
  """External command error.
218 7bca53e4 Michael Hanselmann

219 7bca53e4 Michael Hanselmann
  """
220 e50bdd68 Guido Trotter
221 e50bdd68 Guido Trotter
222 e50bdd68 Guido Trotter
class QuitGanetiException(Exception):
223 e50bdd68 Guido Trotter
  """Signal that Ganeti that it must quit.
224 e50bdd68 Guido Trotter

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

231 e50bdd68 Guido Trotter
  Examples:
232 e50bdd68 Guido Trotter
    # Return a result of "True" to the caller, but quit ganeti afterwards
233 9f9c8ee2 Guido Trotter
    raise QuitGanetiException(False, True)
234 e50bdd68 Guido Trotter
    # Send an error to the caller, and quit ganeti
235 9f9c8ee2 Guido Trotter
    raise QuitGanetiException(True, "Fatal safety violation, shutting down")
236 e50bdd68 Guido Trotter

237 e50bdd68 Guido Trotter
  """
238 e50bdd68 Guido Trotter
239 f1da30e6 Michael Hanselmann
240 d11bda8d Iustin Pop
class JobQueueError(GenericError):
241 f1da30e6 Michael Hanselmann
  """Job queue error.
242 f1da30e6 Michael Hanselmann

243 f1da30e6 Michael Hanselmann
  """
244 6797ec29 Iustin Pop
245 6797ec29 Iustin Pop
246 686d7433 Iustin Pop
class JobQueueDrainError(JobQueueError):
247 686d7433 Iustin Pop
  """Job queue is marked for drain error.
248 686d7433 Iustin Pop

249 686d7433 Iustin Pop
  This is raised when a job submission attempt is made but the queue
250 686d7433 Iustin Pop
  is marked for drain.
251 686d7433 Iustin Pop

252 686d7433 Iustin Pop
  """
253 686d7433 Iustin Pop
254 686d7433 Iustin Pop
255 6797ec29 Iustin Pop
# errors should be added above
256 6797ec29 Iustin Pop
257 6797ec29 Iustin Pop
258 6797ec29 Iustin Pop
def GetErrorClass(name):
259 6797ec29 Iustin Pop
  """Return the class of an exception.
260 6797ec29 Iustin Pop

261 6797ec29 Iustin Pop
  Given the class name, return the class itself.
262 6797ec29 Iustin Pop

263 6797ec29 Iustin Pop
  @type name: str
264 6797ec29 Iustin Pop
  @param name: the exception name
265 6797ec29 Iustin Pop
  @rtype: class
266 6797ec29 Iustin Pop
  @return: the actual class, or None if not found
267 6797ec29 Iustin Pop

268 6797ec29 Iustin Pop
  """
269 6797ec29 Iustin Pop
  item = globals().get(name, None)
270 6797ec29 Iustin Pop
  if item is not None:
271 6797ec29 Iustin Pop
    if not (isinstance(item, type(Exception)) and
272 6797ec29 Iustin Pop
            issubclass(item, GenericError)):
273 6797ec29 Iustin Pop
      item = None
274 6797ec29 Iustin Pop
  return item