Revision f87c9f5d
b/htools/Ganeti/HTools/Node.hs  

185  185 
conflictingPrimaries :: Node > Int 
186  186 
conflictingPrimaries (Node { pTags = t }) = Foldable.sum t  Map.size t 
187  187  
188 
  Helper function to increment a base value depending on the passed 

189 
 boolean argument. 

190 
incIf :: (Num a) => Bool > a > a > a 

191 
incIf True base delta = base + delta 

192 
incIf False base _ = base 

193  
194 
  Helper function to decrement a base value depending on the passed 

195 
 boolean argument. 

196 
decIf :: (Num a) => Bool > a > a > a 

197 
decIf True base delta = base  delta 

198 
decIf False base _ = base 

199  
188  200 
 * Initialization functions 
189  201  
190  202 
  Create a new node. 
...  ...  
336  348 
removePri :: Node > Instance.Instance > Node 
337  349 
removePri t inst = 
338  350 
let iname = Instance.idx inst 
351 
i_online = Instance.instanceNotOffline inst 

352 
uses_disk = Instance.usesLocalStorage inst 

339  353 
new_plist = delete iname (pList t) 
340 
new_mem = Instance.applyIfOnline inst (+ Instance.mem inst) (fMem t)


341 
new_dsk = fDsk t + Instance.dsk inst


354 
new_mem = incIf i_online (fMem t) (Instance.mem inst)


355 
new_dsk = incIf uses_disk (fDsk t) (Instance.dsk inst)


342  356 
new_mp = fromIntegral new_mem / tMem t 
343  357 
new_dp = fromIntegral new_dsk / tDsk t 
344  358 
new_failn1 = new_mem <= rMem t 
345 
new_ucpu = Instance.applyIfOnline inst 

346 
(\x > x  Instance.vcpus inst) (uCpu t) 

359 
new_ucpu = decIf i_online (uCpu t) (Instance.vcpus inst) 

347  360 
new_rcpu = fromIntegral new_ucpu / tCpu t 
348  361 
new_load = utilLoad t `T.subUtil` Instance.util inst 
349  362 
in t { pList = new_plist, fMem = new_mem, fDsk = new_dsk 
...  ...  
355  368 
removeSec :: Node > Instance.Instance > Node 
356  369 
removeSec t inst = 
357  370 
let iname = Instance.idx inst 
371 
uses_disk = Instance.usesLocalStorage inst 

358  372 
cur_dsk = fDsk t 
359  373 
pnode = Instance.pNode inst 
360  374 
new_slist = delete iname (sList t) 
361 
new_dsk = if Instance.usesLocalStorage inst 

362 
then cur_dsk + Instance.dsk inst 

363 
else cur_dsk 

375 
new_dsk = incIf uses_disk cur_dsk (Instance.dsk inst) 

364  376 
old_peers = peers t 
365  377 
old_peem = P.find pnode old_peers 
366 
new_peem = if Instance.usesSecMem inst 

367 
then old_peem  Instance.mem inst 

368 
else old_peem 

378 
new_peem = decIf (Instance.usesSecMem inst) old_peem (Instance.mem inst) 

369  379 
new_peers = if new_peem > 0 
370  380 
then P.add pnode new_peem old_peers 
371  381 
else P.remove pnode old_peers 
...  ...  
399  409 
 or a failure mode 
400  410 
addPriEx force t inst = 
401  411 
let iname = Instance.idx inst 
412 
i_online = Instance.instanceNotOffline inst 

402  413 
uses_disk = Instance.usesLocalStorage inst 
403  414 
cur_dsk = fDsk t 
404 
new_mem = Instance.applyIfOnline inst 

405 
(\x > x  Instance.mem inst) (fMem t) 

406 
new_dsk = if uses_disk 

407 
then cur_dsk  Instance.dsk inst 

408 
else cur_dsk 

415 
new_mem = decIf i_online (fMem t) (Instance.mem inst) 

416 
new_dsk = decIf uses_disk cur_dsk (Instance.dsk inst) 

409  417 
new_failn1 = new_mem <= rMem t 
410 
new_ucpu = Instance.applyIfOnline inst (+ Instance.vcpus inst) (uCpu t)


418 
new_ucpu = incIf i_online (uCpu t) (Instance.vcpus inst)


411  419 
new_pcpu = fromIntegral new_ucpu / tCpu t 
412  420 
new_dp = fromIntegral new_dsk / tDsk t 
413  421 
l_cpu = T.iPolicyVcpuRatio $ iPolicy t 
Also available in: Unified diff