root / Ganeti / HTools / Instance.hs @ 608efcce
History | View | Annotate | Download (2.8 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 | 262a08a2 | Iustin Pop | import qualified Ganeti.HTools.Types as T |
10 | 262a08a2 | Iustin Pop | import qualified Ganeti.HTools.Container as Container |
11 | 262a08a2 | Iustin Pop | |
12 | 2727257a | Iustin Pop | data Instance = Instance { name :: String -- ^ the instance name |
13 | 2727257a | Iustin Pop | , mem :: Int -- ^ memory of the instance |
14 | f82f1f39 | Iustin Pop | , dsk :: Int -- ^ disk size of instance |
15 | f82f1f39 | Iustin Pop | , running :: Bool -- ^ whether the instance |
16 | f82f1f39 | Iustin Pop | -- is running |
17 | f82f1f39 | Iustin Pop | , run_st :: String -- ^ original (text) run status |
18 | 608efcce | Iustin Pop | , pnode :: T.Ndx -- ^ original primary node |
19 | 608efcce | Iustin Pop | , snode :: T.Ndx -- ^ original secondary node |
20 | 608efcce | Iustin Pop | , idx :: T.Idx -- ^ internal index for |
21 | f82f1f39 | Iustin Pop | -- book-keeping |
22 | e4f08c46 | Iustin Pop | } deriving (Show) |
23 | e4f08c46 | Iustin Pop | |
24 | 262a08a2 | Iustin Pop | instance T.Element Instance where |
25 | 262a08a2 | Iustin Pop | nameOf = name |
26 | 262a08a2 | Iustin Pop | idxOf = idx |
27 | 262a08a2 | Iustin Pop | setName = setName |
28 | 262a08a2 | Iustin Pop | setIdx = setIdx |
29 | 262a08a2 | Iustin Pop | |
30 | 040afc35 | Iustin Pop | -- | A simple name for the int, instance association list |
31 | 608efcce | Iustin Pop | type AssocList = [(T.Idx, Instance)] |
32 | 040afc35 | Iustin Pop | |
33 | 262a08a2 | Iustin Pop | -- | A simple name for an instance map |
34 | 262a08a2 | Iustin Pop | type List = Container.Container Instance |
35 | 262a08a2 | Iustin Pop | |
36 | 608efcce | Iustin Pop | create :: String -> Int -> Int -> String -> T.Ndx -> T.Ndx -> Instance |
37 | 2727257a | Iustin Pop | create name_init mem_init dsk_init run_init pn sn = |
38 | 47a8bade | Iustin Pop | Instance { |
39 | 2727257a | Iustin Pop | name = name_init, |
40 | 47a8bade | Iustin Pop | mem = mem_init, |
41 | 47a8bade | Iustin Pop | dsk = dsk_init, |
42 | f82f1f39 | Iustin Pop | running = case run_init of |
43 | f82f1f39 | Iustin Pop | "running" -> True |
44 | f82f1f39 | Iustin Pop | "ERROR_up" -> True |
45 | f82f1f39 | Iustin Pop | _ -> False, |
46 | f82f1f39 | Iustin Pop | run_st = run_init, |
47 | 47a8bade | Iustin Pop | pnode = pn, |
48 | 47a8bade | Iustin Pop | snode = sn, |
49 | 47a8bade | Iustin Pop | idx = -1 |
50 | 47a8bade | Iustin Pop | } |
51 | e4f08c46 | Iustin Pop | |
52 | e4f08c46 | Iustin Pop | -- | Changes the primary node of the instance. |
53 | fd934a28 | Iustin Pop | setPri :: Instance -- ^ the original instance |
54 | 608efcce | Iustin Pop | -> T.Ndx -- ^ the new primary node |
55 | e4f08c46 | Iustin Pop | -> Instance -- ^ the modified instance |
56 | e4f08c46 | Iustin Pop | setPri t p = t { pnode = p } |
57 | e4f08c46 | Iustin Pop | |
58 | e4f08c46 | Iustin Pop | -- | Changes the secondary node of the instance. |
59 | fd934a28 | Iustin Pop | setSec :: Instance -- ^ the original instance |
60 | 608efcce | Iustin Pop | -> T.Ndx -- ^ the new secondary node |
61 | e4f08c46 | Iustin Pop | -> Instance -- ^ the modified instance |
62 | e4f08c46 | Iustin Pop | setSec t s = t { snode = s } |
63 | e4f08c46 | Iustin Pop | |
64 | e4f08c46 | Iustin Pop | -- | Changes both nodes of the instance. |
65 | fd934a28 | Iustin Pop | setBoth :: Instance -- ^ the original instance |
66 | 608efcce | Iustin Pop | -> T.Ndx -- ^ new primary node index |
67 | 608efcce | Iustin Pop | -> T.Ndx -- ^ new secondary node index |
68 | e4f08c46 | Iustin Pop | -> Instance -- ^ the modified instance |
69 | e4f08c46 | Iustin Pop | setBoth t p s = t { pnode = p, snode = s } |
70 | e4f08c46 | Iustin Pop | |
71 | e4f08c46 | Iustin Pop | -- | Changes the index. |
72 | e4f08c46 | Iustin Pop | -- This is used only during the building of the data structures. |
73 | fd934a28 | Iustin Pop | setIdx :: Instance -- ^ the original instance |
74 | 608efcce | Iustin Pop | -> T.Idx -- ^ new index |
75 | e4f08c46 | Iustin Pop | -> Instance -- ^ the modified instance |
76 | e4f08c46 | Iustin Pop | setIdx t i = t { idx = i } |
77 | 497e30a1 | Iustin Pop | |
78 | 497e30a1 | Iustin Pop | -- | Changes the name |
79 | 497e30a1 | Iustin Pop | -- This is used only during the building of the data structures. |
80 | 262a08a2 | Iustin Pop | setName t s = t { name = s } |