Statistics
| Branch: | Tag: | Revision:

root / Ganeti / HTools / Instance.hs @ 497e30a1

History | View | Annotate | Download (2.5 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 { name :: String   -- ^ the instance name
10
                         , mem :: Int       -- ^ memory of the instance
11
                         , dsk :: Int       -- ^ disk size of instance
12
                         , running :: Bool  -- ^ whether the instance
13
                                            -- is running
14
                         , run_st :: String -- ^ original (text) run status
15
                         , pnode :: Int     -- ^ original primary node
16
                         , snode :: Int     -- ^ original secondary node
17
                         , idx :: Int       -- ^ internal index for
18
                                            -- book-keeping
19
                         } deriving (Show)
20

    
21
-- | A simple name for the int, instance association list
22
type AssocList = [(Int, Instance)]
23

    
24
create :: String -> Int -> Int -> String -> Int -> Int -> Instance
25
create name_init mem_init dsk_init run_init pn sn =
26
    Instance {
27
          name = name_init,
28
          mem = mem_init,
29
          dsk = dsk_init,
30
          running = case run_init of
31
                      "running" -> True
32
                      "ERROR_up" -> True
33
                      _ -> False,
34
          run_st = run_init,
35
          pnode = pn,
36
          snode = sn,
37
          idx = -1
38
        }
39

    
40
-- | Changes the primary node of the instance.
41
setPri :: Instance  -- ^ the original instance
42
        -> Int      -- ^ the new primary node
43
        -> Instance -- ^ the modified instance
44
setPri t p = t { pnode = p }
45

    
46
-- | Changes the secondary node of the instance.
47
setSec :: Instance  -- ^ the original instance
48
        -> Int      -- ^ the new secondary node
49
        -> Instance -- ^ the modified instance
50
setSec t s = t { snode = s }
51

    
52
-- | Changes both nodes of the instance.
53
setBoth :: Instance  -- ^ the original instance
54
         -> Int      -- ^ new primary node index
55
         -> Int      -- ^ new secondary node index
56
         -> Instance -- ^ the modified instance
57
setBoth t p s = t { pnode = p, snode = s }
58

    
59
-- | Changes the index.
60
-- This is used only during the building of the data structures.
61
setIdx :: Instance  -- ^ the original instance
62
        -> Int      -- ^ new index
63
        -> Instance -- ^ the modified instance
64
setIdx t i = t { idx = i }
65

    
66
-- | Changes the name
67
-- This is used only during the building of the data structures.
68
setName t s = t {name = s}