Statistics
| Branch: | Tag: | Revision:

root / Ganeti / HTools / Instance.hs @ b0517d61

History | View | Annotate | Download (2.2 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
module Ganeti.HTools.Instance where
8

    
9
data Instance = Instance { mem :: Int       -- ^ memory of the instance
10
                         , dsk :: Int       -- ^ disk size of instance
11
                         , running :: Bool  -- ^ whether the instance
12
                                            -- is running
13
                         , run_st :: String -- ^ original (text) run status
14
                         , pnode :: Int     -- ^ original primary node
15
                         , snode :: Int     -- ^ original secondary node
16
                         , idx :: Int       -- ^ internal index for
17
                                            -- book-keeping
18
                         } deriving (Show)
19

    
20
create :: Int -> Int -> String -> Int -> Int -> Instance
21
create mem_init dsk_init run_init pn sn =
22
    Instance {
23
          mem = mem_init,
24
          dsk = dsk_init,
25
          running = case run_init of
26
                      "running" -> True
27
                      "ERROR_up" -> True
28
                      _ -> False,
29
          run_st = run_init,
30
          pnode = pn,
31
          snode = sn,
32
          idx = -1
33
        }
34

    
35
-- | Changes the primary node of the instance.
36
setPri :: Instance  -- ^ the original instance
37
        -> Int      -- ^ the new primary node
38
        -> Instance -- ^ the modified instance
39
setPri t p = t { pnode = p }
40

    
41
-- | Changes the secondary node of the instance.
42
setSec :: Instance  -- ^ the original instance
43
        -> Int      -- ^ the new secondary node
44
        -> Instance -- ^ the modified instance
45
setSec t s = t { snode = s }
46

    
47
-- | Changes both nodes of the instance.
48
setBoth :: Instance  -- ^ the original instance
49
         -> Int      -- ^ new primary node index
50
         -> Int      -- ^ new secondary node index
51
         -> Instance -- ^ the modified instance
52
setBoth t p s = t { pnode = p, snode = s }
53

    
54
-- | Changes the index.
55
-- This is used only during the building of the data structures.
56
setIdx :: Instance  -- ^ the original instance
57
        -> Int      -- ^ new index
58
        -> Instance -- ^ the modified instance
59
setIdx t i = t { idx = i }