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
41 import qualified Ganeti.HTools.Types as T
42 import qualified Ganeti.HTools.Container as Container
44 -- * Type declarations
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
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
60 instance T.Element Instance where
66 -- | A simple name for the int, instance association list.
67 type AssocList = [(T.Idx, Instance)]
69 -- | A simple name for an instance map.
70 type List = Container.Container Instance
74 -- | Create an instance.
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 =
85 running = case run_init of
95 -- | Changes the index.
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 }
103 -- | Changes the name.
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 }
111 -- * Update functions
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 }
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 }
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 }