def VerifyIpolicy(owner, ipolicy, iscluster, callback):
  """Checks if an ipolicy has correct form.

  @type owner: str
  @param owner: name of the object containing the attribute
  @type ipolicy: dict
  @param ipolicy: actual value of the ipolicy parameters
  @type iscluster: bool
  @param iscluster: True iff the owner is the cluster
  @type callback: callable
  @param callback: will be called if there is an error

  """
  try:
    objects.InstancePolicy.CheckParameterSyntax(ipolicy, iscluster)
  except errors.ConfigurationError, err:
    callback("%s has invalid instance policy: %s" % (owner, err))
  for key, value in ipolicy.items():
    if key == constants.ISPECS_MINMAX:
      for k in range(len(value)):
        VerifyIspecs(owner, "ipolicy/%s[%s]" % (key, k), value[k], callback)
    elif key == constants.ISPECS_STD:
      VerifyType(owner, "ipolicy/" + key, value,
                 constants.ISPECS_PARAMETER_TYPES, callback)
    else:
      # FIXME: assuming list type
      if key in constants.IPOLICY_PARAMETERS:
        exp_type = float
        # if the value is int, it can be converted into float
        convertible_types = [int]
      else:
        exp_type = list
        convertible_types = []
        # Try to convert from allowed types, if necessary.
        if any(isinstance(value, ct) for ct in convertible_types):
          try:
            value = exp_type(value)
            ipolicy[key] = value
          except __HOLE__:
            pass
        if not isinstance(value, exp_type):
          callback("%s has invalid instance policy: for %s,"
                   " expecting %s, got %s" %
                   (owner, key, exp_type.__name__, type(value)))
dataset/ETHPy150Open ganeti/ganeti/lib/config/verify.py/VerifyIpolicy