Commit 10889e0c authored by René Nussbaumer's avatar René Nussbaumer
Browse files

gnt-instance: Adding instance policy to add


Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 1559e1e7
......@@ -2309,7 +2309,8 @@ def GenericInstanceCreate(mode, opts, args):
src_path=src_path,
tags=tags,
no_install=no_install,
identify_defaults=identify_defaults)
identify_defaults=identify_defaults,
ignore_ipolicy=opts.ignore_ipolicy)
SubmitOrSend(op, opts)
return 0
......
......@@ -1422,6 +1422,7 @@ add_opts = [
OS_OPT,
FORCE_VARIANT_OPT,
NO_INSTALL_OPT,
IGNORE_IPOLICY_OPT,
]
commands = {
......
......@@ -9394,7 +9394,7 @@ class LUInstanceCreate(LogicalUnit):
# pylint: disable=W0142
self.instance_file_storage_dir = utils.PathJoin(*joinargs)
 
def CheckPrereq(self):
def CheckPrereq(self): # pylint: disable=R0914
"""Check prerequisites.
 
"""
......@@ -9631,6 +9631,23 @@ class LUInstanceCreate(LogicalUnit):
 
nodenames = [pnode.name] + self.secondaries
 
# Verify instance specs
ispec = {
constants.ISPEC_MEM_SIZE: self.be_full.get(constants.BE_MAXMEM, None),
constants.ISPEC_CPU_COUNT: self.be_full.get(constants.BE_VCPUS, None),
constants.ISPEC_DISK_COUNT: len(self.disks),
constants.ISPEC_DISK_SIZE: [disk.size for disk in self.disks],
constants.ISPEC_NIC_COUNT: len(self.nics),
}
ipolicy = _CalculateGroupIPolicy(cluster, pnode.group)
res = _ComputeIPolicyInstanceSpecViolation(ipolicy, ispec)
if not self.op.ignore_ipolicy and res:
raise errors.OpPrereqError(("Instance allocation to group %s violates"
" policy: %s") % (pnode.group,
utils.CommaJoin(res)),
errors.ECODE_INVAL)
# disk parameters (not customizable at instance or node level)
# just use the primary node parameters, ignoring the secondary.
self.diskparams = self.cfg.GetNodeGroup(pnode.group).diskparams
......
......@@ -1086,6 +1086,7 @@ class OpInstanceCreate(OpCode):
_PForceVariant,
_PWaitForSync,
_PNameCheck,
_PIgnoreIpolicy,
("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"),
("disks", ht.NoDefault,
# TODO: Generate check from constants.IDISK_PARAMS_TYPES
......
......@@ -39,6 +39,7 @@ ADD
| {{-n|--node} *node[:secondary-node]* \| {-I|--iallocator} *name*}
| {{-o|--os-type} *os-type*}
| [--submit]
| [--ignore-ipolicy]
| {*instance*}
Creates a new instance on the specified host. The *instance* argument
......@@ -629,6 +630,9 @@ The ``--submit`` option is used to send the job to the master daemon
but not wait for its completion. The job ID will be shown so that it
can be examined via **gnt-job info**.
If ``--ignore-ipolicy`` is given any instance policy violations occuring
during this operation are ignored.
Example::
# gnt-instance add -t file --disk 0:size=30g -B maxmem=512 -o debian-etch \
......
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