commit a5728081faa3068dcb797a7ccccd9ce47c0b23e0
Author: Guido Trotter <ultrotter@google.com>
Date:   Tue Feb 10 15:06:24 2009 +0000

    Instance parameters: force typing
    
    We want all the hv/be parameters to have a known type, rather than a
    random mix of empty string, boolean values, and None, so we declare the
    type of each variable and we enforce/convert it.
    
    - Add some new constants for enforceable value types
    - Add new constants dicts HVS_PARAMETER_TYPES and BES_PARAMETER_TYPES
      holding not only the valid parameters but also their types
    - Drop the old HVS_PARAMETERS and BES_PARAMETERS constants and calculate
      the values from the type dict
    - Convert all the default parameters to a valid type value
    - Create a new ForceDictType utils function, to check/enforce a dict's
      element value types, with relevant unit tests
    - Drop a few custom functions to check/convert the BE param types in
      utils and cli, in favor of ForceDictType
    - Double-check the parameter types using ForceDictType in both scripts
      and LogicalUnits, when possible.
    
    As a bonus:
    - Remove some old commented-out code in gnt-instance
    - Remove some already fixed FIXME
    - Fix a bug which prevented VALUE_DEFAULT to be applied to BE parameters
      in SetInstanceParams because the value was checked for validity before
      that transformation was made
    - Fix a bug which prevented initing a cluster and passing hvparams to
      work at all
    - ForceDictType allows an allowed_values for exceptions, which makes us
      able to do the checking even when some values must not be
      converted/typechecked (for example the 'default' string in
      SetInstanceParameters)
    
    Reviewed-by: iustinp

diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index 4cbc30b..dea3e83 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -355,19 +355,8 @@ def AddInstance(opts, args):
                                    (didx, err))
       disks[didx] = ddict
 
-  ValidateBeParams(opts.beparams)
-
-##  kernel_path = _TransformPath(opts.kernel_path)
-##  initrd_path = _TransformPath(opts.initrd_path)
-
-##  hvm_acpi = opts.hvm_acpi == _VALUE_TRUE
-##  hvm_pae = opts.hvm_pae == _VALUE_TRUE
-
-##  if ((opts.hvm_cdrom_image_path is not None) and
-##      (opts.hvm_cdrom_image_path.lower() == constants.VALUE_NONE)):
-##    hvm_cdrom_image_path = None
-##  else:
-##    hvm_cdrom_image_path = opts.hvm_cdrom_image_path
+  utils.ForceDictType(opts.beparams, constants.BES_PARAMETER_TYPES)
+  utils.ForceDictType(opts.hvparams, constants.HVS_PARAMETER_TYPES)
 
   op = opcodes.OpCreateInstance(instance_name=instance,
                                 disks=disks,
@@ -492,6 +481,9 @@ def BatchCreate(opts, args):
 
     nic0 = {'ip': specs['ip'], 'bridge': specs['bridge'], 'mac': specs['mac']}
 
+    utils.ForceDictType(specs['backend'], constants.BES_PARAMETER_TYPES)
+    utils.ForceDictType(hvparams, constants.HVS_PARAMETER_TYPES)
+
     op = opcodes.OpCreateInstance(instance_name=name,
                                   disks=disks,
                                   disk_template=specs['template'],
@@ -1187,18 +1179,17 @@ def SetInstanceParams(opts, args):
     if isinstance(opts.beparams[param], basestring):
       if opts.beparams[param].lower() == "default":
         opts.beparams[param] = constants.VALUE_DEFAULT
-      elif opts.beparams[param].lower() == "none":
-        opts.beparams[param] = constants.VALUE_NONE
-      elif param == constants.BE_MEMORY:
-        opts.beparams[constants.BE_MEMORY] = \
-          utils.ParseUnit(opts.beparams[constants.BE_MEMORY])
+
+  utils.ForceDictType(opts.beparams, constants.BES_PARAMETER_TYPES,
+                      allowed_values=[constants.VALUE_DEFAULT])
 
   for param in opts.hypervisor:
     if isinstance(opts.hypervisor[param], basestring):
       if opts.hypervisor[param].lower() == "default":
         opts.hypervisor[param] = constants.VALUE_DEFAULT
-      elif opts.hypervisor[param].lower() == "none":
-        opts.hypervisor[param] = constants.VALUE_NONE
+
+  utils.ForceDictType(opts.hypervisor, constants.HVS_PARAMETER_TYPES,
+                      allowed_values=[constants.VALUE_DEFAULT])
 
   for idx, (nic_op, nic_dict) in enumerate(opts.nics):
     try:
