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.
</para>
<para>
Use the <option>--force-multiple</option> to keep
gnt-instance from asking for confirmation when more than one
......@@ -799,18 +799,56 @@ node1.example.com:sdb:/dev/md1
<command>failover</command>
<arg>-f</arg>
<arg>--ignore-consistency</arg>
<arg choice="req"><replaceable>instance</replaceable></arg>
<sbr>
<group choice="opt">
<arg>--instance</arg>
<arg>--primary</arg>
<arg>--secondary</arg>
</group>
<sbr>
<arg choice="req" rep="repeat"><replaceable>name</replaceable></arg>
</cmdsynopsis>
<para>
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.
</para>
<para>
The selection of which instances to failover is done via the
following options:
<variablelist>
<varlistentry>
<term><option>--instance</option></term>
<listitem>
<simpara>will select the instances given as arguments
(at least one argument required); this is the default
selection</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--primary</option></term>
<listitem>
<simpara>will select all instances whose primary node
is in the list of nodes passed as arguments (at least
one node required)</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--secondary</option></term>
<listitem>
<simpara>will select all instances whose secondary
node is in the list of nodes passed as arguments (at
least one node required)</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
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 @@ node1.example.com:sdb:/dev/md1
Example:
<screen>
# gnt-instance failover instance1.example.com
# gnt-instance failover --primary node4.example.com
</screen>
</para>
</refsect3>
......
......@@ -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?" %
(instance_name,))
if not AskUser(usertext):
return 1
result = 0
for name in inames:
op = opcodes.OpFailoverInstance(instance_name=name,
ignore_consistency=opts.ignore_consistency)
if multi_on:
logger.ToStdout("Failing over instance %s" % name)
try:
SubmitOpCode(op)
except errors.OpExecError, err:
result = 1
_, err_msg = FormatError(err)
logger.ToStderr(err_msg)
op = opcodes.OpFailoverInstance(instance_name=instance_name,
ignore_consistency=opts.ignore_consistency)
SubmitOpCode(op)
return 0
return result
def ConnectToInstanceConsole(opts, args):
......@@ -710,12 +721,13 @@ commands = {
'console': (ConnectToInstanceConsole, ARGS_ONE, [DEBUG_OPT],
"<instance>",
"Opens a console on the specified instance"),
'failover': (FailoverInstance, ARGS_ONE,
'failover': (FailoverInstance, ARGS_ATLEAST(1),
[DEBUG_OPT, FORCE_OPT,
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