Revision 0c7d4422 htools/Ganeti/HTools/Simu.hs
b/htools/Ganeti/HTools/Simu.hs | ||
---|---|---|
49 | 49 |
++ c ++ "'" |
50 | 50 |
|
51 | 51 |
-- | Parse the string description into nodes. |
52 |
parseDesc :: String -> Result (AllocPolicy, Int, Int, Int, Int) |
|
53 |
parseDesc 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 |
|
52 |
parseDesc :: String -> [String] |
|
53 |
-> Result (AllocPolicy, Int, Int, Int, Int, Int) |
|
54 |
parseDesc _ [a, n, d, m, c, s] = do |
|
55 |
apol <- allocPolicyFromRaw a `mplus` apolAbbrev a |
|
56 |
ncount <- tryRead "node count" n |
|
57 |
disk <- annotateResult "disk size" (parseUnit d) |
|
58 |
mem <- annotateResult "memory size" (parseUnit m) |
|
59 |
cpu <- tryRead "cpu count" c |
|
60 |
spindles <- tryRead "spindles" s |
|
61 |
return (apol, ncount, disk, mem, cpu, spindles) |
|
62 |
|
|
63 |
parseDesc desc [a, n, d, m, c] = parseDesc desc [a, n, d, m, c, "1"] |
|
64 |
|
|
65 |
parseDesc desc es = |
|
66 |
fail $ printf |
|
67 |
"Invalid cluster specification, expected 6 comma-separated\ |
|
68 |
\ sections (allocation policy, node count, disk size,\ |
|
69 |
\ memory size, number of CPUs, spindles) but got %d: '%s'" |
|
70 |
(length es) desc |
|
66 | 71 |
|
67 | 72 |
-- | Creates a node group with the given specifications. |
68 | 73 |
createGroup :: Int -- ^ The group index |
69 | 74 |
-> String -- ^ The group specification |
70 | 75 |
-> Result (Group.Group, [Node.Node]) |
71 | 76 |
createGroup grpIndex spec = do |
72 |
(apol, ncount, disk, mem, cpu) <- parseDesc spec |
|
77 |
(apol, ncount, disk, mem, cpu, spindles) <- parseDesc spec $ |
|
78 |
sepSplit ',' spec |
|
73 | 79 |
let nodes = map (\idx -> |
74 | 80 |
Node.create (printf "node-%02d-%03d" grpIndex idx) |
75 | 81 |
(fromIntegral mem) 0 mem |
76 | 82 |
(fromIntegral disk) disk |
77 |
(fromIntegral cpu) False 1 grpIndex
|
|
83 |
(fromIntegral cpu) False spindles grpIndex
|
|
78 | 84 |
) [1..ncount] |
79 | 85 |
grp = Group.create (printf "group-%02d" grpIndex) |
80 | 86 |
(printf "fake-uuid-%02d" grpIndex) apol defIPolicy |
Also available in: Unified diff