1 {-| Module describing an instance.
3 The instance data type holds very few fields, the algorithm
4 intelligence is in the "Node" and "Cluster" modules.
10 Copyright (C) 2009 Google Inc.
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.
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.
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
29 module Ganeti.HTools.Instance where
31 import qualified Ganeti.HTools.Types as T
32 import qualified Ganeti.HTools.Container as Container
34 -- * Type declarations
36 -- | The instance type
37 data Instance = Instance { name :: String -- ^ The instance name
38 , mem :: Int -- ^ Memory of the instance
39 , dsk :: Int -- ^ Disk size of instance
40 , running :: Bool -- ^ Whether the instance
42 , run_st :: String -- ^ Original (text) run status
43 , pnode :: T.Ndx -- ^ Original primary node
44 , snode :: T.Ndx -- ^ Original secondary node
45 , idx :: T.Idx -- ^ Internal index for
49 instance T.Element Instance where
55 -- | A simple name for the int, instance association list.
56 type AssocList = [(T.Idx, Instance)]
58 -- | A simple name for an instance map.
59 type List = Container.Container Instance
63 -- | Create an instance.
65 -- Some parameters are not initialized by function, and must be set
66 -- later (via 'setIdx' for example).
67 create :: String -> Int -> Int -> String -> T.Ndx -> T.Ndx -> Instance
68 create name_init mem_init dsk_init run_init pn sn =
73 running = case run_init of
83 -- | Changes the index.
85 -- This is used only during the building of the data structures.
86 setIdx :: Instance -- ^ the original instance
87 -> T.Idx -- ^ new index
88 -> Instance -- ^ the modified instance
89 setIdx t i = t { idx = i }
91 -- | Changes the name.
93 -- This is used only during the building of the data structures.
94 setName :: Instance -- ^ The original instance
95 -> String -- ^ New name
97 setName t s = t { name = s }
101 -- | Changes the primary node of the instance.
102 setPri :: Instance -- ^ the original instance
103 -> T.Ndx -- ^ the new primary node
104 -> Instance -- ^ the modified instance
105 setPri t p = t { pnode = p }
107 -- | Changes the secondary node of the instance.
108 setSec :: Instance -- ^ the original instance
109 -> T.Ndx -- ^ the new secondary node
110 -> Instance -- ^ the modified instance
111 setSec t s = t { snode = s }
113 -- | Changes both nodes of the instance.
114 setBoth :: Instance -- ^ the original instance
115 -> T.Ndx -- ^ new primary node index
116 -> T.Ndx -- ^ new secondary node index
117 -> Instance -- ^ the modified instance
118 setBoth t p s = t { pnode = p, snode = s }