Abstract Param upgrade from cluster.UpgradeConfig
authorGuido Trotter <ultrotter@google.com>
Mon, 8 Jun 2009 10:27:26 +0000 (11:27 +0100)
committerGuido Trotter <ultrotter@google.com>
Mon, 8 Jun 2009 16:58:32 +0000 (17:58 +0100)
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 <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/objects.py

index 729a8be..1a6178d 100644 (file)
@@ -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