Statistics
| Branch: | Tag: | Revision:

root / Ganeti / HTools / Simu.hs @ 94e05c32

History | View | Annotate | Download (2.2 kB)

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