{-
-Copyright (C) 2009, 2010, 2011 Google Inc.
+Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-}
module Ganeti.HTools.Simu
- (
- loadData
- , parseData
- ) where
+ ( loadData
+ , parseData
+ ) where
import Control.Monad (mplus)
import Text.Printf (printf)
++ c ++ "'"
-- | Parse the string description into nodes.
-parseDesc :: String -> Result (AllocPolicy, Int, Int, Int, Int)
-parseDesc desc =
- case sepSplit ',' desc of
- [a, n, d, m, c] -> do
- apol <- allocPolicyFromRaw a `mplus` apolAbbrev a
- ncount <- tryRead "node count" n
- disk <- annotateResult "disk size" (parseUnit d)
- mem <- annotateResult "memory size" (parseUnit m)
- cpu <- tryRead "cpu count" c
- return (apol, ncount, disk, mem, cpu)
- es -> fail $ printf
- "Invalid cluster specification, expected 5 comma-separated\
- \ sections (allocation policy, node count, disk size,\
- \ memory size, number of CPUs) but got %d: '%s'" (length es) desc
+parseDesc :: String -> [String]
+ -> Result (AllocPolicy, Int, Int, Int, Int, Int)
+parseDesc _ [a, n, d, m, c, s] = do
+ apol <- allocPolicyFromRaw a `mplus` apolAbbrev a
+ ncount <- tryRead "node count" n
+ disk <- annotateResult "disk size" (parseUnit d)
+ mem <- annotateResult "memory size" (parseUnit m)
+ cpu <- tryRead "cpu count" c
+ spindles <- tryRead "spindles" s
+ return (apol, ncount, disk, mem, cpu, spindles)
+
+parseDesc desc [a, n, d, m, c] = parseDesc desc [a, n, d, m, c, "1"]
+
+parseDesc desc es =
+ fail $ printf
+ "Invalid cluster specification, expected 6 comma-separated\
+ \ sections (allocation policy, node count, disk size,\
+ \ memory size, number of CPUs, spindles) but got %d: '%s'"
+ (length es) desc
-- | Creates a node group with the given specifications.
createGroup :: Int -- ^ The group index
-> String -- ^ The group specification
-> Result (Group.Group, [Node.Node])
createGroup grpIndex spec = do
- (apol, ncount, disk, mem, cpu) <- parseDesc spec
+ (apol, ncount, disk, mem, cpu, spindles) <- parseDesc spec $
+ sepSplit ',' spec
let nodes = map (\idx ->
- Node.create (printf "node-%02d-%03d" grpIndex idx)
- (fromIntegral mem) 0 mem
- (fromIntegral disk) disk
- (fromIntegral cpu) False grpIndex
+ Node.create (printf "node-%02d-%03d" grpIndex idx)
+ (fromIntegral mem) 0 mem
+ (fromIntegral disk) disk
+ (fromIntegral cpu) False spindles grpIndex
) [1..ncount]
grp = Group.create (printf "group-%02d" grpIndex)
- (printf "fake-uuid-%02d" grpIndex) apol
+ (printf "fake-uuid-%02d" grpIndex) apol defIPolicy
return (Group.setIdx grp grpIndex, nodes)
-- | Builds the cluster data from node\/instance files.
$ zip [1..] nodes'
ktg = map (\g -> (Group.idx g, g)) groups
return (ClusterData (Container.fromList ktg)
- (Container.fromList ktn) Container.empty [])
+ (Container.fromList ktn) Container.empty [] defIPolicy)
-- | Builds the cluster data from node\/instance files.
loadData :: [String] -- ^ Cluster description in text format