Statistics
| Branch: | Tag: | Revision:

root / Ganeti / HTools / Instance.hs @ 5aa48dbe

History | View | Annotate | Download (2.2 kB)

1 e4f08c46 Iustin Pop
{-| Module describing an instance.
2 e4f08c46 Iustin Pop
3 e4f08c46 Iustin Pop
The instance data type holds very few fields, the algorithm
4 e4f08c46 Iustin Pop
intelligence is in the "Node" and "Cluster" modules.
5 e4f08c46 Iustin Pop
6 e4f08c46 Iustin Pop
-}
7 669d7e3d Iustin Pop
module Ganeti.HTools.Instance where
8 e4f08c46 Iustin Pop
9 f82f1f39 Iustin Pop
data Instance = Instance { mem :: Int       -- ^ memory of the instance
10 f82f1f39 Iustin Pop
                         , dsk :: Int       -- ^ disk size of instance
11 f82f1f39 Iustin Pop
                         , running :: Bool  -- ^ whether the instance
12 f82f1f39 Iustin Pop
                                            -- is running
13 f82f1f39 Iustin Pop
                         , run_st :: String -- ^ original (text) run status
14 f82f1f39 Iustin Pop
                         , pnode :: Int     -- ^ original primary node
15 f82f1f39 Iustin Pop
                         , snode :: Int     -- ^ original secondary node
16 f82f1f39 Iustin Pop
                         , idx :: Int       -- ^ internal index for
17 f82f1f39 Iustin Pop
                                            -- book-keeping
18 e4f08c46 Iustin Pop
                         } deriving (Show)
19 e4f08c46 Iustin Pop
20 f82f1f39 Iustin Pop
create :: Int -> Int -> String -> Int -> Int -> Instance
21 f82f1f39 Iustin Pop
create mem_init dsk_init run_init pn sn =
22 47a8bade Iustin Pop
    Instance {
23 47a8bade Iustin Pop
          mem = mem_init,
24 47a8bade Iustin Pop
          dsk = dsk_init,
25 f82f1f39 Iustin Pop
          running = case run_init of
26 f82f1f39 Iustin Pop
                      "running" -> True
27 f82f1f39 Iustin Pop
                      "ERROR_up" -> True
28 f82f1f39 Iustin Pop
                      _ -> False,
29 f82f1f39 Iustin Pop
          run_st = run_init,
30 47a8bade Iustin Pop
          pnode = pn,
31 47a8bade Iustin Pop
          snode = sn,
32 47a8bade Iustin Pop
          idx = -1
33 47a8bade Iustin Pop
        }
34 e4f08c46 Iustin Pop
35 e4f08c46 Iustin Pop
-- | Changes the primary node of the instance.
36 fd934a28 Iustin Pop
setPri :: Instance  -- ^ the original instance
37 fd934a28 Iustin Pop
        -> Int      -- ^ the new primary node
38 e4f08c46 Iustin Pop
        -> Instance -- ^ the modified instance
39 e4f08c46 Iustin Pop
setPri t p = t { pnode = p }
40 e4f08c46 Iustin Pop
41 e4f08c46 Iustin Pop
-- | Changes the secondary node of the instance.
42 fd934a28 Iustin Pop
setSec :: Instance  -- ^ the original instance
43 fd934a28 Iustin Pop
        -> Int      -- ^ the new secondary node
44 e4f08c46 Iustin Pop
        -> Instance -- ^ the modified instance
45 e4f08c46 Iustin Pop
setSec t s = t { snode = s }
46 e4f08c46 Iustin Pop
47 e4f08c46 Iustin Pop
-- | Changes both nodes of the instance.
48 fd934a28 Iustin Pop
setBoth :: Instance  -- ^ the original instance
49 fd934a28 Iustin Pop
         -> Int      -- ^ new primary node index
50 fd934a28 Iustin Pop
         -> Int      -- ^ new secondary node index
51 e4f08c46 Iustin Pop
         -> Instance -- ^ the modified instance
52 e4f08c46 Iustin Pop
setBoth t p s = t { pnode = p, snode = s }
53 e4f08c46 Iustin Pop
54 e4f08c46 Iustin Pop
-- | Changes the index.
55 e4f08c46 Iustin Pop
-- This is used only during the building of the data structures.
56 fd934a28 Iustin Pop
setIdx :: Instance  -- ^ the original instance
57 fd934a28 Iustin Pop
        -> Int      -- ^ new index
58 e4f08c46 Iustin Pop
        -> Instance -- ^ the modified instance
59 e4f08c46 Iustin Pop
setIdx t i = t { idx = i }