Commit 5c983ee5 authored by Iustin Pop's avatar Iustin Pop
Browse files

Introduce two-argument style for OpPrereqError

This patch introduces a two-argument style for OpPrereqError. Only the
direct raise calls in are converted, other users will follow. is modified to handle both two-argument style and the current
format. RAPI doesn't need modification as the way we encode errors is
already using a list for the error arguments, so RAPI users only need to
start checking the list length and the second argument.
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 159d4ec6
......@@ -1266,8 +1266,13 @@ def FormatError(err):
msg = "Failure: can't resolve hostname '%s'"
obuf.write(msg % err.args[0])
elif isinstance(err, errors.OpPrereqError):
obuf.write("Failure: prerequisites not met for this"
" operation:\n%s" % msg)
if len(err.args) == 2:
obuf.write("Failure: prerequisites not met for this"
" operation:\nerror type: %s, error details:\n%s" %
(err.args[1], err.args[0]))
obuf.write("Failure: prerequisites not met for this"
" operation:\n%s" % msg)
elif isinstance(err, errors.OpExecError):
obuf.write("Failure: command execution error:\n%s" % msg)
elif isinstance(err, errors.TagError):
This diff is collapsed.
......@@ -22,6 +22,26 @@
"""Ganeti exception handling"""
# OpPrereqError failure types
# not enough resources (iallocator failure, disk space, memory, etc.)
ECODE_NORES = "insufficient_resources"
# wrong arguments (at syntax level)
ECODE_INVAL = "wrong_input"
# wrong entity state
ECODE_STATE = "wrong_state"
# entity not found
ECODE_NOENT = "unknown_entity"
# entity already exists
ECODE_EXISTS = "already_exists"
# resource not unique (e.g. MAC or IP duplication)
ECODE_NOTUNIQUE = "resource_not_unique"
# internal cluster error
ECODE_FAULT = "internal_error"
# environment error (e.g. node disk error)
ECODE_ENVIRON = "environment_error"
class GenericError(Exception):
"""Base exception for Ganeti.
......@@ -125,6 +145,10 @@ class ParameterError(GenericError):
class OpPrereqError(GenericError):
"""Prerequisites for the OpCode are not fulfilled.
This exception will have either one or two arguments. For the
two-argument construction, the second argument should be one of the
ECODE_* codes.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment