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