Commit 36c87212 authored by Iustin Pop's avatar Iustin Pop
Browse files

Implement multi-failover options

This patch adds the same style of multi-instance selection as in
shutdown/startup to the failover subcommand, with the exception that we
cannot failover with --node or --all (it doesn't make sense).

Reviewed-by: imsnah
parent 24a40d57
......@@ -633,7 +633,7 @@
<command>startup</command> command and they influence the
actual instances being rebooted.
Use the <option>--force-multiple</option> to keep
gnt-instance from asking for confirmation when more than one
......@@ -799,18 +799,56 @@
<arg choice="req"><replaceable>instance</replaceable></arg>
<group choice="opt">
<arg choice="req" rep="repeat"><replaceable>name</replaceable></arg>
Failover will fail the instance over its secondary
Failover will fail the selected instances to their secondary
node. This works only for instances having a remote raid
disk layout.
The selection of which instances to failover is done via the
following options:
<simpara>will select the instances given as arguments
(at least one argument required); this is the default
<simpara>will select all instances whose primary node
is in the list of nodes passed as arguments (at least
one node required)</simpara>
<simpara>will select all instances whose secondary
node is in the list of nodes passed as arguments (at
least one node required)</simpara>
Normally the failover will check the consistency of the
disks before failing over the instance. If you are trying to
disks before failing over an instance. If you are trying to
migrate instances off a dead node, this will fail. Use the
<option>--ignore-consistency</option> option for this
purpose. Note that this option can be dangerous as errors in
......@@ -823,6 +861,7 @@
# gnt-instance failover
# gnt-instance failover --primary
......@@ -465,20 +465,31 @@ def FailoverInstance(opts, args):
force - whether to failover without asking questions.
instance_name = args[0]
force = opts.force
if opts.multi_mode is None:
opts.multi_mode = _SHUTDOWN_INSTANCES
inames = _ExpandMultiNames(opts.multi_mode, args)
if not inames:
logger.ToStderr("No instances match the selected options")
return 1
multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1
if not (opts.force_multi or not multi_on
or _ConfirmOperation(inames, "failover (including shutdown)")):
return 1
if not force:
usertext = ("Failover will happen to image %s."
" This requires a shutdown of the instance. Continue?" %
if not AskUser(usertext):
return 1
result = 0
for name in inames:
op = opcodes.OpFailoverInstance(instance_name=name,
if multi_on:
logger.ToStdout("Failing over instance %s" % name)
except errors.OpExecError, err:
result = 1
_, err_msg = FormatError(err)
op = opcodes.OpFailoverInstance(instance_name=instance_name,
return 0
return result
def ConnectToInstanceConsole(opts, args):
......@@ -710,12 +721,13 @@ commands = {
'console': (ConnectToInstanceConsole, ARGS_ONE, [DEBUG_OPT],
"Opens a console on the specified instance"),
'failover': (FailoverInstance, ARGS_ONE,
'failover': (FailoverInstance, ARGS_ATLEAST(1),
make_option("--ignore-consistency", dest="ignore_consistency",
action="store_true", default=False,
help="Ignore the consistency of the disks on"
" the secondary"),
m_pri_node_opt, m_sec_node_opt, m_inst_opt, m_force_multi,
"[-f] <instance>",
"Stops the instance and starts it on the backup node, using"
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