Skip to content
Snippets Groups Projects
Commit d81ec8b7 authored by Iustin Pop's avatar Iustin Pop
Browse files

Implement a node to drbd minors query function


This can be queried remotely since it's a pure configuration query.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 792f8e55
No related branches found
No related tags found
No related merge requests found
...@@ -73,6 +73,7 @@ $(declareIADT "ConfdRequestType" ...@@ -73,6 +73,7 @@ $(declareIADT "ConfdRequestType"
, ("ReqClusterMaster", 'C.confdReqClusterMaster ) , ("ReqClusterMaster", 'C.confdReqClusterMaster )
, ("ReqMcPipList", 'C.confdReqMcPipList ) , ("ReqMcPipList", 'C.confdReqMcPipList )
, ("ReqInstIpsList", 'C.confdReqInstancesIpsList ) , ("ReqInstIpsList", 'C.confdReqInstancesIpsList )
, ("ReqNodeDrbd", 'C.confdReqNodeDrbd )
]) ])
$(makeJSONInstance ''ConfdRequestType) $(makeJSONInstance ''ConfdRequestType)
......
...@@ -227,6 +227,19 @@ buildResponse cdata (ConfdRequest { confdRqType = ReqNodePipByInstPip ...@@ -227,6 +227,19 @@ buildResponse cdata (ConfdRequest { confdRqType = ReqNodePipByInstPip
buildResponse _ (ConfdRequest { confdRqType = ReqNodePipByInstPip }) = buildResponse _ (ConfdRequest { confdRqType = ReqNodePipByInstPip }) =
return queryArgumentError return queryArgumentError
buildResponse cdata req@(ConfdRequest { confdRqType = ReqNodeDrbd }) = do
let cfg = fst cdata
node_name <- case confdRqQuery req of
PlainQuery str -> return str
_ -> fail $ "Invalid query type " ++ show (confdRqQuery req)
node <- getNode cfg node_name
let minors = concatMap (getInstMinorsForNode (nodeName node)) .
M.elems . configInstances $ cfg
encoded = [J.JSArray [J.showJSON a, J.showJSON b, J.showJSON c,
J.showJSON d, J.showJSON e, J.showJSON f] |
(a, b, c, d, e, f) <- minors]
return (ReplyStatusOk, J.showJSON encoded)
-- | Parses a signed request. -- | Parses a signed request.
parseRequest :: HashKey -> String -> Result (String, String, ConfdRequest) parseRequest :: HashKey -> String -> Result (String, String, ConfdRequest)
parseRequest key str = do parseRequest key str = do
......
...@@ -32,6 +32,7 @@ module Ganeti.Config ...@@ -32,6 +32,7 @@ module Ganeti.Config
, getNode , getNode
, getInstance , getInstance
, getInstPrimaryNode , getInstPrimaryNode
, getInstMinorsForNode
, buildLinkIpInstnameMap , buildLinkIpInstnameMap
, instNodes , instNodes
) where ) where
...@@ -133,6 +134,43 @@ getInstPrimaryNode :: ConfigData -> String -> Result Node ...@@ -133,6 +134,43 @@ getInstPrimaryNode :: ConfigData -> String -> Result Node
getInstPrimaryNode cfg name = getInstPrimaryNode cfg name =
getInstance cfg name >>= return . instPrimaryNode >>= getNode cfg getInstance cfg name >>= return . instPrimaryNode >>= getNode cfg
-- | Filters DRBD minors for a given node.
getDrbdMinorsForNode :: String -> Disk -> [(Int, String)]
getDrbdMinorsForNode node disk =
let child_minors = concatMap (getDrbdMinorsForNode node) (diskChildren disk)
this_minors =
case diskLogicalId disk of
LIDDrbd8 nodeA nodeB _ minorA minorB _
| nodeA == node -> [(minorA, nodeB)]
| nodeB == node -> [(minorB, nodeA)]
_ -> []
in this_minors ++ child_minors
-- | String for primary role.
rolePrimary :: String
rolePrimary = "primary"
-- | String for secondary role.
roleSecondary :: String
roleSecondary = "secondary"
-- | Gets the list of DRBD minors for an instance that are related to
-- a given node.
getInstMinorsForNode :: String -> Instance
-> [(String, Int, String, String, String, String)]
getInstMinorsForNode node inst =
let role = if node == instPrimaryNode inst
then rolePrimary
else roleSecondary
iname = instName inst
-- FIXME: the disk/ build there is hack-ish; unify this in a
-- separate place, or reuse the iv_name (but that is deprecated on
-- the Python side)
in concatMap (\(idx, dsk) ->
[(node, minor, iname, "disk/" ++ show idx, role, peer)
| (minor, peer) <- getDrbdMinorsForNode node dsk]) .
zip [(0::Int)..] . instDisks $ inst
-- | Builds link -> ip -> instname map. -- | Builds link -> ip -> instname map.
-- --
-- TODO: improve this by splitting it into multiple independent functions: -- TODO: improve this by splitting it into multiple independent functions:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment