Revision da5f09ef lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
813 | 813 |
return params_copy |
814 | 814 |
|
815 | 815 |
|
816 |
def _UpdateMinMaxISpecs(ipolicy, new_minmax, group_policy): |
|
817 |
use_none = use_default = group_policy |
|
818 |
minmax = ipolicy.setdefault(constants.ISPECS_MINMAX, {}) |
|
819 |
for (key, value) in new_minmax.items(): |
|
820 |
if key not in constants.ISPECS_MINMAX_KEYS: |
|
821 |
raise errors.OpPrereqError("Invalid key in new ipolicy/%s: %s" % |
|
822 |
(constants.ISPECS_MINMAX, key), |
|
823 |
errors.ECODE_INVAL) |
|
824 |
old_spec = minmax.get(key, {}) |
|
825 |
minmax[key] = _GetUpdatedParams(old_spec, value, use_none=use_none, |
|
826 |
use_default=use_default) |
|
827 |
utils.ForceDictType(minmax[key], constants.ISPECS_PARAMETER_TYPES) |
|
828 |
|
|
829 |
|
|
816 | 830 |
def _GetUpdatedIPolicy(old_ipolicy, new_ipolicy, group_policy=False): |
817 |
"""Return the new version of a instance policy. |
|
831 |
"""Return the new version of an instance policy.
|
|
818 | 832 |
|
819 | 833 |
@param group_policy: whether this policy applies to a group and thus |
820 | 834 |
we should support removal of policy entries |
... | ... | |
826 | 840 |
if key not in constants.IPOLICY_ALL_KEYS: |
827 | 841 |
raise errors.OpPrereqError("Invalid key in new ipolicy: %s" % key, |
828 | 842 |
errors.ECODE_INVAL) |
829 |
if key in constants.IPOLICY_ISPECS: |
|
843 |
if key == constants.ISPECS_MINMAX: |
|
844 |
_UpdateMinMaxISpecs(ipolicy, value, group_policy) |
|
845 |
elif key == constants.ISPECS_STD: |
|
830 | 846 |
ipolicy[key] = _GetUpdatedParams(old_ipolicy.get(key, {}), value, |
831 | 847 |
use_none=use_none, |
832 | 848 |
use_default=use_default) |
... | ... | |
1203 | 1219 |
" is down") |
1204 | 1220 |
|
1205 | 1221 |
|
1206 |
def _ComputeMinMaxSpec(name, qualifier, ipolicy, value):
|
|
1222 |
def _ComputeMinMaxSpec(name, qualifier, ispecs, value):
|
|
1207 | 1223 |
"""Computes if value is in the desired range. |
1208 | 1224 |
|
1209 | 1225 |
@param name: name of the parameter for which we perform the check |
1210 | 1226 |
@param qualifier: a qualifier used in the error message (e.g. 'disk/1', |
1211 | 1227 |
not just 'disk') |
1212 |
@param ipolicy: dictionary containing min, max and std values
|
|
1228 |
@param ispecs: dictionary containing min and max values
|
|
1213 | 1229 |
@param value: actual value that we want to use |
1214 |
@return: None or element not meeting the criteria |
|
1215 |
|
|
1230 |
@return: None or an error string |
|
1216 | 1231 |
|
1217 | 1232 |
""" |
1218 | 1233 |
if value in [None, constants.VALUE_AUTO]: |
1219 | 1234 |
return None |
1220 |
max_v = ipolicy[constants.ISPECS_MAX].get(name, value)
|
|
1221 |
min_v = ipolicy[constants.ISPECS_MIN].get(name, value)
|
|
1235 |
max_v = ispecs[constants.ISPECS_MAX].get(name, value)
|
|
1236 |
min_v = ispecs[constants.ISPECS_MIN].get(name, value)
|
|
1222 | 1237 |
if value > max_v or min_v > value: |
1223 | 1238 |
if qualifier: |
1224 | 1239 |
fqn = "%s/%s" % (name, qualifier) |
... | ... | |
1273 | 1288 |
ret.append("Disk template %s is not allowed (allowed templates: %s)" % |
1274 | 1289 |
(disk_template, utils.CommaJoin(allowed_dts))) |
1275 | 1290 |
|
1291 |
minmax = ipolicy[constants.ISPECS_MINMAX] |
|
1276 | 1292 |
return ret + filter(None, |
1277 |
(_compute_fn(name, qualifier, ipolicy, value)
|
|
1293 |
(_compute_fn(name, qualifier, minmax, value)
|
|
1278 | 1294 |
for (name, qualifier, value) in test_settings)) |
1279 | 1295 |
|
1280 | 1296 |
|
Also available in: Unified diff