Commit fb644e77 authored by Agata Murawska's avatar Agata Murawska
Browse files

GroupSetParam supports instance policy changes


Signed-off-by: default avatarAgata Murawska <agatamurawska@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 1f5d9bf8
......@@ -146,8 +146,11 @@ def SetGroupParams(opts, args):
@return: the desired exit code
"""
if (opts.ndparams is None and opts.alloc_policy is None
and not opts.diskparams and not opts.hv_state and not opts.disk_state):
allmods = [opts.ndparams, opts.alloc_policy, opts.diskparams, opts.hv_state,
opts.disk_state, opts.ispecs_mem_size, opts.ispecs_cpu_count,
opts.ispecs_disk_count, opts.ispecs_disk_size,
opts.ispecs_nic_count, opts.diskparams]
if allmods.count(None) == len(allmods):
ToStderr("Please give at least one of the parameters.")
return 1
......@@ -159,12 +162,41 @@ def SetGroupParams(opts, args):
hv_state = dict(opts.hv_state)
diskparams = dict(opts.diskparams)
# set the default values
to_ipolicy = [
opts.ispecs_mem_size,
opts.ispecs_cpu_count,
opts.ispecs_disk_count,
opts.ispecs_disk_size,
opts.ispecs_nic_count,
]
for ispec in to_ipolicy:
for param in ispec:
if isinstance(ispec[param], basestring):
if ispec[param].lower() == "default":
ispec[param] = constants.VALUE_DEFAULT
# create ipolicy object
ipolicy = objects.CreateIPolicyFromOpts(\
ispecs_mem_size=opts.ispecs_mem_size,
ispecs_cpu_count=opts.ispecs_cpu_count,
ispecs_disk_count=opts.ispecs_disk_count,
ispecs_disk_size=opts.ispecs_disk_size,
ispecs_nic_count=opts.ispecs_nic_count,
group_ipolicy=True,
allowed_values=[constants.VALUE_DEFAULT])
for key in ipolicy.keys():
utils.ForceDictType(ipolicy[key], constants.ISPECS_PARAMETER_TYPES,
allowed_values=[constants.VALUE_DEFAULT])
op = opcodes.OpGroupSetParams(group_name=args[0],
ndparams=opts.ndparams,
alloc_policy=opts.alloc_policy,
hv_state=hv_state,
disk_state=disk_state,
diskparams=diskparams)
diskparams=diskparams,
ipolicy=ipolicy)
result = SubmitOrSend(op, opts)
if result:
......@@ -266,7 +298,7 @@ commands = {
"modify": (
SetGroupParams, ARGS_ONE_GROUP,
[DRY_RUN_OPT, SUBMIT_OPT, ALLOC_POLICY_OPT, NODE_PARAMS_OPT, HV_STATE_OPT,
DISK_STATE_OPT, DISK_PARAMS_OPT],
DISK_STATE_OPT, DISK_PARAMS_OPT] + INSTANCE_POLICY_OPTS,
"<group_name>", "Alters the parameters of a node group"),
"remove": (
RemoveGroup, ARGS_ONE_GROUP, [DRY_RUN_OPT],
......
......@@ -13068,7 +13068,8 @@ class LUGroupSetParams(LogicalUnit):
self.op.diskparams,
self.op.alloc_policy,
self.op.hv_state,
self.op.disk_state
self.op.disk_state,
self.op.ipolicy,
]
 
if all_changes.count(None) == len(all_changes):
......@@ -13117,6 +13118,16 @@ class LUGroupSetParams(LogicalUnit):
_MergeAndVerifyDiskState(self.op.disk_state,
self.group.disk_state_static)
 
if self.op.ipolicy:
g_ipolicy = {}
for key, value in self.op.ipolicy.iteritems():
g_ipolicy[key] = _GetUpdatedParams(self.group.ipolicy.get(key, {}),
value,
use_none=True)
utils.ForceDictType(g_ipolicy[key], constants.ISPECS_PARAMETER_TYPES)
self.new_ipolicy = g_ipolicy
objects.InstancePolicy.CheckParameterSyntax(self.new_ipolicy)
def BuildHooksEnv(self):
"""Build hooks env.
 
......@@ -13156,6 +13167,9 @@ class LUGroupSetParams(LogicalUnit):
if self.op.disk_state:
self.group.disk_state_static = self.new_disk_state
 
if self.op.ipolicy:
self.group.ipolicy = self.new_ipolicy
self.cfg.Update(self.group, feedback_fn)
return result
 
......
......@@ -1446,6 +1446,7 @@ class OpGroupSetParams(OpCode):
_PDiskParams,
_PHvState,
_PDiskState,
("ipolicy", None, ht.TMaybeDict, "Group-wide instance policy specs"),
]
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