Revision a488a217

b/Ganeti/HTools/Loader.hs
98 98
fixNodes :: [(Ndx, Node.Node)]
99 99
         -> (Idx, Instance.Instance)
100 100
         -> [(Ndx, Node.Node)]
101
fixNodes accu (idx, inst) =
101
fixNodes accu (_, inst) =
102 102
    let
103 103
        pdx = Instance.pNode inst
104 104
        sdx = Instance.sNode inst
105 105
        pold = fromJust $ lookup pdx accu
106
        pnew = Node.setPri pold idx
107
        pnew' = Node.addCpus pnew (Instance.vcpus inst)
106
        pnew = Node.setPri pold inst
108 107
        ac1 = deleteBy assocEqual (pdx, pold) accu
109
        ac2 = (pdx, pnew'):ac1
108
        ac2 = (pdx, pnew):ac1
110 109
    in
111 110
      if sdx /= Node.noSecondary
112 111
      then let sold = fromJust $ lookup sdx accu
113
               snew = Node.setSec sold idx
112
               snew = Node.setSec sold inst
114 113
               ac3 = deleteBy assocEqual (sdx, sold) ac2
115 114
           in (sdx, snew):ac3
116 115
      else ac2
b/Ganeti/HTools/Node.hs
47 47
    , setSec
48 48
    , setMdsk
49 49
    , setMcpu
50
    , addCpus
51 50
    -- * Instance (re)location
52 51
    , removePri
53 52
    , removeSec
......
217 216
        new_prem = fromIntegral new_rmem / tMem t
218 217
    in t {peers=pmap, failN1 = new_failN1, rMem = new_rmem, pRem = new_prem}
219 218

  
220
-- | Assigns an instance to a node as primary without other updates.
221
setPri :: Node -> T.Idx -> Node
222
setPri t ix = t { pList = ix:pList t }
219
-- | Assigns an instance to a node as primary and update the used VCPU
220
-- count.
221
setPri :: Node -> Instance.Instance -> Node
222
setPri t inst = t { pList = (Instance.idx inst):pList t
223
                  , uCpu = new_count
224
                  , pCpu = fromIntegral new_count / tCpu t }
225
    where new_count = uCpu t + Instance.vcpus inst
223 226

  
224 227
-- | Assigns an instance to a node as secondary without other updates.
225
setSec :: Node -> T.Idx -> Node
226
setSec t ix = t { sList = ix:sList t }
227

  
228
-- | Add primary cpus to a node
229
addCpus :: Node -> Int -> Node
230
addCpus t count =
231
    let new_count = uCpu t + count
232
    in t { uCpu = new_count, pCpu = fromIntegral new_count / tCpu t }
228
setSec :: Node -> Instance.Instance -> Node
229
setSec t inst = t { sList = (Instance.idx inst):sList t }
233 230

  
234 231
-- * Update functions
235 232

  

Also available in: Unified diff