Commit d948c101 authored by Bernardo Dal Seno's avatar Bernardo Dal Seno
Browse files

Refactor cli.CreateIPolicyFromOpts()



The code relative to instance specs has been moved into a different
function. This in preparation for further patches to have a more clear code
structure.
Signed-off-by: default avatarBernardo Dal Seno <bdalseno@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent eeaa5f6c
......@@ -3685,24 +3685,9 @@ def _MaybeParseUnit(elements):
return parsed
def CreateIPolicyFromOpts(ispecs_mem_size=None,
ispecs_cpu_count=None,
ispecs_disk_count=None,
ispecs_disk_size=None,
ispecs_nic_count=None,
ipolicy_disk_templates=None,
ipolicy_vcpu_ratio=None,
ipolicy_spindle_ratio=None,
group_ipolicy=False,
allowed_values=None,
fill_all=False):
"""Creation of instance policy based on command line options.
@param fill_all: whether for cluster policies we should ensure that
all values are filled
"""
def _InitIspecsFromOpts(ipolicy, ispecs_mem_size, ispecs_cpu_count,
ispecs_disk_count, ispecs_disk_size, ispecs_nic_count,
group_ipolicy, allowed_values):
try:
if ispecs_mem_size:
ispecs_mem_size = _MaybeParseUnit(ispecs_mem_size)
......@@ -3715,7 +3700,7 @@ def CreateIPolicyFromOpts(ispecs_mem_size=None,
errors.ECODE_INVAL)
# prepare ipolicy dict
ipolicy_transposed = {
ispecs_transposed = {
constants.ISPEC_MEM_SIZE: ispecs_mem_size,
constants.ISPEC_CPU_COUNT: ispecs_cpu_count,
constants.ISPEC_DISK_COUNT: ispecs_disk_count,
......@@ -3728,16 +3713,39 @@ def CreateIPolicyFromOpts(ispecs_mem_size=None,
forced_type = TISPECS_GROUP_TYPES
else:
forced_type = TISPECS_CLUSTER_TYPES
for specs in ipolicy_transposed.values():
for specs in ispecs_transposed.values():
utils.ForceDictType(specs, forced_type, allowed_values=allowed_values)
# then transpose
ipolicy_out = objects.MakeEmptyIPolicy()
for name, specs in ipolicy_transposed.iteritems():
for (name, specs) in ispecs_transposed.iteritems():
assert name in constants.ISPECS_PARAMETERS
for key, val in specs.items(): # {min: .. ,max: .., std: ..}
ipolicy_out[key][name] = val
ipolicy[key][name] = val
def CreateIPolicyFromOpts(ispecs_mem_size=None,
ispecs_cpu_count=None,
ispecs_disk_count=None,
ispecs_disk_size=None,
ispecs_nic_count=None,
ipolicy_disk_templates=None,
ipolicy_vcpu_ratio=None,
ipolicy_spindle_ratio=None,
group_ipolicy=False,
allowed_values=None,
fill_all=False):
"""Creation of instance policy based on command line options.
@param fill_all: whether for cluster policies we should ensure that
all values are filled
"""
ipolicy_out = objects.MakeEmptyIPolicy()
_InitIspecsFromOpts(ipolicy_out, ispecs_mem_size, ispecs_cpu_count,
ispecs_disk_count, ispecs_disk_size, ispecs_nic_count,
group_ipolicy, allowed_values)
if ipolicy_disk_templates is not None:
ipolicy_out[constants.IPOLICY_DTS] = list(ipolicy_disk_templates)
......
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