Revision ebf38064 htools/Ganeti/HTools/Simu.hs
b/htools/Ganeti/HTools/Simu.hs | ||
---|---|---|
26 | 26 |
-} |
27 | 27 |
|
28 | 28 |
module Ganeti.HTools.Simu |
29 |
( |
|
30 |
loadData |
|
31 |
, parseData |
|
32 |
) where |
|
29 |
( loadData |
|
30 |
, parseData |
|
31 |
) where |
|
33 | 32 |
|
34 | 33 |
import Control.Monad (mplus) |
35 | 34 |
import Text.Printf (printf) |
... | ... | |
52 | 51 |
-- | Parse the string description into nodes. |
53 | 52 |
parseDesc :: String -> Result (AllocPolicy, Int, Int, Int, Int) |
54 | 53 |
parseDesc desc = |
55 |
case sepSplit ',' desc of
|
|
56 |
[a, n, d, m, c] -> do
|
|
57 |
apol <- allocPolicyFromRaw a `mplus` apolAbbrev a
|
|
58 |
ncount <- tryRead "node count" n
|
|
59 |
disk <- annotateResult "disk size" (parseUnit d)
|
|
60 |
mem <- annotateResult "memory size" (parseUnit m)
|
|
61 |
cpu <- tryRead "cpu count" c
|
|
62 |
return (apol, ncount, disk, mem, cpu)
|
|
63 |
es -> fail $ printf
|
|
64 |
"Invalid cluster specification, expected 5 comma-separated\
|
|
65 |
\ sections (allocation policy, node count, disk size,\
|
|
66 |
\ memory size, number of CPUs) but got %d: '%s'" (length es) desc
|
|
54 |
case sepSplit ',' desc of |
|
55 |
[a, n, d, m, c] -> do |
|
56 |
apol <- allocPolicyFromRaw a `mplus` apolAbbrev a |
|
57 |
ncount <- tryRead "node count" n |
|
58 |
disk <- annotateResult "disk size" (parseUnit d) |
|
59 |
mem <- annotateResult "memory size" (parseUnit m) |
|
60 |
cpu <- tryRead "cpu count" c |
|
61 |
return (apol, ncount, disk, mem, cpu) |
|
62 |
es -> fail $ printf |
|
63 |
"Invalid cluster specification, expected 5 comma-separated\ |
|
64 |
\ sections (allocation policy, node count, disk size,\ |
|
65 |
\ memory size, number of CPUs) but got %d: '%s'" (length es) desc |
|
67 | 66 |
|
68 | 67 |
-- | Creates a node group with the given specifications. |
69 | 68 |
createGroup :: Int -- ^ The group index |
... | ... | |
72 | 71 |
createGroup grpIndex spec = do |
73 | 72 |
(apol, ncount, disk, mem, cpu) <- parseDesc spec |
74 | 73 |
let nodes = map (\idx -> |
75 |
Node.create (printf "node-%02d-%03d" grpIndex idx)
|
|
76 |
(fromIntegral mem) 0 mem
|
|
77 |
(fromIntegral disk) disk
|
|
78 |
(fromIntegral cpu) False grpIndex
|
|
74 |
Node.create (printf "node-%02d-%03d" grpIndex idx) |
|
75 |
(fromIntegral mem) 0 mem |
|
76 |
(fromIntegral disk) disk |
|
77 |
(fromIntegral cpu) False grpIndex |
|
79 | 78 |
) [1..ncount] |
80 | 79 |
grp = Group.create (printf "group-%02d" grpIndex) |
81 | 80 |
(printf "fake-uuid-%02d" grpIndex) apol |
Also available in: Unified diff