Revision 4efa6249 src/Ganeti/Confd/Server.hs
b/src/Ganeti/Confd/Server.hs | ||
---|---|---|
29 | 29 |
, prepMain |
30 | 30 |
) where |
31 | 31 |
|
32 |
import Control.Applicative((<$>)) |
|
32 | 33 |
import Control.Concurrent |
33 | 34 |
import Control.Monad (forever, liftM) |
34 | 35 |
import Data.IORef |
... | ... | |
112 | 113 |
Bad _ -> queryUnknownEntry -- either instance or node not found |
113 | 114 |
Ok node -> (ReplyStatusOk, J.showJSON (nodePrimaryIp node)) |
114 | 115 |
|
116 |
-- | Returns a node name for a given UUID |
|
117 |
uuidToNodeName :: ConfigData -> String -> Result String |
|
118 |
uuidToNodeName cfg uuid = gntErrorToResult $ nodeName <$> getNode cfg uuid |
|
119 |
|
|
120 |
-- | Encodes a list of minors into a JSON representation, converting UUIDs to |
|
121 |
-- names in the process |
|
122 |
encodeMinors :: ConfigData -> (String, Int, String, String, String, String) |
|
123 |
-> Result J.JSValue |
|
124 |
encodeMinors cfg (node_uuid, a, b, c, d, peer_uuid) = do |
|
125 |
node_name <- uuidToNodeName cfg node_uuid |
|
126 |
peer_name <- uuidToNodeName cfg peer_uuid |
|
127 |
return . J.JSArray $ [J.showJSON node_name, J.showJSON a, J.showJSON b, |
|
128 |
J.showJSON c, J.showJSON d, J.showJSON peer_name] |
|
129 |
|
|
115 | 130 |
-- | Builds the response to a given query. |
116 | 131 |
buildResponse :: (ConfigData, LinkIpMap) -> ConfdRequest -> Result StatusAnswer |
117 | 132 |
buildResponse (cfg, _) (ConfdRequest { confdRqType = ReqPing }) = |
... | ... | |
186 | 201 |
PlainQuery str -> return str |
187 | 202 |
_ -> fail $ "Invalid query type " ++ show (confdRqQuery req) |
188 | 203 |
node <- gntErrorToResult $ getNode cfg node_name |
189 |
let minors = concatMap (getInstMinorsForNode (nodeName node)) .
|
|
204 |
let minors = concatMap (getInstMinorsForNode (nodeUuid node)) .
|
|
190 | 205 |
M.elems . fromContainer . configInstances $ cfg |
191 |
encoded = [J.JSArray [J.showJSON a, J.showJSON b, J.showJSON c, |
|
192 |
J.showJSON d, J.showJSON e, J.showJSON f] | |
|
193 |
(a, b, c, d, e, f) <- minors] |
|
206 |
encoded <- mapM (encodeMinors cfg) minors |
|
194 | 207 |
return (ReplyStatusOk, J.showJSON encoded) |
195 | 208 |
|
196 | 209 |
-- | Return the list of instances for a node (as ([primary], [secondary])) given |
Also available in: Unified diff