Revision 55bd1414

b/htools/Ganeti/HTools/Instance.hs
35 35
  , instanceOffline
36 36
  , instanceNotOffline
37 37
  , instanceDown
38
  , usesSecMem
38 39
  , applyIfOnline
39 40
  , setIdx
40 41
  , setName
......
114 115
applyIfOnline :: Instance -> (a -> a) -> a -> a
115 116
applyIfOnline = applyIf . instanceNotOffline
116 117

  
118
-- | Helper for determining whether an instance's memory needs to be
119
-- taken into account for secondary memory reservation.
120
usesSecMem :: Instance -> Bool
121
usesSecMem inst = instanceNotOffline inst && autoBalance inst
122

  
117 123
-- | Constant holding the local storage templates.
118 124
--
119 125
-- /Note:/ Currently Ganeti only exports node total/free disk space
b/htools/Ganeti/HTools/Node.hs
273 273
buildPeers t il =
274 274
  let mdata = map
275 275
              (\i_idx -> let inst = Container.find i_idx il
276
                             mem = if Instance.autoBalance inst
276
                             mem = if Instance.usesSecMem inst
277 277
                                     then Instance.mem inst
278 278
                                     else 0
279 279
                         in (Instance.pNode inst, mem))
......
293 293
                  , utilLoad = utilLoad t `T.addUtil` Instance.util inst
294 294
                  , pTags = addTags (pTags t) (Instance.tags inst)
295 295
                  }
296
  where new_count = uCpu t + Instance.vcpus inst
296
  where new_count = Instance.applyIfOnline inst (+ Instance.vcpus inst)
297
                    (uCpu t )
297 298

  
298 299
-- | Assigns an instance to a node as secondary without other updates.
299 300
setSec :: Node -> Instance.Instance -> Node
......
343 344
                  else cur_dsk
344 345
      old_peers = peers t
345 346
      old_peem = P.find pnode old_peers
346
      new_peem =  if Instance.autoBalance inst
347
      new_peem =  if Instance.usesSecMem inst
347 348
                    then old_peem - Instance.mem inst
348 349
                    else old_peem
349 350
      new_peers = if new_peem > 0
......
423 424
      old_peers = peers t
424 425
      old_mem = fMem t
425 426
      new_dsk = fDsk t - Instance.dsk inst
426
      secondary_needed_mem = if Instance.autoBalance inst &&
427
                             not (Instance.instanceOffline inst)
427
      secondary_needed_mem = if Instance.usesSecMem inst
428 428
                               then Instance.mem inst
429 429
                               else 0
430 430
      new_peem = P.find pdx old_peers + secondary_needed_mem

Also available in: Unified diff