Commit d04aaa2f authored by Iustin Pop's avatar Iustin Pop
Browse files

Add -H/-B startup parameters to gnt-instance

This patch modifies the start instance script, opcode and logical unit
to support temporary startup parameters.

Different from 1.2, where only the kernel arguments were supporting
changes (and thus xen-pvm specific), this version supports changing all
hypervisor and backend parameters (with appropriate checks).

This is much more flexible, and allows for example:
  - start with different, temporary kernel
  - start with different memory size

Note: in later versions, this should be extended to cover disk
parameters as well (e.g. start with drbd without flushes, start with
drbd in async mode, etc.).
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarGuido Trotter <>
parent 0eca8e0c
......@@ -2761,6 +2761,34 @@ class LUStartupInstance(LogicalUnit):
assert self.instance is not None, \
"Cannot retrieve locked instance %s" % self.op.instance_name
# extra beparams
self.beparams = getattr(self.op, "beparams", {})
if self.beparams:
if not isinstance(self.beparams, dict):
raise errors.OpPrereqError("Invalid beparams passed: %s, expected"
" dict" % (type(self.beparams), ))
# fill the beparams dict
utils.ForceDictType(self.beparams, constants.BES_PARAMETER_TYPES)
self.op.beparams = self.beparams
# extra hvparams
self.hvparams = getattr(self.op, "hvparams", {})
if self.hvparams:
if not isinstance(self.hvparams, dict):
raise errors.OpPrereqError("Invalid hvparams passed: %s, expected"
" dict" % (type(self.hvparams), ))
# check hypervisor parameter syntax (locally)
cluster = self.cfg.GetClusterInfo()
utils.ForceDictType(self.hvparams, constants.HVS_PARAMETER_TYPES)
filled_hvp = cluster.FillDict(cluster.hvparams[instance.hypervisor],
hv_type = hypervisor.GetHypervisor(instance.hypervisor)
_CheckHVParams(self, instance.all_nodes, instance.hypervisor, filled_hvp)
self.op.hvparams = self.hvparams
_CheckNodeOnline(self, instance.primary_node)
bep = self.cfg.GetClusterInfo().FillBE(instance)
......@@ -2789,7 +2817,8 @@ class LUStartupInstance(LogicalUnit):
_StartInstanceDisks(self, instance, force)
result = self.rpc.call_instance_start(node_current, instance, None, None)
result = self.rpc.call_instance_start(node_current, instance,
self.hvparams, self.beparams)
msg = result.RemoteFailMsg()
if msg:
_ShutdownInstanceDisks(self, instance)
......@@ -382,7 +382,7 @@ class OpStartupInstance(OpCode):
"""Startup an instance."""
OP_DSC_FIELD = "instance_name"
__slots__ = ["instance_name", "force"]
__slots__ = ["instance_name", "force", "hvparams", "beparams"]
class OpShutdownInstance(OpCode):
......@@ -1127,7 +1127,7 @@ instance5: 11225
Show detailed information about the given instance(s). This is
different from <command>list</command> as it shows detailed data
about the instance's disks (especially useful for the drbd disk
about the instance's disks (especially useful for the drbd disk
......@@ -1314,6 +1314,9 @@ instance5: 11225
<arg>-H <option>key=value...</option></arg>
<arg>-B <option>key=value...</option></arg>
<arg choice="opt"
......@@ -1382,6 +1385,23 @@ instance5: 11225
instance will be affected.
The <option>-H</option> and <option>-B</option> options
specify extra, temporary hypervisor and backend parameters
that can be used to start an instance with modified
parameters. They can be useful for quick testing without
having to modify an instance back and forth, e.g.:
# gnt-instance start -H root_args="single" instance1
# gnt-instance start -B memory=2048 instance2
The first form will start the instance
<userinput>instance1</userinput> in single-user mode, and
the instance <userinput>instance2</userinput> with 2GB of
RAM (this time only, unless that is the actual instance
memory size already).
The <option>--submit</option> option is used to send the job to
the master daemon but not wait for its completion. The job
......@@ -710,6 +710,11 @@ def StartupInstance(opts, args):
for name in inames:
op = opcodes.OpStartupInstance(instance_name=name,
# do not add these parameters to the opcode unless they're defined
if opts.hvparams:
op.hvparams = opts.hvparams
if opts.beparams:
op.beparams = opts.beparams
jex.QueueJob(name, op)
jex.WaitOrShow(not opts.submit_only)
return 0
......@@ -1472,8 +1477,14 @@ commands = {
m_node_opt, m_pri_node_opt, m_sec_node_opt,
m_clust_opt, m_inst_opt,
keyval_option("-H", "--hypervisor", type="keyval",
default={}, dest="hvparams",
help="Temporary hypervisor parameters"),
keyval_option("-B", "--backend", type="keyval",
default={}, dest="beparams",
help="Temporary backend parameters"),
"<instance>", "Starts an instance"),
"<instance>", "Starts an instance"),
'reboot': (RebootInstance, ARGS_ANY,
[DEBUG_OPT, m_force_multi,
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