Revision 0c2e59ac lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
1116 | 1116 |
(instance.name, msg), errors.ECODE_STATE) |
1117 | 1117 |
|
1118 | 1118 |
|
1119 |
def _ComputeMinMaxSpec(name, ipolicy, value): |
|
1119 |
def _ComputeMinMaxSpec(name, qualifier, ipolicy, value):
|
|
1120 | 1120 |
"""Computes if value is in the desired range. |
1121 | 1121 |
|
1122 | 1122 |
@param name: name of the parameter for which we perform the check |
1123 |
@param qualifier: a qualifier used in the error message (e.g. 'disk/1', |
|
1124 |
not just 'disk') |
|
1123 | 1125 |
@param ipolicy: dictionary containing min, max and std values |
1124 | 1126 |
@param value: actual value that we want to use |
1125 | 1127 |
@return: None or element not meeting the criteria |
... | ... | |
1131 | 1133 |
max_v = ipolicy[constants.ISPECS_MAX].get(name, value) |
1132 | 1134 |
min_v = ipolicy[constants.ISPECS_MIN].get(name, value) |
1133 | 1135 |
if value > max_v or min_v > value: |
1136 |
if qualifier: |
|
1137 |
fqn = "%s/%s" % (name, qualifier) |
|
1138 |
else: |
|
1139 |
fqn = name |
|
1134 | 1140 |
return ("%s value %s is not in range [%s, %s]" % |
1135 |
(name, value, min_v, max_v))
|
|
1141 |
(fqn, value, min_v, max_v))
|
|
1136 | 1142 |
return None |
1137 | 1143 |
|
1138 | 1144 |
|
... | ... | |
1162 | 1168 |
assert disk_count == len(disk_sizes) |
1163 | 1169 |
|
1164 | 1170 |
test_settings = [ |
1165 |
(constants.ISPEC_MEM_SIZE, mem_size), |
|
1166 |
(constants.ISPEC_CPU_COUNT, cpu_count), |
|
1167 |
(constants.ISPEC_DISK_COUNT, disk_count), |
|
1168 |
(constants.ISPEC_NIC_COUNT, nic_count), |
|
1169 |
(constants.ISPEC_SPINDLE_USE, spindle_use), |
|
1170 |
] + map((lambda d: (constants.ISPEC_DISK_SIZE, d)), disk_sizes) |
|
1171 |
(constants.ISPEC_MEM_SIZE, "", mem_size), |
|
1172 |
(constants.ISPEC_CPU_COUNT, "", cpu_count), |
|
1173 |
(constants.ISPEC_DISK_COUNT, "", disk_count), |
|
1174 |
(constants.ISPEC_NIC_COUNT, "", nic_count), |
|
1175 |
(constants.ISPEC_SPINDLE_USE, "", spindle_use), |
|
1176 |
] + [(constants.ISPEC_DISK_SIZE, str(idx), d) |
|
1177 |
for idx, d in enumerate(disk_sizes)] |
|
1171 | 1178 |
|
1172 | 1179 |
return filter(None, |
1173 |
(_compute_fn(name, ipolicy, value) |
|
1174 |
for (name, value) in test_settings)) |
|
1180 |
(_compute_fn(name, qualifier, ipolicy, value)
|
|
1181 |
for (name, qualifier, value) in test_settings))
|
|
1175 | 1182 |
|
1176 | 1183 |
|
1177 | 1184 |
def _ComputeIPolicyInstanceViolation(ipolicy, instance, |
Also available in: Unified diff