Revision 756df409
b/htools/Ganeti/HTools/Cluster.hs | ||
---|---|---|
68 | 68 |
-- * Allocation functions |
69 | 69 |
, iterateAlloc |
70 | 70 |
, tieredAlloc |
71 |
, tieredSpecMap |
|
72 | 71 |
-- * Node group functions |
73 | 72 |
, instanceGroup |
74 | 73 |
, findSplitInstances |
75 | 74 |
, splitCluster |
76 | 75 |
) where |
77 | 76 |
|
78 |
import Data.Function (on) |
|
79 | 77 |
import qualified Data.IntSet as IntSet |
80 | 78 |
import Data.List |
81 | 79 |
import Data.Maybe (fromJust) |
... | ... | |
1171 | 1169 |
Ok newinst' -> tieredAlloc nl' il' newlimit |
1172 | 1170 |
newinst' allocnodes ixes' cstats' |
1173 | 1171 |
|
1174 |
-- | Compute the tiered spec string description from a list of |
|
1175 |
-- allocated instances. |
|
1176 |
tieredSpecMap :: [Instance.Instance] |
|
1177 |
-> [String] |
|
1178 |
tieredSpecMap trl_ixes = |
|
1179 |
let fin_trl_ixes = reverse trl_ixes |
|
1180 |
ix_byspec = groupBy ((==) `on` Instance.specOf) fin_trl_ixes |
|
1181 |
spec_map = map (\ixs -> (Instance.specOf $ head ixs, length ixs)) |
|
1182 |
ix_byspec |
|
1183 |
in map (\(spec, cnt) -> printf "%d,%d,%d=%d" (rspecMem spec) |
|
1184 |
(rspecDsk spec) (rspecCpu spec) cnt) spec_map |
|
1185 |
|
|
1186 | 1172 |
-- * Formatting functions |
1187 | 1173 |
|
1188 | 1174 |
-- | Given the original and final nodes, computes the relocation description. |
b/htools/Ganeti/HTools/Program/Hspace.hs | ||
---|---|---|
27 | 27 |
|
28 | 28 |
import Control.Monad |
29 | 29 |
import Data.Char (toUpper, isAlphaNum) |
30 |
import Data.Function (on) |
|
30 | 31 |
import Data.List |
31 | 32 |
import Data.Maybe (isJust, fromJust) |
32 | 33 |
import Data.Ord (comparing) |
... | ... | |
152 | 153 |
-- this should be the final entry |
153 | 154 |
printKeys [("OK", "1")] |
154 | 155 |
|
156 |
-- | Compute the tiered spec counts from a list of allocated |
|
157 |
-- instances. |
|
158 |
tieredSpecMap :: [Instance.Instance] |
|
159 |
-> [(RSpec, Int)] |
|
160 |
tieredSpecMap trl_ixes = |
|
161 |
let fin_trl_ixes = reverse trl_ixes |
|
162 |
ix_byspec = groupBy ((==) `on` Instance.specOf) fin_trl_ixes |
|
163 |
spec_map = map (\ixs -> (Instance.specOf $ head ixs, length ixs)) |
|
164 |
ix_byspec |
|
165 |
in spec_map |
|
166 |
|
|
167 |
-- | Formats a spec map to strings. |
|
168 |
formatSpecMap :: [(RSpec, Int)] -> [String] |
|
169 |
formatSpecMap = |
|
170 |
map (\(spec, cnt) -> printf "%d,%d,%d=%d" (rspecMem spec) |
|
171 |
(rspecDsk spec) (rspecCpu spec) cnt) |
|
172 |
|
|
155 | 173 |
formatRSpec :: Double -> String -> RSpec -> [(String, String)] |
156 | 174 |
formatRSpec m_cpu s r = |
157 | 175 |
[ ("KM_" ++ s ++ "_CPU", show $ rspecCpu r) |
... | ... | |
304 | 322 |
then return result_noalloc |
305 | 323 |
else exitifbad (Cluster.tieredAlloc nl il Nothing (iofspec tspec) |
306 | 324 |
allocnodes [] []) |
307 |
let spec_map' = Cluster.tieredSpecMap trl_ixes
|
|
325 |
let spec_map' = tieredSpecMap trl_ixes |
|
308 | 326 |
|
309 | 327 |
printAllocationMap verbose "Tiered allocation map" trl_nl trl_ixes |
310 | 328 |
|
... | ... | |
316 | 334 |
|
317 | 335 |
printKeys $ map (\(a, fn) -> ("TSPEC_INI_" ++ a, fn tspec)) specData |
318 | 336 |
printKeys $ printStats PTiered (Cluster.totalResources trl_nl) |
319 |
printKeys [("TSPEC", intercalate " " spec_map')]
|
|
337 |
printKeys [("TSPEC", intercalate " " (formatSpecMap spec_map'))]
|
|
320 | 338 |
printAllocationStats m_cpu nl trl_nl) |
321 | 339 |
|
322 | 340 |
-- Run the standard (avg-mode) allocation |
Also available in: Unified diff