Revision 38c37a51 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
1016 | 1016 |
(instance.name, msg), errors.ECODE_STATE) |
1017 | 1017 |
|
1018 | 1018 |
|
1019 |
def _CheckMinMaxSpecs(name, ipolicy, value): |
|
1020 |
"""Checks if value is in the desired range. |
|
1021 |
|
|
1022 |
@param name: name of the parameter for which we perform the check |
|
1023 |
@param ipolicy: dictionary containing min, max and std values |
|
1024 |
@param value: actual value that we want to use |
|
1025 |
@return: None or element not meeting the criteria |
|
1026 |
|
|
1027 |
|
|
1028 |
""" |
|
1029 |
if value in [None, constants.VALUE_AUTO]: |
|
1030 |
return None |
|
1031 |
max_v = ipolicy[constants.MAX_ISPECS].get(name, value) |
|
1032 |
min_v = ipolicy[constants.MIN_ISPECS].get(name, value) |
|
1033 |
if value > max_v or min_v > value: |
|
1034 |
return ("%s value %s is not in range [%s, %s]" % |
|
1035 |
(name, value, min_v, max_v)) |
|
1036 |
return None |
|
1037 |
|
|
1038 |
|
|
1019 | 1039 |
def _ExpandItemName(fn, name, kind): |
1020 | 1040 |
"""Expand an item name. |
1021 | 1041 |
|
... | ... | |
2115 | 2135 |
msg = "cannot reach the master IP" |
2116 | 2136 |
_ErrorIf(True, constants.CV_ENODENET, node, msg) |
2117 | 2137 |
|
2138 |
def _VerifyInstancePolicy(self, instance): |
|
2139 |
"""Verify instance specs against instance policy set on node group level. |
|
2140 |
|
|
2141 |
|
|
2142 |
""" |
|
2143 |
cluster = self.cfg.GetClusterInfo() |
|
2144 |
full_beparams = cluster.FillBE(instance) |
|
2145 |
ipolicy = cluster.SimpleFillIPolicy(self.group_info.ipolicy) |
|
2146 |
|
|
2147 |
mem_size = full_beparams.get(constants.BE_MAXMEM, None) |
|
2148 |
cpu_count = full_beparams.get(constants.BE_VCPUS, None) |
|
2149 |
disk_count = len(instance.disks) |
|
2150 |
disk_sizes = [disk.size for disk in instance.disks] |
|
2151 |
nic_count = len(instance.nics) |
|
2152 |
|
|
2153 |
test_settings = [ |
|
2154 |
(constants.MEM_SIZE_SPEC, mem_size), |
|
2155 |
(constants.CPU_COUNT_SPEC, cpu_count), |
|
2156 |
(constants.DISK_COUNT_SPEC, disk_count), |
|
2157 |
(constants.NIC_COUNT_SPEC, nic_count), |
|
2158 |
] + map((lambda d: (constants.DISK_SIZE_SPEC, d)), disk_sizes) |
|
2159 |
|
|
2160 |
for (name, value) in test_settings: |
|
2161 |
test_result = _CheckMinMaxSpecs(name, ipolicy, value) |
|
2162 |
self._ErrorIf(test_result is not None, |
|
2163 |
constants.CV_EINSTANCEPOLICY, instance.name, |
|
2164 |
test_result) |
|
2165 |
|
|
2118 | 2166 |
def _VerifyInstance(self, instance, instanceconfig, node_image, |
2119 | 2167 |
diskstatus): |
2120 | 2168 |
"""Verify an instance. |
... | ... | |
2129 | 2177 |
node_vol_should = {} |
2130 | 2178 |
instanceconfig.MapLVsByNode(node_vol_should) |
2131 | 2179 |
|
2180 |
self._VerifyInstancePolicy(instanceconfig) |
|
2181 |
|
|
2132 | 2182 |
for node in node_vol_should: |
2133 | 2183 |
n_img = node_image[node] |
2134 | 2184 |
if n_img.offline or n_img.rpc_fail or n_img.lvm_fail: |
Also available in: Unified diff