Statistics
| Branch: | Tag: | Revision:

root / Ganeti / HTools / Instance.hs @ 47a8bade

History | View | Annotate | Download (1.7 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
                         , pnode :: Int -- ^ original primary node
12
                         , snode :: Int -- ^ original secondary node
13
                         , idx :: Int   -- ^ internal index for book-keeping
14
                         } deriving (Show)
15

    
16
create :: Int -> Int -> Int -> Int -> Instance
17
create mem_init dsk_init pn sn =
18
    Instance {
19
          mem = mem_init,
20
          dsk = dsk_init,
21
          pnode = pn,
22
          snode = sn,
23
          idx = -1
24
        }
25

    
26
-- | Changes the primary node of the instance.
27
setPri :: Instance  -- ^ the original instance
28
        -> Int      -- ^ the new primary node
29
        -> Instance -- ^ the modified instance
30
setPri t p = t { pnode = p }
31

    
32
-- | Changes the secondary node of the instance.
33
setSec :: Instance  -- ^ the original instance
34
        -> Int      -- ^ the new secondary node
35
        -> Instance -- ^ the modified instance
36
setSec t s = t { snode = s }
37

    
38
-- | Changes both nodes of the instance.
39
setBoth :: Instance  -- ^ the original instance
40
         -> Int      -- ^ new primary node index
41
         -> Int      -- ^ new secondary node index
42
         -> Instance -- ^ the modified instance
43
setBoth t p s = t { pnode = p, snode = s }
44

    
45
-- | Changes the index.
46
-- This is used only during the building of the data structures.
47
setIdx :: Instance  -- ^ the original instance
48
        -> Int      -- ^ new index
49
        -> Instance -- ^ the modified instance
50
setIdx t i = t { idx = i }