From 5e71804206ee9058f986564ed629a054b5c2bc2e Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 19 Nov 2010 12:11:37 +0100 Subject: [PATCH] Simu loader: move the loading to non-IO code While we don't actually have IO code in the Simu loader, we do have the same interface. So we move the code again to a separate parseData function which is exported. --- Ganeti/HTools/Simu.hs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Ganeti/HTools/Simu.hs b/Ganeti/HTools/Simu.hs index 81c57682e..6c01726ec 100644 --- a/Ganeti/HTools/Simu.hs +++ b/Ganeti/HTools/Simu.hs @@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Ganeti.HTools.Simu ( loadData + , parseData ) where import Text.Printf (printf) @@ -49,17 +50,22 @@ parseDesc desc = return (ncount, disk, mem, cpu) _ -> fail "Invalid cluster specification" +-- | Builds the cluster data from node\/instance files. +parseData :: String -- ^ Cluster description in text format + -> Result (Node.AssocList, Instance.AssocList, [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 + in (idx, Node.setIdx n idx) + ) [1..cnt] + return (nodes, [], []) + -- | Builds the cluster data from node\/instance files. loadData :: String -- ^ Cluster description in text format -> IO (Result (Node.AssocList, Instance.AssocList, [String])) -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, [], []) +loadData = -- IO monad, just for consistency with the other loaders + return . parseData -- GitLab