"NOVOTING_OPT",
"NO_REMEMBER_OPT",
"NWSYNC_OPT",
+ "OFFLINE_INST_OPT",
+ "ONLINE_INST_OPT",
"ON_PRIMARY_OPT",
"ON_SECONDARY_OPT",
"OFFLINE_OPT",
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)),
"""
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
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)
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()],
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:
(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.
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
"""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):
("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