Revision 62fed51b lib/objects.py

b/lib/objects.py
942 942
    @raise errors.ConfigurationError: when the policy is not legal
943 943

  
944 944
    """
945
    if constants.ISPECS_MINMAX in ipolicy:
946
      if check_std and constants.ISPECS_STD not in ipolicy:
947
        msg = "Missing key in ipolicy: %s" % constants.ISPECS_STD
948
        raise errors.ConfigurationError(msg)
949
      minmaxspecs = ipolicy[constants.ISPECS_MINMAX]
950
      stdspec = ipolicy.get(constants.ISPECS_STD)
951
      for param in constants.ISPECS_PARAMETERS:
952
        InstancePolicy.CheckISpecSyntax(minmaxspecs, stdspec, param, check_std)
945
    InstancePolicy.CheckISpecSyntax(ipolicy, check_std)
953 946
    if constants.IPOLICY_DTS in ipolicy:
954 947
      InstancePolicy.CheckDiskTemplates(ipolicy[constants.IPOLICY_DTS])
955 948
    for key in constants.IPOLICY_PARAMETERS:
......
961 954
                                      utils.CommaJoin(wrong_keys))
962 955

  
963 956
  @classmethod
964
  def CheckISpecSyntax(cls, minmaxspecs, stdspec, name, check_std):
957
  def CheckISpecSyntax(cls, ipolicy, check_std):
958
    """Check the instance policy specs for validity.
959

  
960
    @type ipolicy: dict
961
    @param ipolicy: dictionary with min/max/std specs
962
    @type check_std: bool
963
    @param check_std: Whether to check std value or just assume compliance
964
    @raise errors.ConfigurationError: when specs are not valid
965

  
966
    """
967
    if constants.ISPECS_MINMAX not in ipolicy:
968
      # Nothing to check
969
      return
970

  
971
    if check_std and constants.ISPECS_STD not in ipolicy:
972
      msg = "Missing key in ipolicy: %s" % constants.ISPECS_STD
973
      raise errors.ConfigurationError(msg)
974
    minmaxspecs = ipolicy[constants.ISPECS_MINMAX]
975
    stdspec = ipolicy.get(constants.ISPECS_STD)
976
    missing = constants.ISPECS_MINMAX_KEYS - frozenset(minmaxspecs.keys())
977
    if missing:
978
      msg = "Missing instance specification: %s" % utils.CommaJoin(missing)
979
      raise errors.ConfigurationError(msg)
980
    for param in constants.ISPECS_PARAMETERS:
981
      InstancePolicy._CheckISpecParamSyntax(minmaxspecs, stdspec, param,
982
                                            check_std)
983

  
984
  @classmethod
985
  def _CheckISpecParamSyntax(cls, minmaxspecs, stdspec, name, check_std):
965 986
    """Check the instance policy specs for validity on a given key.
966 987

  
967 988
    We check if the instance specs makes sense for a given key, that is
......
979 1000
        valid
980 1001

  
981 1002
    """
982
    missing = constants.ISPECS_MINMAX_KEYS - frozenset(minmaxspecs.keys())
983
    if missing:
984
      msg = "Missing instance specification: %s" % utils.CommaJoin(missing)
985
      raise errors.ConfigurationError(msg)
986

  
987 1003
    minspec = minmaxspecs[constants.ISPECS_MIN]
988 1004
    maxspec = minmaxspecs[constants.ISPECS_MAX]
989 1005
    min_v = minspec.get(name, 0)

Also available in: Unified diff