Revision 1e3dccc8

b/Ganeti/HTools/Instance.hs
68 68
    setName = setName
69 69
    setIdx  = setIdx
70 70

  
71
-- | Base memory unit.
72
unitMem :: Int
73
unitMem = 64
74
-- | Base disk unit.
75
unitDsk :: Int
76
unitDsk = 256
77
-- | Base vcpus unit.
78
unitCpu :: Int
79
unitCpu = 1
80

  
81 71
-- | Running instance states.
82 72
runningStates :: [String]
83 73
runningStates = ["running", "ERROR_up"]
......
156 146
-- | Try to shrink the instance based on the reason why we can't
157 147
-- allocate it.
158 148
shrinkByType :: Instance -> T.FailMode -> T.Result Instance
159
shrinkByType inst T.FailMem = let v = mem inst - unitMem
160
                              in if v < unitMem
149
shrinkByType inst T.FailMem = let v = mem inst - T.unitMem
150
                              in if v < T.unitMem
161 151
                                 then T.Bad "out of memory"
162 152
                                 else T.Ok inst { mem = v }
163
shrinkByType inst T.FailDisk = let v = dsk inst - unitDsk
164
                               in if v < unitDsk
153
shrinkByType inst T.FailDisk = let v = dsk inst - T.unitDsk
154
                               in if v < T.unitDsk
165 155
                                  then T.Bad "out of disk"
166 156
                                  else T.Ok inst { dsk = v }
167
shrinkByType inst T.FailCPU = let v = vcpus inst - unitCpu
168
                              in if v < unitCpu
157
shrinkByType inst T.FailCPU = let v = vcpus inst - T.unitCpu
158
                              in if v < T.unitCpu
169 159
                                 then T.Bad "out of vcpus"
170 160
                                 else T.Ok inst { vcpus = v }
171 161
shrinkByType _ f = T.Bad $ "Unhandled failure mode " ++ show f
b/Ganeti/HTools/Node.hs
41 41
    , setSec
42 42
    , setMdsk
43 43
    , setMcpu
44
    -- * Tag maps
45
    , addTags
46
    , delTags
47
    , rejectAddTags
44 48
    -- * Instance (re)location
45 49
    , removePri
46 50
    , removeSec
......
48 52
    , addSec
49 53
    -- * Stats
50 54
    , availDisk
55
    , availMem
56
    , availCpu
51 57
    , conflictingPrimaries
52 58
    -- * Formatting
53 59
    , defaultFields
......
397 403
       then 0
398 404
       else _f - _l
399 405

  
406
-- | Computes the amount of available memory on a given node
407
availMem :: Node -> Int
408
availMem t =
409
    let _f = fMem t
410
        _l = rMem t
411
    in if _f < _l
412
       then 0
413
       else _f - _l
414

  
415
-- | Computes the amount of available memory on a given node
416
availCpu :: Node -> Int
417
availCpu t =
418
    let _u = uCpu t
419
        _l = hiCpu t
420
    in if _l >= _u
421
       then _l - _u
422
       else 0
423

  
400 424
-- * Display functions
401 425

  
402 426
showField :: Node -> String -> String
b/Ganeti/HTools/Types.hs
37 37
    , subUtil
38 38
    , defVcpuRatio
39 39
    , defReservedDiskRatio
40
    , unitMem
41
    , unitCpu
42
    , unitDsk
40 43
    , Placement
41 44
    , IMove(..)
42 45
    , MoveJob
......
134 137
defReservedDiskRatio :: Double
135 138
defReservedDiskRatio = 0
136 139

  
140
-- | Base memory unit.
141
unitMem :: Int
142
unitMem = 64
143

  
144
-- | Base disk unit.
145
unitDsk :: Int
146
unitDsk = 256
147

  
148
-- | Base vcpus unit.
149
unitCpu :: Int
150
unitCpu = 1
151

  
137 152
{-|
138 153

  
139 154
This is similar to the JSON library Result type - *very* similar, but
......
166 181
-- | Either-like data-type customized for our failure modes
167 182
data OpResult a = OpFail FailMode -- ^ Failed operation
168 183
                | OpGood a        -- ^ Success operation
184
                  deriving (Show)
169 185

  
170 186
instance Monad OpResult where
171 187
    (OpGood x) >>= fn = fn x

Also available in: Unified diff