{-
-Copyright (C) 2009 Google Inc.
+Copyright (C) 2009, 2010 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
-import Control.Monad
import Text.Printf (printf)
import Ganeti.HTools.Utils
import Ganeti.HTools.Types
+import qualified Ganeti.HTools.Container as Container
import qualified Ganeti.HTools.Node as Node
import qualified Ganeti.HTools.Instance as Instance
parseDesc :: String -> Result (Int, Int, Int, Int)
parseDesc desc =
case sepSplit ',' desc of
- n:d:m:c:[] -> do
+ [n, d, m, c] -> do
ncount <- tryRead "node count" n
disk <- tryRead "disk size" d
mem <- tryRead "memory size" m
_ -> fail "Invalid cluster specification"
-- | Builds the cluster data from node\/instance files.
+parseData :: String -- ^ Cluster description in text format
+ -> Result (Node.List, Instance.List, [String])
+parseData ndata = do
+ (cnt, disk, mem, cpu) <- parseDesc ndata
+ let nodes = map (\idx ->
+ let n = Node.create (printf "node%03d" idx)
+ (fromIntegral mem) 0 mem
+ (fromIntegral disk) disk
+ (fromIntegral cpu) False defaultGroupID
+ in (idx, Node.setIdx n idx)
+ ) [1..cnt]
+ return (Container.fromAssocList nodes, Container.empty, [])
+
+-- | Builds the cluster data from node\/instance files.
loadData :: String -- ^ Cluster description in text format
- -> IO (Result (Node.AssocList, Instance.AssocList))
-loadData ndata = -- IO monad, just for consistency with the other loaders
- return $ do
- (cnt, disk, mem, cpu) <- parseDesc ndata
- let nodes = map (\idx ->
- let n = Node.create (printf "node%03d" idx)
- (fromIntegral mem) 0 mem
- (fromIntegral disk) disk
- (fromIntegral cpu) False
- in (idx, Node.setIdx n idx)
- ) [1..cnt]
- return (nodes, [])
+ -> IO (Result (Node.List, Instance.List, [String]))
+loadData = -- IO monad, just for consistency with the other loaders
+ return . parseData