Commit a488a217 authored by Iustin Pop's avatar Iustin Pop
Browse files

Merge the Node.setPri and Node.addCpus functions

The latter is only used right after the former in the Loader module, and
we'll need more of this 'update not with the data of this instance'
functionality (which is different than addPri where all information must
be updated).

The patch also changes the signature of Node.setSec (to remain
consistent with setPri).
parent 5b763470
......@@ -98,19 +98,18 @@ assocEqual = (==) `on` fst
fixNodes :: [(Ndx, Node.Node)]
-> (Idx, Instance.Instance)
-> [(Ndx, Node.Node)]
fixNodes accu (idx, inst) =
fixNodes accu (_, inst) =
let
pdx = Instance.pNode inst
sdx = Instance.sNode inst
pold = fromJust $ lookup pdx accu
pnew = Node.setPri pold idx
pnew' = Node.addCpus pnew (Instance.vcpus inst)
pnew = Node.setPri pold inst
ac1 = deleteBy assocEqual (pdx, pold) accu
ac2 = (pdx, pnew'):ac1
ac2 = (pdx, pnew):ac1
in
if sdx /= Node.noSecondary
then let sold = fromJust $ lookup sdx accu
snew = Node.setSec sold idx
snew = Node.setSec sold inst
ac3 = deleteBy assocEqual (sdx, sold) ac2
in (sdx, snew):ac3
else ac2
......
......@@ -47,7 +47,6 @@ module Ganeti.HTools.Node
, setSec
, setMdsk
, setMcpu
, addCpus
-- * Instance (re)location
, removePri
, removeSec
......@@ -217,19 +216,17 @@ buildPeers t il =
new_prem = fromIntegral new_rmem / tMem t
in t {peers=pmap, failN1 = new_failN1, rMem = new_rmem, pRem = new_prem}
-- | Assigns an instance to a node as primary without other updates.
setPri :: Node -> T.Idx -> Node
setPri t ix = t { pList = ix:pList t }
-- | Assigns an instance to a node as primary and update the used VCPU
-- count.
setPri :: Node -> Instance.Instance -> Node
setPri t inst = t { pList = (Instance.idx inst):pList t
, uCpu = new_count
, pCpu = fromIntegral new_count / tCpu t }
where new_count = uCpu t + Instance.vcpus inst
-- | Assigns an instance to a node as secondary without other updates.
setSec :: Node -> T.Idx -> Node
setSec t ix = t { sList = ix:sList t }
-- | Add primary cpus to a node
addCpus :: Node -> Int -> Node
addCpus t count =
let new_count = uCpu t + count
in t { uCpu = new_count, pCpu = fromIntegral new_count / tCpu t }
setSec :: Node -> Instance.Instance -> Node
setSec t inst = t { sList = (Instance.idx inst):sList t }
-- * Update functions
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment