From: Guido Trotter Date: Mon, 8 Jun 2009 10:27:26 +0000 (+0100) Subject: Abstract Param upgrade from cluster.UpgradeConfig X-Git-Tag: v2.1.0beta0~431^2~116 X-Git-Url: https://code.grnet.gr/git/ganeti-local/commitdiff_plain/6e34b628bfff359d4ed093b57c276525f0a7e1fa?ds=sidebyside Abstract Param upgrade from cluster.UpgradeConfig A new UpgradeGroupedParams is used to upgrade all the profiles for one parameter filling in the default values, or creating the whole dict anew, should it be missing. This is used only for beparams, currently, but will be used at least for nicparams and diskparams as well. Signed-off-by: Guido Trotter Reviewed-by: Iustin Pop --- diff --git a/lib/objects.py b/lib/objects.py index 729a8be..1a6178d 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -54,6 +54,24 @@ def FillDict(defaults_dict, custom_dict): ret_dict.update(custom_dict) return ret_dict + +def UpgradeGroupedParams(target, defaults): + """Update all groups for the target parameter. + + @type target: dict of dicts + @param target: {group: {parameter: value}} + @type defaults: dict + @param defaults: default parameter values + + """ + if target is None: + target = {constants.PP_DEFAULT: defaults} + else: + for group in target: + target[group] = FillDict(defaults, target[group]) + return target + + class ConfigObject(object): """A generic config object. @@ -763,12 +781,8 @@ class Cluster(TaggableObject): self.hvparams[hypervisor] = FillDict( constants.HVC_DEFAULTS[hypervisor], self.hvparams[hypervisor]) - if self.beparams is None: - self.beparams = {constants.PP_DEFAULT: constants.BEC_DEFAULTS} - else: - for begroup in self.beparams: - self.beparams[begroup] = FillDict(constants.BEC_DEFAULTS, - self.beparams[begroup]) + self.beparams = UpgradeGroupedParams(self.beparams, + constants.BEC_DEFAULTS) if self.modify_etc_hosts is None: self.modify_etc_hosts = True