From 6e34b628bfff359d4ed093b57c276525f0a7e1fa Mon Sep 17 00:00:00 2001 From: Guido Trotter Date: Mon, 8 Jun 2009 11:27:26 +0100 Subject: [PATCH] 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 --- lib/objects.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) 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 -- 1.7.10.4