Commit 0d57ce24 authored by Guido Trotter's avatar Guido Trotter

Allow shutting down offline instance

If an instance is offline we definitely shouldn't start it up.
But shutting it down, should it be up by mistake is not "that" bad.
Still, we only allow it with --force, as it still performs an action on
an instance we shouldn't touch. This should make everybody happy.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent eec7840a
......@@ -234,7 +234,7 @@ instance Arbitrary OpCodes.OpCode where
pure emptyJSObject <*> pure emptyJSObject <*>
arbitrary <*> arbitrary
"OP_INSTANCE_SHUTDOWN" ->
OpCodes.OpInstanceShutdown <$> genFQDN <*> arbitrary <*>
OpCodes.OpInstanceShutdown <$> genFQDN <*> arbitrary <*> arbitrary <*>
arbitrary <*> arbitrary
"OP_INSTANCE_REBOOT" ->
OpCodes.OpInstanceReboot <$> genFQDN <*> arbitrary <*>
......
......@@ -333,6 +333,7 @@ $(genOpCode "OpCode"
])
, ("OpInstanceShutdown",
[ pInstanceName
, pForce
, pIgnoreOfflineNodes
, pShutdownTimeout'
, pNoRemember
......
......@@ -648,6 +648,7 @@ def _ShutdownInstance(name, opts):
"""
return opcodes.OpInstanceShutdown(instance_name=name,
force=opts.force,
timeout=opts.timeout,
ignore_offline_nodes=opts.ignore_offline,
no_remember=opts.no_remember)
......@@ -1533,7 +1534,7 @@ commands = {
"<instance>", "Alters the parameters of an instance"),
"shutdown": (
GenericManyOps("shutdown", _ShutdownInstance), [ArgInstance()],
[m_node_opt, m_pri_node_opt, m_sec_node_opt, m_clust_opt,
[FORCE_OPT, m_node_opt, m_pri_node_opt, m_sec_node_opt, m_clust_opt,
m_node_tags_opt, m_pri_node_tags_opt, m_sec_node_tags_opt,
m_inst_tags_opt, m_inst_opt, m_force_multi, TIMEOUT_OPT, SUBMIT_OPT,
DRY_RUN_OPT, PRIORITY_OPT, IGNORE_OFFLINE_OPT, NO_REMEMBER_OPT],
......
......@@ -7177,7 +7177,10 @@ class LUInstanceShutdown(LogicalUnit):
assert self.instance is not None, \
"Cannot retrieve locked instance %s" % self.op.instance_name
_CheckInstanceState(self, self.instance, INSTANCE_ONLINE)
if not self.op.force:
_CheckInstanceState(self, self.instance, INSTANCE_ONLINE)
else:
self.LogWarning("Ignoring offline instance check")
self.primary_offline = \
self.cfg.GetNodeInfo(self.instance.primary_node).offline
......
......@@ -1430,6 +1430,7 @@ class OpInstanceShutdown(OpCode):
OP_DSC_FIELD = "instance_name"
OP_PARAMS = [
_PInstanceName,
_PForce,
_PIgnoreOfflineNodes,
("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TNonNegativeInt,
"How long to wait for instance to shut down"),
......
......@@ -1163,7 +1163,7 @@ SHUTDOWN
| **shutdown**
| [\--timeout=*N*]
| [\--force-multiple] [\--ignore-offline] [\--no-remember]
| [\--force] [\--force-multiple] [\--ignore-offline] [\--no-remember]
| [\--instance \| \--node \| \--primary \| \--secondary \| \--all \|
| \--tags \| \--node-tags \| \--pri-node-tags \| \--sec-node-tags]
| [\--submit]
......@@ -1188,6 +1188,10 @@ and they influence the actual instances being shutdown.
force the instance to be marked as stopped. This option should be used
with care as it can lead to an inconsistent cluster state.
Use ``--force`` to be able to shutdown an instance even when it's marked
as offline. This is useful is an offline instance ends up in the
``ERROR_up`` state, for example.
The ``--no-remember`` option will perform the shutdown but not change
the state of the instance in the configuration file (if it was running
before, Ganeti will still thinks it needs to be running). This can be
......
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