Revision 7b2ead5a htools/Ganeti/Config.hs
b/htools/Ganeti/Config.hs | ||
---|---|---|
33 | 33 |
, getInstance |
34 | 34 |
, getInstPrimaryNode |
35 | 35 |
, buildLinkIpInstnameMap |
36 |
, instNodes |
|
36 | 37 |
) where |
37 | 38 |
|
38 | 39 |
import Data.List (foldl') |
39 | 40 |
import qualified Data.Map as M |
41 |
import qualified Data.Set as S |
|
40 | 42 |
import qualified Text.JSON as J |
41 | 43 |
|
42 | 44 |
import Ganeti.HTools.JSON |
... | ... | |
62 | 64 |
|
63 | 65 |
-- * Query functions |
64 | 66 |
|
67 |
-- | Computes the nodes covered by a disk. |
|
68 |
computeDiskNodes :: Disk -> S.Set String |
|
69 |
computeDiskNodes dsk = |
|
70 |
case diskLogicalId dsk of |
|
71 |
LIDDrbd8 nodeA nodeB _ _ _ _ -> S.fromList [nodeA, nodeB] |
|
72 |
_ -> S.empty |
|
73 |
|
|
74 |
-- | Computes all disk-related nodes of an instance. For non-DRBD, |
|
75 |
-- this will be empty, for DRBD it will contain both the primary and |
|
76 |
-- the secondaries. |
|
77 |
instDiskNodes :: Instance -> S.Set String |
|
78 |
instDiskNodes = S.unions . map computeDiskNodes . instDisks |
|
79 |
|
|
80 |
-- | Computes all nodes of an instance. |
|
81 |
instNodes :: Instance -> S.Set String |
|
82 |
instNodes inst = instPrimaryNode inst `S.insert` instDiskNodes inst |
|
83 |
|
|
84 |
-- | Computes the secondary nodes of an instance. Since this is valid |
|
85 |
-- only for DRBD, we call directly 'instDiskNodes', skipping over the |
|
86 |
-- extra primary insert. |
|
87 |
instSecondaryNodes :: Instance -> S.Set String |
|
88 |
instSecondaryNodes inst = |
|
89 |
instPrimaryNode inst `S.delete` instDiskNodes inst |
|
90 |
|
|
65 | 91 |
-- | Get instances of a given node. |
66 | 92 |
getNodeInstances :: ConfigData -> String -> ([Instance], [Instance]) |
67 | 93 |
getNodeInstances cfg nname = |
68 | 94 |
let all_inst = M.elems . configInstances $ cfg |
69 | 95 |
pri_inst = filter ((== nname) . instPrimaryNode) all_inst |
70 |
-- FIXME: actually compute the secondary nodes |
|
71 |
sec_inst = undefined |
|
96 |
sec_inst = filter ((nname `S.member`) . instSecondaryNodes) all_inst |
|
72 | 97 |
in (pri_inst, sec_inst) |
73 | 98 |
|
74 | 99 |
-- | Returns the default cluster link. |
Also available in: Unified diff