Revision 5a13489b src/Ganeti/HTools/Instance.hs
b/src/Ganeti/HTools/Instance.hs | ||
---|---|---|
59 | 59 |
, mirrorType |
60 | 60 |
) where |
61 | 61 |
|
62 |
import Control.Monad (liftM2) |
|
63 |
|
|
62 | 64 |
import Ganeti.BasicTypes |
63 | 65 |
import qualified Ganeti.HTools.Types as T |
64 | 66 |
import qualified Ganeti.HTools.Container as Container |
... | ... | |
278 | 280 |
-- | Checks if an instance is smaller/bigger than a given spec. Returns |
279 | 281 |
-- OpGood for a correct spec, otherwise Bad one of the possible |
280 | 282 |
-- failure modes. |
281 |
instCompareISpec :: Ordering -> Instance-> T.ISpec -> T.OpResult () |
|
282 |
instCompareISpec which inst ispec |
|
283 |
instCompareISpec :: Ordering -> Instance-> T.ISpec -> Bool -> T.OpResult ()
|
|
284 |
instCompareISpec which inst ispec exclstor
|
|
283 | 285 |
| which == mem inst `compare` T.iSpecMemorySize ispec = Bad T.FailMem |
284 | 286 |
| which `elem` map ((`compare` T.iSpecDiskSize ispec) . dskSize) |
285 | 287 |
(disks inst) = Bad T.FailDisk |
286 | 288 |
| which == vcpus inst `compare` T.iSpecCpuCount ispec = Bad T.FailCPU |
287 |
| which == spindleUse inst `compare` T.iSpecSpindleUse ispec |
|
289 |
| exclstor && |
|
290 |
case getTotalSpindles inst of |
|
291 |
Nothing -> True |
|
292 |
Just sp_sum -> which == sp_sum `compare` T.iSpecSpindleUse ispec |
|
293 |
= Bad T.FailSpindles |
|
294 |
| not exclstor && which == spindleUse inst `compare` T.iSpecSpindleUse ispec |
|
288 | 295 |
= Bad T.FailSpindles |
289 | 296 |
| diskTemplate inst /= T.DTDiskless && |
290 | 297 |
which == length (disks inst) `compare` T.iSpecDiskCount ispec |
... | ... | |
292 | 299 |
| otherwise = Ok () |
293 | 300 |
|
294 | 301 |
-- | Checks if an instance is smaller than a given spec. |
295 |
instBelowISpec :: Instance -> T.ISpec -> T.OpResult () |
|
302 |
instBelowISpec :: Instance -> T.ISpec -> Bool -> T.OpResult ()
|
|
296 | 303 |
instBelowISpec = instCompareISpec GT |
297 | 304 |
|
298 | 305 |
-- | Checks if an instance is bigger than a given spec. |
299 |
instAboveISpec :: Instance -> T.ISpec -> T.OpResult () |
|
306 |
instAboveISpec :: Instance -> T.ISpec -> Bool -> T.OpResult ()
|
|
300 | 307 |
instAboveISpec = instCompareISpec LT |
301 | 308 |
|
302 | 309 |
-- | Checks if an instance matches a min/max specs pair |
303 |
instMatchesMinMaxSpecs :: Instance -> T.MinMaxISpecs -> T.OpResult () |
|
304 |
instMatchesMinMaxSpecs inst minmax = do |
|
305 |
instAboveISpec inst (T.minMaxISpecsMinSpec minmax) |
|
306 |
instBelowISpec inst (T.minMaxISpecsMaxSpec minmax) |
|
310 |
instMatchesMinMaxSpecs :: Instance -> T.MinMaxISpecs -> Bool -> T.OpResult ()
|
|
311 |
instMatchesMinMaxSpecs inst minmax exclstor = do
|
|
312 |
instAboveISpec inst (T.minMaxISpecsMinSpec minmax) exclstor
|
|
313 |
instBelowISpec inst (T.minMaxISpecsMaxSpec minmax) exclstor
|
|
307 | 314 |
|
308 | 315 |
-- | Checks if an instance matches any specs of a policy |
309 |
instMatchesSpecs :: Instance -> [T.MinMaxISpecs] -> T.OpResult () |
|
316 |
instMatchesSpecs :: Instance -> [T.MinMaxISpecs] -> Bool -> T.OpResult ()
|
|
310 | 317 |
-- Return Ok for no constraints, though this should never happen |
311 |
instMatchesSpecs _ [] = Ok () |
|
312 |
instMatchesSpecs inst minmaxes = |
|
318 |
instMatchesSpecs _ [] _ = Ok ()
|
|
319 |
instMatchesSpecs inst minmaxes exclstor =
|
|
313 | 320 |
-- The initial "Bad" should be always replaced by a real result |
314 | 321 |
foldr eithermatch (Bad T.FailInternal) minmaxes |
315 |
where eithermatch mm (Bad _) = instMatchesMinMaxSpecs inst mm |
|
322 |
where eithermatch mm (Bad _) = instMatchesMinMaxSpecs inst mm exclstor
|
|
316 | 323 |
eithermatch _ y@(Ok ()) = y |
317 | 324 |
|
318 | 325 |
-- | Checks if an instance matches a policy. |
319 |
instMatchesPolicy :: Instance -> T.IPolicy -> T.OpResult () |
|
320 |
instMatchesPolicy inst ipol = do |
|
321 |
instMatchesSpecs inst $ T.iPolicyMinMaxISpecs ipol
|
|
326 |
instMatchesPolicy :: Instance -> T.IPolicy -> Bool -> T.OpResult ()
|
|
327 |
instMatchesPolicy inst ipol exclstor = do
|
|
328 |
instMatchesSpecs inst (T.iPolicyMinMaxISpecs ipol) exclstor
|
|
322 | 329 |
if diskTemplate inst `elem` T.iPolicyDiskTemplates ipol |
323 | 330 |
then Ok () |
324 | 331 |
else Bad T.FailDisk |
Also available in: Unified diff