+ @param ipolicy: dictionary with min/max/std specs
+ @type check_std: bool
+ @param check_std: Whether to check std value or just assume compliance
+ @raise errors.ConfigurationError: when specs are not valid
+
+ """
+ if constants.ISPECS_MINMAX not in ipolicy:
+ # Nothing to check
+ return
+
+ if check_std and constants.ISPECS_STD not in ipolicy:
+ msg = "Missing key in ipolicy: %s" % constants.ISPECS_STD
+ raise errors.ConfigurationError(msg)
+ stdspec = ipolicy.get(constants.ISPECS_STD)
+ if check_std:
+ InstancePolicy._CheckIncompleteSpec(stdspec, constants.ISPECS_STD)
+
+ if not ipolicy[constants.ISPECS_MINMAX]:
+ raise errors.ConfigurationError("Empty minmax specifications")
+ std_is_good = False
+ for minmaxspecs in ipolicy[constants.ISPECS_MINMAX]:
+ missing = constants.ISPECS_MINMAX_KEYS - frozenset(minmaxspecs.keys())
+ if missing:
+ msg = "Missing instance specification: %s" % utils.CommaJoin(missing)
+ raise errors.ConfigurationError(msg)
+ for (key, spec) in minmaxspecs.items():
+ InstancePolicy._CheckIncompleteSpec(spec, key)
+
+ spec_std_ok = True
+ for param in constants.ISPECS_PARAMETERS:
+ par_std_ok = InstancePolicy._CheckISpecParamSyntax(minmaxspecs, stdspec,
+ param, check_std)
+ spec_std_ok = spec_std_ok and par_std_ok
+ std_is_good = std_is_good or spec_std_ok
+ if not std_is_good:
+ raise errors.ConfigurationError("Invalid std specifications")
+
+ @classmethod
+ def _CheckISpecParamSyntax(cls, minmaxspecs, stdspec, name, check_std):
+ """Check the instance policy specs for validity on a given key.
+
+ We check if the instance specs makes sense for a given key, that is
+ if minmaxspecs[min][name] <= stdspec[name] <= minmaxspec[max][name].
+
+ @type minmaxspecs: dict
+ @param minmaxspecs: dictionary with min and max instance spec
+ @type stdspec: dict
+ @param stdspec: dictionary with standard instance spec