Revision 1a0dacf6 src/Ganeti/Config.hs
b/src/Ganeti/Config.hs | ||
---|---|---|
47 | 47 |
, getInstPrimaryNode |
48 | 48 |
, getInstMinorsForNode |
49 | 49 |
, getInstAllNodes |
50 |
, getInstDisks |
|
50 | 51 |
, getFilledInstHvParams |
51 | 52 |
, getFilledInstBeParams |
52 | 53 |
, getFilledInstOsParams |
... | ... | |
99 | 100 |
-- | Computes all disk-related nodes of an instance. For non-DRBD, |
100 | 101 |
-- this will be empty, for DRBD it will contain both the primary and |
101 | 102 |
-- the secondaries. |
102 |
instDiskNodes :: Instance -> S.Set String |
|
103 |
instDiskNodes = S.unions . map computeDiskNodes . instDisks |
|
103 |
instDiskNodes :: ConfigData -> Instance -> S.Set String |
|
104 |
instDiskNodes cfg inst = |
|
105 |
case getInstDisks cfg (instName inst) of |
|
106 |
Ok disks -> S.unions $ map computeDiskNodes disks |
|
107 |
Bad _ -> S.empty |
|
104 | 108 |
|
105 | 109 |
-- | Computes all nodes of an instance. |
106 |
instNodes :: Instance -> S.Set String |
|
107 |
instNodes inst = instPrimaryNode inst `S.insert` instDiskNodes inst
|
|
110 |
instNodes :: ConfigData -> Instance -> S.Set String
|
|
111 |
instNodes cfg inst = instPrimaryNode inst `S.insert` instDiskNodes cfg inst
|
|
108 | 112 |
|
109 | 113 |
-- | Computes the secondary nodes of an instance. Since this is valid |
110 | 114 |
-- only for DRBD, we call directly 'instDiskNodes', skipping over the |
111 | 115 |
-- extra primary insert. |
112 |
instSecondaryNodes :: Instance -> S.Set String |
|
113 |
instSecondaryNodes inst = |
|
114 |
instPrimaryNode inst `S.delete` instDiskNodes inst |
|
116 |
instSecondaryNodes :: ConfigData -> Instance -> S.Set String
|
|
117 |
instSecondaryNodes cfg inst =
|
|
118 |
instPrimaryNode inst `S.delete` instDiskNodes cfg inst
|
|
115 | 119 |
|
116 | 120 |
-- | Get instances of a given node. |
117 | 121 |
-- The node is specified through its UUID. |
... | ... | |
119 | 123 |
getNodeInstances cfg nname = |
120 | 124 |
let all_inst = M.elems . fromContainer . configInstances $ cfg |
121 | 125 |
pri_inst = filter ((== nname) . instPrimaryNode) all_inst |
122 |
sec_inst = filter ((nname `S.member`) . instSecondaryNodes) all_inst |
|
126 |
sec_inst = filter ((nname `S.member`) . instSecondaryNodes cfg) all_inst
|
|
123 | 127 |
in (pri_inst, sec_inst) |
124 | 128 |
|
125 | 129 |
-- | Computes the role of a node. |
... | ... | |
314 | 318 |
-- the primary node has to be appended to the results. |
315 | 319 |
getInstAllNodes :: ConfigData -> String -> ErrorResult [Node] |
316 | 320 |
getInstAllNodes cfg name = do |
317 |
inst <- getInstance cfg name
|
|
318 |
let diskNodes = concatMap (getDrbdDiskNodes cfg) $ instDisks inst
|
|
321 |
inst_disks <- getInstDisks cfg name
|
|
322 |
let diskNodes = concatMap (getDrbdDiskNodes cfg) inst_disks
|
|
319 | 323 |
pNode <- getInstPrimaryNode cfg name |
320 | 324 |
return . nub $ pNode:diskNodes |
321 | 325 |
|
322 | 326 |
-- | Get disks for a given instance. |
323 | 327 |
-- The instance is specified by name or uuid. |
324 |
--getInstDisks :: ConfigData -> String -> ErrorResult [Disk]
|
|
325 |
--getInstDisks cfg iname = do
|
|
326 |
-- let inst = getInstance cfg iname
|
|
327 |
-- mapM (getDisk cfg) $ instDisks inst
|
|
328 |
getInstDisks :: ConfigData -> String -> ErrorResult [Disk] |
|
329 |
getInstDisks cfg iname = do |
|
330 |
inst <- getInstance cfg iname
|
|
331 |
mapM (getDisk cfg) $ instDisks inst |
|
328 | 332 |
|
329 | 333 |
-- | Filters DRBD minors for a given node. |
330 | 334 |
getDrbdMinorsForNode :: String -> Disk -> [(Int, String)] |
... | ... | |
348 | 352 |
|
349 | 353 |
-- | Gets the list of DRBD minors for an instance that are related to |
350 | 354 |
-- a given node. |
351 |
getInstMinorsForNode :: String -> Instance |
|
355 |
getInstMinorsForNode :: ConfigData -> String -> Instance
|
|
352 | 356 |
-> [(String, Int, String, String, String, String)] |
353 |
getInstMinorsForNode node inst = |
|
357 |
getInstMinorsForNode cfg node inst =
|
|
354 | 358 |
let role = if node == instPrimaryNode inst |
355 | 359 |
then rolePrimary |
356 | 360 |
else roleSecondary |
357 | 361 |
iname = instName inst |
362 |
inst_disks = case getInstDisks cfg (instName inst) of |
|
363 |
Ok disks -> disks |
|
364 |
Bad _ -> [] |
|
358 | 365 |
-- FIXME: the disk/ build there is hack-ish; unify this in a |
359 | 366 |
-- separate place, or reuse the iv_name (but that is deprecated on |
360 | 367 |
-- the Python side) |
361 | 368 |
in concatMap (\(idx, dsk) -> |
362 | 369 |
[(node, minor, iname, "disk/" ++ show idx, role, peer) |
363 | 370 |
| (minor, peer) <- getDrbdMinorsForNode node dsk]) . |
364 |
zip [(0::Int)..] . instDisks $ inst
|
|
371 |
zip [(0::Int)..] $ inst_disks
|
|
365 | 372 |
|
366 | 373 |
-- | Builds link -> ip -> instname map. |
367 | 374 |
-- |
Also available in: Unified diff