Revision 6ef49eef src/Ganeti/HTools/Instance.hs
b/src/Ganeti/HTools/Instance.hs | ||
---|---|---|
275 | 275 |
specOf Instance { mem = m, dsk = d, vcpus = c } = |
276 | 276 |
T.RSpec { T.rspecCpu = c, T.rspecMem = m, T.rspecDsk = d } |
277 | 277 |
|
278 |
-- | Checks if an instance is smaller than a given spec. Returns |
|
278 |
-- | Checks if an instance is smaller/bigger than a given spec. Returns
|
|
279 | 279 |
-- OpGood for a correct spec, otherwise Bad one of the possible |
280 | 280 |
-- failure modes. |
281 |
instBelowISpec :: Instance -> T.ISpec -> T.OpResult () |
|
282 |
instBelowISpec inst ispec |
|
283 |
| mem inst > T.iSpecMemorySize ispec = Bad T.FailMem |
|
284 |
| any (> T.iSpecDiskSize ispec) (map dskSize $ disks inst) = Bad T.FailDisk |
|
285 |
| vcpus inst > T.iSpecCpuCount ispec = Bad T.FailCPU |
|
281 |
instCompareISpec :: Ordering -> Instance-> T.ISpec -> T.OpResult () |
|
282 |
instCompareISpec which inst ispec |
|
283 |
| which == mem inst `compare` T.iSpecMemorySize ispec = Bad T.FailMem |
|
284 |
| which `elem` map ((`compare` T.iSpecDiskSize ispec) . dskSize) |
|
285 |
(disks inst) = Bad T.FailDisk |
|
286 |
| which == vcpus inst `compare` T.iSpecCpuCount ispec = Bad T.FailCPU |
|
287 |
| which == spindleUse inst `compare` T.iSpecSpindleUse ispec |
|
288 |
= Bad T.FailSpindles |
|
289 |
| diskTemplate inst /= T.DTDiskless && |
|
290 |
which == length (disks inst) `compare` T.iSpecDiskCount ispec |
|
291 |
= Bad T.FailDiskCount |
|
286 | 292 |
| otherwise = Ok () |
287 | 293 |
|
294 |
-- | Checks if an instance is smaller than a given spec. |
|
295 |
instBelowISpec :: Instance -> T.ISpec -> T.OpResult () |
|
296 |
instBelowISpec = instCompareISpec GT |
|
297 |
|
|
288 | 298 |
-- | Checks if an instance is bigger than a given spec. |
289 | 299 |
instAboveISpec :: Instance -> T.ISpec -> T.OpResult () |
290 |
instAboveISpec inst ispec |
|
291 |
| mem inst < T.iSpecMemorySize ispec = Bad T.FailMem |
|
292 |
| any (< T.iSpecDiskSize ispec) (map dskSize $ disks inst) = Bad T.FailDisk |
|
293 |
| vcpus inst < T.iSpecCpuCount ispec = Bad T.FailCPU |
|
294 |
| otherwise = Ok () |
|
300 |
instAboveISpec = instCompareISpec LT |
|
295 | 301 |
|
296 | 302 |
-- | Checks if an instance matches a min/max specs pair |
297 | 303 |
instMatchesMinMaxSpecs :: Instance -> T.MinMaxISpecs -> T.OpResult () |
... | ... | |
303 | 309 |
instMatchesSpecs :: Instance -> [T.MinMaxISpecs] -> T.OpResult () |
304 | 310 |
-- Return Ok for no constraints, though this should never happen |
305 | 311 |
instMatchesSpecs _ [] = Ok () |
306 |
instMatchesSpecs inst (minmax:minmaxes) = |
|
307 |
foldr eithermatch (instMatchesMinMaxSpecs inst minmax) minmaxes |
|
312 |
instMatchesSpecs inst minmaxes = |
|
313 |
-- The initial "Bad" should be always replaced by a real result |
|
314 |
foldr eithermatch (Bad T.FailInternal) minmaxes |
|
308 | 315 |
where eithermatch mm (Bad _) = instMatchesMinMaxSpecs inst mm |
309 | 316 |
eithermatch _ y@(Ok ()) = y |
310 |
-- # See 04f231771 |
|
311 | 317 |
|
312 | 318 |
-- | Checks if an instance matches a policy. |
313 | 319 |
instMatchesPolicy :: Instance -> T.IPolicy -> T.OpResult () |
Also available in: Unified diff