Revision ff6c5e55

b/lib/client/gnt_cluster.py
468 468
    _PrintGroupedParams(result["ipolicy"][key], roman=opts.roman_integers)
469 469
  ToStdout("  - enabled disk templates: %s",
470 470
           utils.CommaJoin(result["ipolicy"][constants.IPOLICY_DTS]))
471
  for key in constants.IPOLICY_PARAMETERS:
472
    ToStdout("  - %s: %s", key, result["ipolicy"][key])
471 473

  
472 474
  return 0
473 475

  
b/lib/cmdlib.py
740 740
                                       use_none=use_none,
741 741
                                       use_default=use_default)
742 742
    else:
743
      # FIXME: we assume all others are lists; this should be redone
744
      # in a nicer way
745 743
      if not value or value == [constants.VALUE_DEFAULT]:
746 744
        if group_policy:
747 745
          del ipolicy[key]
......
750 748
                                     " on the cluster'" % key,
751 749
                                     errors.ECODE_INVAL)
752 750
      else:
753
        ipolicy[key] = list(value)
751
        if key in constants.IPOLICY_PARAMETERS:
752
          # FIXME: we assume all such values are float
753
          try:
754
            ipolicy[key] = float(value)
755
          except (TypeError, ValueError), err:
756
            raise errors.OpPrereqError("Invalid value for attribute"
757
                                       " '%s': '%s', error: %s" %
758
                                       (key, value, err), errors.ECODE_INVAL)
759
        else:
760
          # FIXME: we assume all others are lists; this should be redone
761
          # in a nicer way
762
          ipolicy[key] = list(value)
754 763
  try:
755 764
    objects.InstancePolicy.CheckParameterSyntax(ipolicy)
756 765
  except errors.ConfigurationError, err:
b/lib/config.py
439 439
          _helper(owner, fullkey, value, constants.ISPECS_PARAMETER_TYPES)
440 440
        else:
441 441
          # FIXME: assuming list type
442
          if not isinstance(value, list):
442
          if key in constants.IPOLICY_PARAMETERS:
443
            exp_type = float
444
          else:
445
            exp_type = list
446
          if not isinstance(value, exp_type):
443 447
            result.append("%s has invalid instance policy: for %s,"
444
                          " expecting list, got %s" %
445
                          (owner, key, type(value)))
448
                          " expecting %s, got %s" %
449
                          (owner, key, exp_type.__name__, type(value)))
446 450

  
447 451
    # check cluster parameters
448 452
    _helper("cluster", "beparams", cluster.SimpleFillBE({}),
b/lib/constants.py
950 950
ISPECS_MAX = "max"
951 951
ISPECS_STD = "std"
952 952
IPOLICY_DTS = "disk_templates"
953
IPOLICY_VCPU_RATIO = "vcpu_ratio"
953 954

  
954 955
IPOLICY_ISPECS = frozenset([
955 956
  ISPECS_MIN,
956 957
  ISPECS_MAX,
957 958
  ISPECS_STD,
958 959
  ])
959
IPOLICY_ALL_KEYS = IPOLICY_ISPECS.union([IPOLICY_DTS])
960

  
961
IPOLICY_PARAMETERS = frozenset([
962
  IPOLICY_VCPU_RATIO,
963
  ])
964

  
965
IPOLICY_ALL_KEYS = (IPOLICY_ISPECS |
966
                    IPOLICY_PARAMETERS |
967
                    frozenset([IPOLICY_DTS]))
960 968

  
961 969
# Node parameter names
962 970
ND_OOB_PROGRAM = "oob_program"
......
1907 1915
    ISPEC_NIC_COUNT: 1,
1908 1916
    },
1909 1917
  IPOLICY_DTS: DISK_TEMPLATES,
1918
  IPOLICY_VCPU_RATIO: 4.0,
1910 1919
  }
1911 1920

  
1912 1921
MASTER_POOL_SIZE_DEFAULT = 10
b/lib/objects.py
105 105
  # list items
106 106
  for key in [constants.IPOLICY_DTS]:
107 107
    ret_dict[key] = list(custom_ipolicy.get(key, default_ipolicy[key]))
108
  # other items which we know we can directly copy (immutables)
109
  for key in constants.IPOLICY_PARAMETERS:
110
    ret_dict[key] = custom_ipolicy.get(key, default_ipolicy[key])
108 111

  
109 112
  return ret_dict
110 113

  
......
908 911
      InstancePolicy.CheckISpecSyntax(ipolicy, param)
909 912
    if constants.IPOLICY_DTS in ipolicy:
910 913
      InstancePolicy.CheckDiskTemplates(ipolicy[constants.IPOLICY_DTS])
914
    for key in constants.IPOLICY_PARAMETERS:
915
      if key in ipolicy:
916
        InstancePolicy.CheckParameter(key, ipolicy[key])
911 917
    wrong_keys = frozenset(ipolicy.keys()) - constants.IPOLICY_ALL_KEYS
912 918
    if wrong_keys:
913 919
      raise errors.ConfigurationError("Invalid keys in ipolicy: %s" %
......
948 954
      raise errors.ConfigurationError("Invalid disk template(s) %s" %
949 955
                                      utils.CommaJoin(wrong))
950 956

  
957
  @classmethod
958
  def CheckParameter(cls, key, value):
959
    """Checks a parameter.
960

  
961
    Currently we expect all parameters to be float values.
962

  
963
    """
964
    try:
965
      float(value)
966
    except (TypeError, ValueError), err:
967
      raise errors.ConfigurationError("Invalid value for key" " '%s':"
968
                                      " '%s', error: %s" % (key, value, err))
969

  
951 970

  
952 971
class Instance(TaggableObject):
953 972
  """Config object representing an instance."""

Also available in: Unified diff