Add an explicit export list to Instance.hs
[ganeti-local] / Ganeti / HTools / Instance.hs
1 {-| Module describing an instance.
2
3 The instance data type holds very few fields, the algorithm
4 intelligence is in the "Node" and "Cluster" modules.
5
6 -}
7
8 {-
9
10 Copyright (C) 2009 Google Inc.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 02110-1301, USA.
26
27 -}
28
29 module Ganeti.HTools.Instance
30     ( Instance(..)
31     , AssocList
32     , List
33     , create
34     , setIdx
35     , setName
36     , setPri
37     , setSec
38     , setBoth
39     ) where
40
41 import qualified Ganeti.HTools.Types as T
42 import qualified Ganeti.HTools.Container as Container
43
44 -- * Type declarations
45
46 -- | The instance type
47 data Instance = Instance { name :: String   -- ^ The instance name
48                          , mem :: Int       -- ^ Memory of the instance
49                          , dsk :: Int       -- ^ Disk size of instance
50                          , vcpus :: Int     -- ^ Number of VCPUs
51                          , running :: Bool  -- ^ Whether the instance
52                                             -- is running
53                          , runSt :: String  -- ^ Original (text) run status
54                          , pNode :: T.Ndx   -- ^ Original primary node
55                          , sNode :: T.Ndx   -- ^ Original secondary node
56                          , idx :: T.Idx     -- ^ Internal index for
57                                             -- book-keeping
58                          } deriving (Show)
59
60 instance T.Element Instance where
61     nameOf  = name
62     idxOf   = idx
63     setName = setName
64     setIdx  = setIdx
65
66 -- | A simple name for the int, instance association list.
67 type AssocList = [(T.Idx, Instance)]
68
69 -- | A simple name for an instance map.
70 type List = Container.Container Instance
71
72 -- * Initialization
73
74 -- | Create an instance.
75 --
76 -- Some parameters are not initialized by function, and must be set
77 -- later (via 'setIdx' for example).
78 create :: String -> Int -> Int -> Int -> String -> T.Ndx -> T.Ndx -> Instance
79 create name_init mem_init dsk_init vcpus_init run_init pn sn =
80     Instance {
81           name = name_init,
82           mem = mem_init,
83           dsk = dsk_init,
84           vcpus = vcpus_init,
85           running = case run_init of
86                       "running" -> True
87                       "ERROR_up" -> True
88                       _ -> False,
89           runSt = run_init,
90           pNode = pn,
91           sNode = sn,
92           idx = -1
93         }
94
95 -- | Changes the index.
96 --
97 -- This is used only during the building of the data structures.
98 setIdx :: Instance -- ^ The original instance
99        -> T.Idx    -- ^ New index
100        -> Instance -- ^ The modified instance
101 setIdx t i = t { idx = i }
102
103 -- | Changes the name.
104 --
105 -- This is used only during the building of the data structures.
106 setName :: Instance -- ^ The original instance
107         -> String   -- ^ New name
108         -> Instance -- ^ The modified instance
109 setName t s = t { name = s }
110
111 -- * Update functions
112
113 -- | Changes the primary node of the instance.
114 setPri :: Instance  -- ^ the original instance
115         -> T.Ndx    -- ^ the new primary node
116         -> Instance -- ^ the modified instance
117 setPri t p = t { pNode = p }
118
119 -- | Changes the secondary node of the instance.
120 setSec :: Instance  -- ^ the original instance
121         -> T.Ndx    -- ^ the new secondary node
122         -> Instance -- ^ the modified instance
123 setSec t s = t { sNode = s }
124
125 -- | Changes both nodes of the instance.
126 setBoth :: Instance  -- ^ the original instance
127          -> T.Ndx    -- ^ new primary node index
128          -> T.Ndx    -- ^ new secondary node index
129          -> Instance -- ^ the modified instance
130 setBoth t p s = t { pNode = p, sNode = s }