beparams: add min/max memory values
authorGuido Trotter <ultrotter@google.com>
Thu, 10 Nov 2011 16:19:12 +0000 (16:19 +0000)
committerGuido Trotter <ultrotter@google.com>
Tue, 22 Nov 2011 14:52:54 +0000 (14:52 +0000)
For now the new "memory" parameter stays there, but it will be removed
later. The new values are just taken from the old one, in this patch.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/constants.py
lib/objects.py

index 7a19cfe..e65eef0 100644 (file)
@@ -860,12 +860,16 @@ DSS_PARAMETER_TYPES = {
 DSS_PARAMETERS = frozenset(DSS_PARAMETER_TYPES.keys())
 
 # Backend parameter names
-BE_MEMORY = "memory"
+BE_MEMORY = "memory" # deprecated and replaced by max and min mem
+BE_MAXMEM = "maxmem"
+BE_MINMEM = "minmem"
 BE_VCPUS = "vcpus"
 BE_AUTO_BALANCE = "auto_balance"
 
 BES_PARAMETER_TYPES = {
     BE_MEMORY: VTYPE_SIZE,
+    BE_MAXMEM: VTYPE_SIZE,
+    BE_MINMEM: VTYPE_SIZE,
     BE_VCPUS: VTYPE_INT,
     BE_AUTO_BALANCE: VTYPE_BOOL,
     }
@@ -1624,6 +1628,8 @@ HVC_GLOBALS = frozenset([
 
 BEC_DEFAULTS = {
   BE_MEMORY: 128,
+  BE_MINMEM: 128,
+  BE_MAXMEM: 128,
   BE_VCPUS: 1,
   BE_AUTO_BALANCE: True,
   }
index 0dad54c..c23068e 100644 (file)
@@ -96,6 +96,21 @@ def UpgradeGroupedParams(target, defaults):
   return target
 
 
+def UpgradeBeParams(target):
+  """Update the be parameters dict to the new format.
+
+  @type target: dict
+  @param target: "be" parameters dict
+
+  """
+  if constants.BE_MEMORY in target:
+    memory = target[constants.BE_MEMORY]
+    target[constants.BE_MAXMEM] = memory
+    target[constants.BE_MINMEM] = memory
+    #FIXME(dynmem): delete old value
+    #del target[constants.BE_MEMORY]
+
+
 class ConfigObject(object):
   """A generic config object.
 
@@ -912,6 +927,7 @@ class Instance(TaggableObject):
           pass
     if self.osparams is None:
       self.osparams = {}
+    UpgradeBeParams(self.beparams)
 
 
 class OS(ConfigObject):
@@ -1150,6 +1166,9 @@ class Cluster(TaggableObject):
 
     self.beparams = UpgradeGroupedParams(self.beparams,
                                          constants.BEC_DEFAULTS)
+    for beparams_group in self.beparams:
+      UpgradeBeParams(self.beparams[beparams_group])
+
     migrate_default_bridge = not self.nicparams
     self.nicparams = UpgradeGroupedParams(self.nicparams,
                                           constants.NICC_DEFAULTS)