1 {-| Parsing data from a simulated description of the cluster
3 This module holds the code for parsing a cluster description.
9 Copyright (C) 2009, 2010 Google Inc.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 module Ganeti.HTools.Simu
34 import Text.Printf (printf)
36 import Ganeti.HTools.Utils
37 import Ganeti.HTools.Types
38 import qualified Ganeti.HTools.Container as Container
39 import qualified Ganeti.HTools.Node as Node
40 import qualified Ganeti.HTools.Instance as Instance
42 -- | Parse the string description into nodes
43 parseDesc :: String -> Result (Int, Int, Int, Int)
45 case sepSplit ',' desc of
47 ncount <- tryRead "node count" n
48 disk <- tryRead "disk size" d
49 mem <- tryRead "memory size" m
50 cpu <- tryRead "cpu count" c
51 return (ncount, disk, mem, cpu)
52 _ -> fail "Invalid cluster specification"
54 -- | Builds the cluster data from node\/instance files.
55 parseData :: String -- ^ Cluster description in text format
56 -> Result (Node.List, Instance.List, [String])
58 (cnt, disk, mem, cpu) <- parseDesc ndata
59 let nodes = map (\idx ->
60 let n = Node.create (printf "node%03d" idx)
61 (fromIntegral mem) 0 mem
62 (fromIntegral disk) disk
63 (fromIntegral cpu) False defaultGroupID
64 in (idx, Node.setIdx n idx)
66 return (Container.fromAssocList nodes, Container.empty, [])
68 -- | Builds the cluster data from node\/instance files.
69 loadData :: String -- ^ Cluster description in text format
70 -> IO (Result (Node.List, Instance.List, [String]))
71 loadData = -- IO monad, just for consistency with the other loaders