def VerifyIpolicy(owner, ipolicy, iscluster, callback):
  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 ValueError:
            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)))
A smarter {% if %} tag for django templates.
dataset/ETHPy150Open ganeti/ganeti/lib/config/verify.py/VerifyIpolicy--crossover with--dataset/ETHPy150Open skorokithakis/django-annoying/annoying/templatetags/smart_if.py/smart_if