On Tue, Sep 25, 2012 at 06:43:53PM +0200, Agata Murawska wrote:
> Added support for NodeInfo RPC call as source of data for node query.
> 
> Signed-off-by: Agata Murawska <[email protected]>
> ---
>  htools/Ganeti/Query/Node.hs |   37 +++++++++++++++++++++++++++++++++++--
>  1 files changed, 35 insertions(+), 2 deletions(-)
> 
> diff --git a/htools/Ganeti/Query/Node.hs b/htools/Ganeti/Query/Node.hs
> index cc88b4f..1857123 100644
> --- a/htools/Ganeti/Query/Node.hs
> +++ b/htools/Ganeti/Query/Node.hs
> @@ -31,9 +31,11 @@ module Ganeti.Query.Node
>  import Control.Applicative
>  import Data.List
>  import qualified Data.Map as Map
> +import qualified Text.JSON as J
>  
>  import Ganeti.Config
>  import Ganeti.Objects
> +import Ganeti.JSON
>  import Ganeti.Rpc
>  import Ganeti.Query.Language
>  import Ganeti.Query.Common
> @@ -42,7 +44,7 @@ import Ganeti.Query.Types
>  -- | NodeRuntime is the resulting type for NodeInfo call.
>  type NodeRuntime = Either RpcError RpcResultNodeInfo
>  
> --- | List of node live fields, all ignored for now (no RPC).
> +-- | List of node live fields.
>  nodeLiveFieldsDefs :: [(FieldName, FieldTitle, FieldType, String, FieldDoc)]
>  nodeLiveFieldsDefs =
>    [ ("bootid", "BootID", QFTText, "bootid",
> @@ -66,11 +68,42 @@ nodeLiveFieldsDefs =
>       "Total amount of memory of physical machine")
>    ]
>  
> +-- | Map each name to a function that extracts that value from
> +-- the RPC result.
> +nodeLiveFieldExtract :: String -> RpcResultNodeInfo -> J.JSValue
> +nodeLiveFieldExtract "bootid" res =
> +    J.showJSON $ rpcResNodeInfoBootId res
> +nodeLiveFieldExtract "cpu_nodes" res =
> +    jsonNullOrFirst (rpcResNodeInfoHvInfo res) hvInfoCpuNodes
> +nodeLiveFieldExtract "cpu_sockets" res =
> +    jsonNullOrFirst (rpcResNodeInfoHvInfo res) hvInfoCpuSockets
> +nodeLiveFieldExtract "cpu_total" res =
> +    jsonNullOrFirst (rpcResNodeInfoHvInfo res) hvInfoCpuTotal
> +nodeLiveFieldExtract "vg_free" res =
> +    jsonNullOrFirst (rpcResNodeInfoVgInfo res) vgInfoVgFree
> +nodeLiveFieldExtract "vg_size" res =
> +    jsonNullOrFirst (rpcResNodeInfoVgInfo res) vgInfoVgSize
> +nodeLiveFieldExtract "memory_free" res =
> +    jsonNullOrFirst (rpcResNodeInfoHvInfo res) hvInfoMemoryFree
> +nodeLiveFieldExtract "memory_dom0" res =
> +    jsonNullOrFirst (rpcResNodeInfoHvInfo res) hvInfoMemoryDom0
> +nodeLiveFieldExtract "memory_total" res =
> +    jsonNullOrFirst (rpcResNodeInfoHvInfo res) hvInfoMemoryTotal
> +nodeLiveFieldExtract _ _ = J.JSNull
> +
> +-- | Helper for extracting field from RPC result.
> +nodeLiveRpcCall :: FieldName -> NodeRuntime -> Node -> ResultEntry
> +nodeLiveRpcCall fname (Right res) _ =
> +    ResultEntry RSNormal (Just $ nodeLiveFieldExtract fname res)

Please use rsNormal helper here… then LGTM.

iustin

Reply via email to