2012/10/5 Iustin Pop <[email protected]>:
> The String parameter to 'nodeLiveFieldExtract' is the query2 field
> name, not the RPC-layer field name. Grrr for not having a real data
> type for this.
Huh, this is interesting - I had it with FieldName originally, but
changed since the string values here were the same as names of the
fields used for dictionary creation (see Rpc.hs) and I hoped this can
then be at some point automated.

>
> Furthermore, we add some safety check that we don't return JSNull via
> rsNormal…
>
> Signed-off-by: Iustin Pop <[email protected]>
> ---
>  htools/Ganeti/Query/Node.hs |   38 ++++++++++++++++++++------------------
>  1 file changed, 20 insertions(+), 18 deletions(-)
>
> diff --git a/htools/Ganeti/Query/Node.hs b/htools/Ganeti/Query/Node.hs
> index ded9979..0630754 100644
> --- a/htools/Ganeti/Query/Node.hs
> +++ b/htools/Ganeti/Query/Node.hs
> @@ -72,29 +72,31 @@ nodeLiveFieldsDefs =
>  -- the RPC result.
>  nodeLiveFieldExtract :: String -> RpcResultNodeInfo -> J.JSValue
I may have gaps in my memory (no code on this machine ;) ), but
shouldn't the type be FieldName not String now?

>  nodeLiveFieldExtract "bootid" res =
> -    J.showJSON $ rpcResNodeInfoBootId res
> -nodeLiveFieldExtract "cpu_nodes" res =
> -    jsonHead (rpcResNodeInfoHvInfo res) hvInfoCpuNodes
> -nodeLiveFieldExtract "cpu_sockets" res =
> -    jsonHead (rpcResNodeInfoHvInfo res) hvInfoCpuSockets
> -nodeLiveFieldExtract "cpu_total" res =
> -    jsonHead (rpcResNodeInfoHvInfo res) hvInfoCpuTotal
> -nodeLiveFieldExtract "vg_free" res =
> -    jsonHead (rpcResNodeInfoVgInfo res) vgInfoVgFree
> -nodeLiveFieldExtract "vg_size" res =
> -    jsonHead (rpcResNodeInfoVgInfo res) vgInfoVgSize
> -nodeLiveFieldExtract "memory_free" res =
> -    jsonHead (rpcResNodeInfoHvInfo res) hvInfoMemoryFree
> -nodeLiveFieldExtract "memory_dom0" res =
> -    jsonHead (rpcResNodeInfoHvInfo res) hvInfoMemoryDom0
> -nodeLiveFieldExtract "memory_total" res =
> -    jsonHead (rpcResNodeInfoHvInfo res) hvInfoMemoryTotal
> +  J.showJSON $ rpcResNodeInfoBootId res
> +nodeLiveFieldExtract "cnodes" res =
> +  jsonHead (rpcResNodeInfoHvInfo res) hvInfoCpuNodes
> +nodeLiveFieldExtract "csockets" res =
> +  jsonHead (rpcResNodeInfoHvInfo res) hvInfoCpuSockets
> +nodeLiveFieldExtract "ctotal" res =
> +  jsonHead (rpcResNodeInfoHvInfo res) hvInfoCpuTotal
> +nodeLiveFieldExtract "dfree" res =
> +  jsonHead (rpcResNodeInfoVgInfo res) vgInfoVgFree
> +nodeLiveFieldExtract "dtotal" res =
> +  jsonHead (rpcResNodeInfoVgInfo res) vgInfoVgSize
> +nodeLiveFieldExtract "mfree" res =
> +  jsonHead (rpcResNodeInfoHvInfo res) hvInfoMemoryFree
> +nodeLiveFieldExtract "mnode" res =
> +  jsonHead (rpcResNodeInfoHvInfo res) hvInfoMemoryDom0
> +nodeLiveFieldExtract "mtotal" res =
> +  jsonHead (rpcResNodeInfoHvInfo res) hvInfoMemoryTotal
>  nodeLiveFieldExtract _ _ = J.JSNull
>
>  -- | Helper for extracting field from RPC result.
>  nodeLiveRpcCall :: FieldName -> NodeRuntime -> Node -> ResultEntry
>  nodeLiveRpcCall fname (Right res) _ =
> -    rsNormal (nodeLiveFieldExtract fname res)
> +  case nodeLiveFieldExtract fname res of
> +    J.JSNull -> rsNoData
> +    x -> rsNormal x
>  nodeLiveRpcCall _ (Left err) _ =
>      ResultEntry (rpcErrorToStatus err) Nothing
>
> --
> 1.7.10.4
>

Reply via email to