Statistics
| Branch: | Tag: | Revision:

root / Ganeti / HTools / Instance.hs @ 903a7d46

History | View | Annotate | Download (3.9 kB)

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 where
30

    
31
import qualified Ganeti.HTools.Types as T
32
import qualified Ganeti.HTools.Container as Container
33

    
34
-- * Type declarations
35

    
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
41
                                            -- is running
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
46
                                            -- book-keeping
47
                         } deriving (Show)
48

    
49
instance T.Element Instance where
50
    nameOf  = name
51
    idxOf   = idx
52
    setName = setName
53
    setIdx  = setIdx
54

    
55
-- | A simple name for the int, instance association list.
56
type AssocList = [(T.Idx, Instance)]
57

    
58
-- | A simple name for an instance map.
59
type List = Container.Container Instance
60

    
61
-- * Initialization
62

    
63
-- | Create an instance.
64
--
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 =
69
    Instance {
70
          name = name_init,
71
          mem = mem_init,
72
          dsk = dsk_init,
73
          running = case run_init of
74
                      "running" -> True
75
                      "ERROR_up" -> True
76
                      _ -> False,
77
          run_st = run_init,
78
          pnode = pn,
79
          snode = sn,
80
          idx = -1
81
        }
82

    
83
-- | Changes the index.
84
--
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 }
90

    
91
-- | Changes the name.
92
--
93
-- This is used only during the building of the data structures.
94
setName :: Instance -- ^ The original instance
95
        -> String   -- ^ New name
96
        -> Instance -- ^ The modified instance
97
setName t s = t { name = s }
98

    
99
-- * Update functions
100

    
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 }
106

    
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 }
112

    
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 }