Commit 1052d622 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add support for modifying instance OS parameters



We move the instance OS rename checks earlier, as we need to run the
validation against the new OS, if it has changed.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 625ac113
......@@ -8330,6 +8330,8 @@ class LUSetInstanceParams(LogicalUnit):
self.op.os_name = None
if not hasattr(self.op, "force_variant"):
self.op.force_variant = False
if not hasattr(self.op, "osparams"):
self.op.osparams = None
self.op.force = getattr(self.op, "force", False)
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):
......@@ -8528,6 +8530,14 @@ class LUSetInstanceParams(LogicalUnit):
pnode = instance.primary_node
nodelist = list(instance.all_nodes)
# OS change
if self.op.os_name and not self.op.force:
_CheckNodeHasOS(self, instance.primary_node, self.op.os_name,
self.op.force_variant)
instance_os = self.op.os_name
else:
instance_os = instance.os
if self.op.disk_template:
if instance.disk_template == self.op.disk_template:
raise errors.OpPrereqError("Instance already has disk template %s" %
......@@ -8564,7 +8574,8 @@ class LUSetInstanceParams(LogicalUnit):
# beparams processing
if self.op.beparams:
i_bedict = _GetUpdatedParams(instance.beparams, self.op.beparams)
i_bedict = _GetUpdatedParams(instance.beparams, self.op.beparams,
use_none=True)
utils.ForceDictType(i_bedict, constants.BES_PARAMETER_TYPES)
be_new = cluster.SimpleFillBE(i_bedict)
self.be_new = be_new # the new actual values
......@@ -8572,6 +8583,15 @@ class LUSetInstanceParams(LogicalUnit):
else:
self.be_new = self.be_inst = {}
# osparams processing
if self.op.osparams:
i_osdict = _GetUpdatedParams(instance.osparams, self.op.osparams)
_CheckOSParams(self, True, nodelist, instance_os, i_osdict)
self.os_new = cluster.SimpleFillOS(instance_os, i_osdict)
self.os_inst = i_osdict # the new dict (without defaults)
else:
self.os_new = self.os_inst = {}
self.warn = []
if constants.BE_MEMORY in self.op.beparams and not self.force:
......@@ -8727,11 +8747,6 @@ class LUSetInstanceParams(LogicalUnit):
(disk_op, len(instance.disks)),
errors.ECODE_INVAL)
# OS change
if self.op.os_name and not self.op.force:
_CheckNodeHasOS(self, instance.primary_node, self.op.os_name,
self.op.force_variant)
return
def _ConvertPlainToDrbd(self, feedback_fn):
......@@ -8946,6 +8961,12 @@ class LUSetInstanceParams(LogicalUnit):
if self.op.os_name:
instance.os = self.op.os_name
# osparams changes
if self.op.osparams:
instance.osparams = self.os_inst
for key, val in self.op.osparams.iteritems():
result.append(("os/%s" % key, val))
self.cfg.Update(instance, feedback_fn)
return result
......
......@@ -636,7 +636,7 @@ class OpSetInstanceParams(OpCode):
OP_DSC_FIELD = "instance_name"
__slots__ = [
"instance_name",
"hvparams", "beparams", "force",
"hvparams", "beparams", "osparams", "force",
"nics", "disks", "disk_template",
"remote_node", "os_name", "force_variant",
]
......
......@@ -1236,7 +1236,7 @@ def SetInstanceParams(opts, args):
"""
if not (opts.nics or opts.disks or opts.disk_template or
opts.hvparams or opts.beparams or opts.os):
opts.hvparams or opts.beparams or opts.os or opts.osparams):
ToStderr("Please give at least one of the parameters.")
return 1
......@@ -1290,6 +1290,7 @@ def SetInstanceParams(opts, args):
hvparams=opts.hvparams,
beparams=opts.beparams,
os_name=opts.os,
osparams=opts.osparams,
force_variant=opts.force_variant,
force=opts.force)
......@@ -1449,7 +1450,8 @@ commands = {
'modify': (
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],
DISK_TEMPLATE_OPT, SINGLE_NODE_OPT, OS_OPT, FORCE_VARIANT_OPT,
OSPARAMS_OPT],
"<instance>", "Alters the parameters of an instance"),
'shutdown': (
GenericManyOps("shutdown", _ShutdownInstance), [ArgInstance()],
......
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