Revision f4c0b8c5 Ganeti/HTools/Node.hs
b/Ganeti/HTools/Node.hs | ||
---|---|---|
58 | 58 |
, AssocList |
59 | 59 |
, AllocElement |
60 | 60 |
, noSecondary |
61 |
, noLimitInt |
|
62 | 61 |
) where |
63 | 62 |
|
64 | 63 |
import Data.List |
... | ... | |
133 | 132 |
noSecondary :: T.Ndx |
134 | 133 |
noSecondary = -1 |
135 | 134 |
|
136 |
-- | No limit value |
|
137 |
noLimit :: Double |
|
138 |
noLimit = -1 |
|
139 |
|
|
140 |
-- | No limit int value |
|
141 |
noLimitInt :: Int |
|
142 |
noLimitInt = -1 |
|
143 |
|
|
144 | 135 |
-- * Helper functions |
145 | 136 |
|
146 | 137 |
-- | Add a tag to a tagmap |
... | ... | |
204 | 195 |
, pCpu = 0 |
205 | 196 |
, offline = offline_init |
206 | 197 |
, xMem = 0 |
207 |
, mDsk = noLimit
|
|
208 |
, mCpu = noLimit
|
|
209 |
, loDsk = noLimitInt
|
|
210 |
, hiCpu = noLimitInt
|
|
198 |
, mDsk = T.defReservedDiskRatio
|
|
199 |
, mCpu = T.defVcpuRatio
|
|
200 |
, loDsk = mDskToloDsk T.defReservedDiskRatio dsk_t_init
|
|
201 |
, hiCpu = mCpuTohiCpu T.defVcpuRatio cpu_t_init
|
|
211 | 202 |
, utilPool = T.baseUtil |
212 | 203 |
, utilLoad = T.zeroUtil |
213 | 204 |
, pTags = Map.empty |
214 | 205 |
} |
215 | 206 |
|
207 |
-- | Conversion formula from mDsk/tDsk to loDsk |
|
208 |
mDskToloDsk :: Double -> Double -> Int |
|
209 |
mDskToloDsk mval tdsk = floor (mval * tdsk) |
|
210 |
|
|
211 |
-- | Conversion formula from mCpu/tCpu to hiCpu |
|
212 |
mCpuTohiCpu :: Double -> Double -> Int |
|
213 |
mCpuTohiCpu mval tcpu = floor (mval * tcpu) |
|
214 |
|
|
216 | 215 |
-- | Changes the index. |
217 | 216 |
-- |
218 | 217 |
-- This is used only during the building of the data structures. |
... | ... | |
235 | 234 |
|
236 | 235 |
-- | Sets the max disk usage ratio |
237 | 236 |
setMdsk :: Node -> Double -> Node |
238 |
setMdsk t val = t { mDsk = val, |
|
239 |
loDsk = if val == noLimit |
|
240 |
then noLimitInt |
|
241 |
else floor (val * tDsk t) } |
|
237 |
setMdsk t val = t { mDsk = val, loDsk = mDskToloDsk val (tDsk t) } |
|
242 | 238 |
|
243 | 239 |
-- | Sets the max cpu usage ratio |
244 | 240 |
setMcpu :: Node -> Double -> Node |
245 |
setMcpu t val = t { mCpu = val, hiCpu = hcpu } |
|
246 |
where new_hcpu = floor (val * tCpu t)::Int |
|
247 |
hcpu = if new_hcpu < 0 |
|
248 |
then noLimitInt |
|
249 |
else new_hcpu |
|
241 |
setMcpu t val = t { mCpu = val, hiCpu = mCpuTohiCpu val (tCpu t) } |
|
250 | 242 |
|
251 | 243 |
-- | Computes the maximum reserved memory for peers from a peer map. |
252 | 244 |
computeMaxRes :: P.PeerMap -> P.Elem |
... | ... | |
401 | 393 |
availDisk t = |
402 | 394 |
let _f = fDsk t |
403 | 395 |
_l = loDsk t |
404 |
in |
|
405 |
if _l == noLimitInt |
|
406 |
then _f |
|
407 |
else if _f < _l |
|
408 |
then 0 |
|
409 |
else _f - _l |
|
396 |
in if _f < _l |
|
397 |
then 0 |
|
398 |
else _f - _l |
|
410 | 399 |
|
411 | 400 |
-- * Display functions |
412 | 401 |
|
Also available in: Unified diff