diff --git a/Ganeti/HTools/Loader.hs b/Ganeti/HTools/Loader.hs index fd39461bb25c8bd56e8a3e776250ff884a8f0a4c..8756f1a417f5fa2b164fb6f7199eff3647e27729 100644 --- a/Ganeti/HTools/Loader.hs +++ b/Ganeti/HTools/Loader.hs @@ -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 diff --git a/Ganeti/HTools/Node.hs b/Ganeti/HTools/Node.hs index 355db0be6054d2a969fc6111696b31662e7abe6e..bc3210824977aa0147b5bbf742775e5194f8c42d 100644 --- a/Ganeti/HTools/Node.hs +++ b/Ganeti/HTools/Node.hs @@ -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