root / Ganeti / HTools / Instance.hs @ 9188aeef
History | View | Annotate | Download (3.1 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 |
-- * Type declarations |
13 |
|
14 |
-- | The instance type |
15 |
data Instance = Instance { name :: String -- ^ The instance name |
16 |
, mem :: Int -- ^ Memory of the instance |
17 |
, dsk :: Int -- ^ Disk size of instance |
18 |
, running :: Bool -- ^ Whether the instance |
19 |
-- is running |
20 |
, run_st :: String -- ^ Original (text) run status |
21 |
, pnode :: T.Ndx -- ^ Original primary node |
22 |
, snode :: T.Ndx -- ^ Original secondary node |
23 |
, idx :: T.Idx -- ^ Internal index for |
24 |
-- book-keeping |
25 |
} deriving (Show) |
26 |
|
27 |
instance T.Element Instance where |
28 |
nameOf = name |
29 |
idxOf = idx |
30 |
setName = setName |
31 |
setIdx = setIdx |
32 |
|
33 |
-- | A simple name for the int, instance association list. |
34 |
type AssocList = [(T.Idx, Instance)] |
35 |
|
36 |
-- | A simple name for an instance map. |
37 |
type List = Container.Container Instance |
38 |
|
39 |
-- * Initialization |
40 |
|
41 |
-- | Create an instance. |
42 |
-- |
43 |
-- Some parameters are not initialized by function, and must be set |
44 |
-- later (via 'setIdx' for example). |
45 |
create :: String -> Int -> Int -> String -> T.Ndx -> T.Ndx -> Instance |
46 |
create name_init mem_init dsk_init run_init pn sn = |
47 |
Instance { |
48 |
name = name_init, |
49 |
mem = mem_init, |
50 |
dsk = dsk_init, |
51 |
running = case run_init of |
52 |
"running" -> True |
53 |
"ERROR_up" -> True |
54 |
_ -> False, |
55 |
run_st = run_init, |
56 |
pnode = pn, |
57 |
snode = sn, |
58 |
idx = -1 |
59 |
} |
60 |
|
61 |
-- | Changes the index. |
62 |
-- |
63 |
-- This is used only during the building of the data structures. |
64 |
setIdx :: Instance -- ^ the original instance |
65 |
-> T.Idx -- ^ new index |
66 |
-> Instance -- ^ the modified instance |
67 |
setIdx t i = t { idx = i } |
68 |
|
69 |
-- | Changes the name. |
70 |
-- |
71 |
-- This is used only during the building of the data structures. |
72 |
setName :: Instance -- ^ The original instance |
73 |
-> String -- ^ New name |
74 |
-> Instance |
75 |
setName t s = t { name = s } |
76 |
|
77 |
-- * Update functions |
78 |
|
79 |
-- | Changes the primary node of the instance. |
80 |
setPri :: Instance -- ^ the original instance |
81 |
-> T.Ndx -- ^ the new primary node |
82 |
-> Instance -- ^ the modified instance |
83 |
setPri t p = t { pnode = p } |
84 |
|
85 |
-- | Changes the secondary node of the instance. |
86 |
setSec :: Instance -- ^ the original instance |
87 |
-> T.Ndx -- ^ the new secondary node |
88 |
-> Instance -- ^ the modified instance |
89 |
setSec t s = t { snode = s } |
90 |
|
91 |
-- | Changes both nodes of the instance. |
92 |
setBoth :: Instance -- ^ the original instance |
93 |
-> T.Ndx -- ^ new primary node index |
94 |
-> T.Ndx -- ^ new secondary node index |
95 |
-> Instance -- ^ the modified instance |
96 |
setBoth t p s = t { pnode = p, snode = s } |