Revision aa5b2f07 htools/Ganeti/HTools/Instance.hs
b/htools/Ganeti/HTools/Instance.hs | ||
---|---|---|
7 | 7 |
|
8 | 8 |
{- |
9 | 9 |
|
10 |
Copyright (C) 2009, 2010, 2011 Google Inc. |
|
10 |
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
|
|
11 | 11 |
|
12 | 12 |
This program is free software; you can redistribute it and/or modify |
13 | 13 |
it under the terms of the GNU General Public License as published by |
... | ... | |
43 | 43 |
, setBoth |
44 | 44 |
, setMovable |
45 | 45 |
, specOf |
46 |
, instBelowISpec |
|
47 |
, instAboveISpec |
|
48 |
, instMatchesPolicy |
|
46 | 49 |
, shrinkByType |
47 | 50 |
, localStorageTemplates |
48 | 51 |
, hasSecondary |
... | ... | |
53 | 56 |
|
54 | 57 |
import qualified Ganeti.HTools.Types as T |
55 | 58 |
import qualified Ganeti.HTools.Container as Container |
56 |
import qualified Ganeti.Constants as C |
|
57 | 59 |
|
58 | 60 |
import Ganeti.HTools.Utils |
59 | 61 |
|
... | ... | |
230 | 232 |
specOf Instance { mem = m, dsk = d, vcpus = c } = |
231 | 233 |
T.RSpec { T.rspecCpu = c, T.rspecMem = m, T.rspecDsk = d } |
232 | 234 |
|
235 |
-- | Checks if an instance is smaller than a given spec. Returns |
|
236 |
-- OpGood for a correct spec, otherwise OpFail one of the possible |
|
237 |
-- failure modes. |
|
238 |
instBelowISpec :: Instance -> T.ISpec -> T.OpResult () |
|
239 |
instBelowISpec inst ispec |
|
240 |
| mem inst > T.iSpecMemorySize ispec = T.OpFail T.FailMem |
|
241 |
| dsk inst > T.iSpecDiskSize ispec = T.OpFail T.FailDisk |
|
242 |
| vcpus inst > T.iSpecCpuCount ispec = T.OpFail T.FailCPU |
|
243 |
| otherwise = T.OpGood () |
|
244 |
|
|
245 |
-- | Checks if an instance is bigger than a given spec. |
|
246 |
instAboveISpec :: Instance -> T.ISpec -> T.OpResult () |
|
247 |
instAboveISpec inst ispec |
|
248 |
| mem inst < T.iSpecMemorySize ispec = T.OpFail T.FailMem |
|
249 |
| dsk inst < T.iSpecDiskSize ispec = T.OpFail T.FailDisk |
|
250 |
| vcpus inst < T.iSpecCpuCount ispec = T.OpFail T.FailCPU |
|
251 |
| otherwise = T.OpGood () |
|
252 |
|
|
253 |
-- | Checks if an instance matches a policy. |
|
254 |
instMatchesPolicy :: Instance -> T.IPolicy -> T.OpResult () |
|
255 |
instMatchesPolicy inst ipol = do |
|
256 |
instAboveISpec inst (T.iPolicyMinSpec ipol) |
|
257 |
instBelowISpec inst (T.iPolicyMaxSpec ipol) |
|
258 |
if (diskTemplate inst `elem` T.iPolicyDiskTemplates ipol) |
|
259 |
then T.OpGood () |
|
260 |
else T.OpFail T.FailDisk |
|
261 |
|
|
233 | 262 |
-- | Checks whether the instance uses a secondary node. |
234 | 263 |
-- |
235 | 264 |
-- /Note:/ This should be reconciled with @'sNode' == |
Also available in: Unified diff