Commit abe609b2 authored by Guido Trotter's avatar Guido Trotter
Browse files

Move FillDict at module level



This way it can be also used by scripts and other object types.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 022c3a0b
......@@ -1489,11 +1489,11 @@ class LUSetClusterParams(LogicalUnit):
# validate beparams changes
if self.op.beparams:
utils.ForceDictType(self.op.beparams, constants.BES_PARAMETER_TYPES)
self.new_beparams = cluster.FillDict(
self.new_beparams = objects.FillDict(
cluster.beparams[constants.BEGR_DEFAULT], self.op.beparams)
# hypervisor list/parameters
self.new_hvparams = cluster.FillDict(cluster.hvparams, {})
self.new_hvparams = objects.FillDict(cluster.hvparams, {})
if self.op.hvparams:
if not isinstance(self.op.hvparams, dict):
raise errors.OpPrereqError("Invalid 'hvparams' parameter on input")
......@@ -2848,7 +2848,7 @@ class LUStartupInstance(LogicalUnit):
# 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],
filled_hvp = objects.FillDict(cluster.hvparams[instance.hypervisor],
instance.hvparams)
filled_hvp.update(self.hvparams)
hv_type = hypervisor.GetHypervisor(instance.hypervisor)
......@@ -4404,14 +4404,14 @@ class LUCreateInstance(LogicalUnit):
# check hypervisor parameter syntax (locally)
utils.ForceDictType(self.op.hvparams, constants.HVS_PARAMETER_TYPES)
filled_hvp = cluster.FillDict(cluster.hvparams[self.op.hypervisor],
filled_hvp = objects.FillDict(cluster.hvparams[self.op.hypervisor],
self.op.hvparams)
hv_type = hypervisor.GetHypervisor(self.op.hypervisor)
hv_type.CheckParameterSyntax(filled_hvp)
# fill and remember the beparams dict
utils.ForceDictType(self.op.beparams, constants.BES_PARAMETER_TYPES)
self.be_full = cluster.FillDict(cluster.beparams[constants.BEGR_DEFAULT],
self.be_full = objects.FillDict(cluster.beparams[constants.BEGR_DEFAULT],
self.op.beparams)
#### instance parameters check
......@@ -5963,7 +5963,7 @@ class LUSetInstanceParams(LogicalUnit):
i_hvdict[key] = val
cluster = self.cfg.GetClusterInfo()
utils.ForceDictType(i_hvdict, constants.HVS_PARAMETER_TYPES)
hv_new = cluster.FillDict(cluster.hvparams[instance.hypervisor],
hv_new = objects.FillDict(cluster.hvparams[instance.hypervisor],
i_hvdict)
# local check
hypervisor.GetHypervisor(
......@@ -5987,7 +5987,7 @@ class LUSetInstanceParams(LogicalUnit):
i_bedict[key] = val
cluster = self.cfg.GetClusterInfo()
utils.ForceDictType(i_bedict, constants.BES_PARAMETER_TYPES)
be_new = cluster.FillDict(cluster.beparams[constants.BEGR_DEFAULT],
be_new = objects.FillDict(cluster.beparams[constants.BEGR_DEFAULT],
i_bedict)
self.be_new = be_new # the new actual values
self.be_inst = i_bedict # the new dict (without defaults)
......
......@@ -37,8 +37,22 @@ from ganeti import constants
__all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance",
"OS", "Node", "Cluster"]
"OS", "Node", "Cluster", "FillDict"]
def FillDict(defaults_dict, custom_dict):
"""Basic function to apply settings on top a default dict.
@type defaults_dict: dict
@param defaults_dict: dictionary holding the default values
@type custom_dict: dict
@param custom_dict: dictionary holding customized value
@rtype: dict
@return: dict with the 'full' values
"""
ret_dict = copy.deepcopy(defaults_dict)
ret_dict.update(custom_dict)
return ret_dict
class ConfigObject(object):
"""A generic config object.
......@@ -746,14 +760,14 @@ class Cluster(TaggableObject):
self.hvparams = constants.HVC_DEFAULTS
else:
for hypervisor in self.hvparams:
self.hvparams[hypervisor] = self.FillDict(
self.hvparams[hypervisor] = FillDict(
constants.HVC_DEFAULTS[hypervisor], self.hvparams[hypervisor])
if self.beparams is None:
self.beparams = {constants.BEGR_DEFAULT: constants.BEC_DEFAULTS}
else:
for begroup in self.beparams:
self.beparams[begroup] = self.FillDict(constants.BEC_DEFAULTS,
self.beparams[begroup] = FillDict(constants.BEC_DEFAULTS,
self.beparams[begroup])
if self.modify_etc_hosts is None:
......@@ -777,22 +791,6 @@ class Cluster(TaggableObject):
obj.tcpudp_port_pool = set(obj.tcpudp_port_pool)
return obj
@staticmethod
def FillDict(defaults_dict, custom_dict):
"""Basic function to apply settings on top a default dict.
@type defaults_dict: dict
@param defaults_dict: dictionary holding the default values
@type custom_dict: dict
@param custom_dict: dictionary holding customized value
@rtype: dict
@return: dict with the 'full' values
"""
ret_dict = copy.deepcopy(defaults_dict)
ret_dict.update(custom_dict)
return ret_dict
def FillHV(self, instance):
"""Fill an instance's hvparams dict.
......@@ -803,7 +801,7 @@ class Cluster(TaggableObject):
the cluster defaults
"""
return self.FillDict(self.hvparams.get(instance.hypervisor, {}),
return FillDict(self.hvparams.get(instance.hypervisor, {}),
instance.hvparams)
def FillBE(self, instance):
......@@ -816,7 +814,7 @@ class Cluster(TaggableObject):
the cluster defaults
"""
return self.FillDict(self.beparams.get(constants.BEGR_DEFAULT, {}),
return FillDict(self.beparams.get(constants.BEGR_DEFAULT, {}),
instance.beparams)
......
......@@ -1135,6 +1135,6 @@ class RpcRunner(object):
"""
cluster = self._cfg.GetClusterInfo()
hv_full = cluster.FillDict(cluster.hvparams.get(hvname, {}), hvparams)
hv_full = objects.FillDict(cluster.hvparams.get(hvname, {}), hvparams)
return self._MultiNodeCall(node_list, "hypervisor_validate_params",
[hvname, hv_full])
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