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 , vcpus :: Int -- ^ Number of VCPUs
41 , running :: Bool -- ^ Whether the instance
43 , runSt :: String -- ^ Original (text) run status
44 , pNode :: T.Ndx -- ^ Original primary node
45 , sNode :: T.Ndx -- ^ Original secondary node
46 , idx :: T.Idx -- ^ Internal index for
50 instance T.Element Instance where
56 -- | A simple name for the int, instance association list.
57 type AssocList = [(T.Idx, Instance)]
59 -- | A simple name for an instance map.
60 type List = Container.Container Instance
64 -- | Create an instance.
66 -- Some parameters are not initialized by function, and must be set
67 -- later (via 'setIdx' for example).
68 create :: String -> Int -> Int -> Int -> String -> T.Ndx -> T.Ndx -> Instance
69 create name_init mem_init dsk_init vcpus_init run_init pn sn =
75 running = case run_init of
85 -- | Changes the index.
87 -- This is used only during the building of the data structures.
88 setIdx :: Instance -- ^ The original instance
89 -> T.Idx -- ^ New index
90 -> Instance -- ^ The modified instance
91 setIdx t i = t { idx = i }
93 -- | Changes the name.
95 -- This is used only during the building of the data structures.
96 setName :: Instance -- ^ The original instance
97 -> String -- ^ New name
98 -> Instance -- ^ The modified instance
99 setName t s = t { name = s }
101 -- * Update functions
103 -- | Changes the primary node of the instance.
104 setPri :: Instance -- ^ the original instance
105 -> T.Ndx -- ^ the new primary node
106 -> Instance -- ^ the modified instance
107 setPri t p = t { pNode = p }
109 -- | Changes the secondary node of the instance.
110 setSec :: Instance -- ^ the original instance
111 -> T.Ndx -- ^ the new secondary node
112 -> Instance -- ^ the modified instance
113 setSec t s = t { sNode = s }
115 -- | Changes both nodes of the instance.
116 setBoth :: Instance -- ^ the original instance
117 -> T.Ndx -- ^ new primary node index
118 -> T.Ndx -- ^ new secondary node index
119 -> Instance -- ^ the modified instance
120 setBoth t p s = t { pNode = p, sNode = s }