Revision e86c9deb src/Ganeti/Query/Node.hs

b/src/Ganeti/Query/Node.hs
263 263
rpcResultNodeBroken :: Node -> (Node, Runtime)
264 264
rpcResultNodeBroken node = (node, Left (RpcResultError "Broken configuration"))
265 265

  
266
-- | Storage-related query fields
267
storageFields :: [String]
268
storageFields = ["dtotal", "dfree", "spfree", "sptotal"]
269

  
270
-- | Hypervisor-related query fields
271
hypervisorFields :: [String]
272
hypervisorFields = ["mnode", "mfree", "mtotal",
273
                    "cnodes", "csockets", "cnos", "ctotal"]
274

  
275
-- | Check if it is required to include domain-specific entities (for example
276
-- storage units for storage info, hypervisor specs for hypervisor info)
277
-- in the node_info call
278
queryDomainRequired :: -- domain-specific fields to look for (storage, hv)
279
                      [String]
280
                      -- list of requested fields
281
                   -> [String]
282
                   -> Bool
283
queryDomainRequired domain_fields fields = any (`elem` fields) domain_fields
284

  
266 285
-- | Collect live data from RPC query if enabled.
267
--
268
-- FIXME: Check which fields we actually need and possibly send empty
269
-- hvs\/vgs if no info from hypervisor\/volume group respectively is
270
-- required
271
collectLiveData:: Bool -> ConfigData -> [Node] -> IO [(Node, Runtime)]
272
collectLiveData False _ nodes =
286
collectLiveData :: Bool
287
                -> ConfigData
288
                -> [String]
289
                -> [Node]
290
                -> IO [(Node, Runtime)]
291
collectLiveData False _ _ nodes =
273 292
  return $ zip nodes (repeat $ Left (RpcResultError "Live data disabled"))
274
collectLiveData True cfg nodes = do
275
  let hvs = [getDefaultHypervisorSpec cfg]
293
collectLiveData True cfg fields nodes = do
294
  let hvs = [getDefaultHypervisorSpec cfg |
295
             queryDomainRequired hypervisorFields fields]
276 296
      good_nodes = nodesWithValidConfig cfg nodes
277
      -- FIXME: use storage units from calling code
278
      storage_units = getStorageUnitsOfNodes cfg good_nodes
297
      storage_units = if queryDomainRequired storageFields fields
298
                        then getStorageUnitsOfNodes cfg good_nodes
299
                        else Map.fromList
300
                          (map (\n -> (nodeUuid n, [])) good_nodes)
279 301
  rpcres <- executeRpcCall good_nodes (RpcCallNodeInfo storage_units hvs)
280 302
  return $ fillUpList (fillPairFromMaybe rpcResultNodeBroken pickPairUnique)
281 303
      nodes rpcres

Also available in: Unified diff