Revision aa8d2e71 Ganeti/HTools/Loader.hs
b/Ganeti/HTools/Loader.hs | ||
---|---|---|
37 | 37 |
, Request(..) |
38 | 38 |
) where |
39 | 39 |
|
40 |
import Control.Monad (foldM) |
|
40 | 41 |
import Data.Function (on) |
41 | 42 |
import Data.List |
42 | 43 |
import Data.Maybe (fromJust) |
... | ... | |
96 | 97 |
|
97 | 98 |
-- | For each instance, add its index to its primary and secondary nodes. |
98 | 99 |
fixNodes :: [(Ndx, Node.Node)] |
99 |
-> (Idx, Instance.Instance)
|
|
100 |
-> Instance.Instance
|
|
100 | 101 |
-> [(Ndx, Node.Node)] |
101 |
fixNodes accu (_, inst) =
|
|
102 |
fixNodes accu inst =
|
|
102 | 103 |
let |
103 | 104 |
pdx = Instance.pNode inst |
104 | 105 |
sdx = Instance.sNode inst |
... | ... | |
130 | 131 |
|
131 | 132 |
-- | Initializer function that loads the data from a node and instance |
132 | 133 |
-- list and massages it into the correct format. |
133 |
mergeData :: (Node.AssocList, |
|
134 |
mergeData :: [(String, DynUtil)] -- ^ Instance utilisation data |
|
135 |
-> (Node.AssocList, |
|
134 | 136 |
Instance.AssocList) -- ^ Data from either Text.loadData |
135 | 137 |
-- or Rapi.loadData |
136 | 138 |
-> Result (Node.List, Instance.List, String) |
137 |
mergeData (nl, il) = do |
|
138 |
let |
|
139 |
nl2 = foldl' fixNodes nl il |
|
140 |
il3 = Container.fromAssocList il |
|
141 |
nl3 = Container.fromAssocList |
|
139 |
mergeData um (nl, il) = do |
|
140 |
let il2 = Container.fromAssocList il |
|
141 |
il3 <- foldM (\im (name, n_util) -> do |
|
142 |
idx <- Container.findByName im name |
|
143 |
let inst = Container.find idx im |
|
144 |
new_i = inst { Instance.util = n_util } |
|
145 |
return $ Container.add idx new_i im |
|
146 |
) il2 um |
|
147 |
let nl2 = foldl' fixNodes nl (Container.elems il3) |
|
148 |
let nl3 = Container.fromAssocList |
|
142 | 149 |
(map (\ (k, v) -> (k, Node.buildPeers v il3)) nl2) |
143 | 150 |
node_names = map Node.name $ Container.elems nl3 |
144 | 151 |
inst_names = map Instance.name $ Container.elems il3 |
Also available in: Unified diff