Commit 57de31c0 authored by Agata Murawska's avatar Agata Murawska
Browse files

Transition into and out of offline instance state


Signed-off-by: default avatarAgata Murawska <agatamurawska@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 2e04d454
......@@ -137,6 +137,8 @@ __all__ = [
"NOVOTING_OPT",
"NO_REMEMBER_OPT",
"NWSYNC_OPT",
"OFFLINE_INST_OPT",
"ONLINE_INST_OPT",
"ON_PRIMARY_OPT",
"ON_SECONDARY_OPT",
"OFFLINE_OPT",
......@@ -685,6 +687,14 @@ NWSYNC_OPT = cli_option("--no-wait-for-sync", dest="wait_for_sync",
default=True, action="store_false",
help="Don't wait for sync (DANGEROUS!)")
ONLINE_INST_OPT = cli_option("--online", dest="online_inst",
action="store_true", default=False,
help="Enable offline instance")
OFFLINE_INST_OPT = cli_option("--offline", dest="offline_inst",
action="store_true", default=False,
help="Disable down instance")
DISK_TEMPLATE_OPT = cli_option("-t", "--disk-template", dest="disk_template",
help=("Custom disk setup (%s)" %
utils.CommaJoin(constants.DISK_TEMPLATES)),
......
......@@ -1248,7 +1248,8 @@ def SetInstanceParams(opts, args):
"""
if not (opts.nics or opts.disks or opts.disk_template or
opts.hvparams or opts.beparams or opts.os or opts.osparams):
opts.hvparams or opts.beparams or opts.os or opts.osparams or
opts.offline_inst or opts.online_inst):
ToStderr("Please give at least one of the parameters.")
return 1
......@@ -1305,7 +1306,9 @@ def SetInstanceParams(opts, args):
osparams=opts.osparams,
force_variant=opts.force_variant,
force=opts.force,
wait_for_sync=opts.wait_for_sync)
wait_for_sync=opts.wait_for_sync,
offline_inst=opts.offline_inst,
online_inst=opts.online_inst)
# even if here we process the result, we allow submit only
result = SubmitOrSend(op, opts)
......@@ -1487,7 +1490,8 @@ commands = {
SetInstanceParams, ARGS_ONE_INSTANCE,
[BACKEND_OPT, DISK_OPT, FORCE_OPT, HVOPTS_OPT, NET_OPT, SUBMIT_OPT,
DISK_TEMPLATE_OPT, SINGLE_NODE_OPT, OS_OPT, FORCE_VARIANT_OPT,
OSPARAMS_OPT, DRY_RUN_OPT, PRIORITY_OPT, NWSYNC_OPT],
OSPARAMS_OPT, DRY_RUN_OPT, PRIORITY_OPT, NWSYNC_OPT, OFFLINE_INST_OPT,
ONLINE_INST_OPT],
"<instance>", "Alters the parameters of an instance"),
"shutdown": (
GenericManyOps("shutdown", _ShutdownInstance), [ArgInstance()],
......
......@@ -10982,7 +10982,8 @@ class LUInstanceSetParams(LogicalUnit):
def CheckArguments(self):
if not (self.op.nics or self.op.disks or self.op.disk_template or
self.op.hvparams or self.op.beparams or self.op.os_name):
self.op.hvparams or self.op.beparams or self.op.os_name or
self.op.online_inst or self.op.offline_inst):
raise errors.OpPrereqError("No changes submitted", errors.ECODE_INVAL)
if self.op.hvparams:
......@@ -11449,6 +11450,16 @@ class LUInstanceSetParams(LogicalUnit):
(disk_op, len(instance.disks)),
errors.ECODE_INVAL)
# disabling the instance
if self.op.offline_inst:
_CheckInstanceState(self, instance, INSTANCE_DOWN,
msg="cannot change instance state to offline")
# enabling the instance
if self.op.online_inst:
_CheckInstanceState(self, instance, INSTANCE_OFFLINE,
msg="cannot make instance go online")
def _ConvertPlainToDrbd(self, feedback_fn):
"""Converts an instance from plain to drbd.
......@@ -11709,6 +11720,14 @@ class LUInstanceSetParams(LogicalUnit):
for key, val in self.op.osparams.iteritems():
result.append(("os/%s" % key, val))
# online/offline instance
if self.op.online_inst:
self.cfg.MarkInstanceDown(instance.name)
result.append(("admin_state", constants.ADMINST_DOWN))
if self.op.offline_inst:
self.cfg.MarkInstanceOffline(instance.name)
result.append(("admin_state", constants.ADMINST_OFFLINE))
self.cfg.Update(instance, feedback_fn)
assert not (self.owned_locks(locking.LEVEL_NODE_RES) or
......
......@@ -1193,7 +1193,14 @@ class ConfigWriter:
"""Mark the instance status to up in the config.
"""
self._SetInstanceStatus(instance_name, True)
self._SetInstanceStatus(instance_name, constants.ADMINST_UP)
@locking.ssynchronized(_config_lock)
def MarkInstanceOffline(self, instance_name):
"""Mark the instance status to down in the config.
"""
self._SetInstanceStatus(instance_name, constants.ADMINST_OFFLINE)
@locking.ssynchronized(_config_lock)
def RemoveInstance(self, instance_name):
......
......@@ -1351,6 +1351,10 @@ class OpInstanceSetParams(OpCode):
("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
("wait_for_sync", True, ht.TBool,
"Whether to wait for the disk to synchronize, when changing template"),
("offline_inst", False, ht.TBool,
"Whether to turn off the down instance completely"),
("online_inst", False, ht.TBool,
"Whether to enable the offline instance"),
]
OP_RESULT = _TSetParamsResult
......
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