Revision cca4e6fe htools/Ganeti/Query/Node.hs
b/htools/Ganeti/Query/Node.hs | ||
---|---|---|
31 | 31 |
import Control.Applicative |
32 | 32 |
import Data.List |
33 | 33 |
import qualified Data.Map as Map |
34 |
import qualified Text.JSON as J |
|
34 | 35 |
|
35 | 36 |
import Ganeti.Config |
36 | 37 |
import Ganeti.Objects |
38 |
import Ganeti.JSON |
|
37 | 39 |
import Ganeti.Rpc |
38 | 40 |
import Ganeti.Query.Language |
39 | 41 |
import Ganeti.Query.Common |
... | ... | |
42 | 44 |
-- | NodeRuntime is the resulting type for NodeInfo call. |
43 | 45 |
type NodeRuntime = Either RpcError RpcResultNodeInfo |
44 | 46 |
|
45 |
-- | List of node live fields, all ignored for now (no RPC).
|
|
47 |
-- | List of node live fields. |
|
46 | 48 |
nodeLiveFieldsDefs :: [(FieldName, FieldTitle, FieldType, String, FieldDoc)] |
47 | 49 |
nodeLiveFieldsDefs = |
48 | 50 |
[ ("bootid", "BootID", QFTText, "bootid", |
... | ... | |
66 | 68 |
"Total amount of memory of physical machine") |
67 | 69 |
] |
68 | 70 |
|
71 |
-- | Map each name to a function that extracts that value from |
|
72 |
-- the RPC result. |
|
73 |
nodeLiveFieldExtract :: String -> RpcResultNodeInfo -> J.JSValue |
|
74 |
nodeLiveFieldExtract "bootid" res = |
|
75 |
J.showJSON $ rpcResNodeInfoBootId res |
|
76 |
nodeLiveFieldExtract "cpu_nodes" res = |
|
77 |
jsonHead (rpcResNodeInfoHvInfo res) hvInfoCpuNodes |
|
78 |
nodeLiveFieldExtract "cpu_sockets" res = |
|
79 |
jsonHead (rpcResNodeInfoHvInfo res) hvInfoCpuSockets |
|
80 |
nodeLiveFieldExtract "cpu_total" res = |
|
81 |
jsonHead (rpcResNodeInfoHvInfo res) hvInfoCpuTotal |
|
82 |
nodeLiveFieldExtract "vg_free" res = |
|
83 |
jsonHead (rpcResNodeInfoVgInfo res) vgInfoVgFree |
|
84 |
nodeLiveFieldExtract "vg_size" res = |
|
85 |
jsonHead (rpcResNodeInfoVgInfo res) vgInfoVgSize |
|
86 |
nodeLiveFieldExtract "memory_free" res = |
|
87 |
jsonHead (rpcResNodeInfoHvInfo res) hvInfoMemoryFree |
|
88 |
nodeLiveFieldExtract "memory_dom0" res = |
|
89 |
jsonHead (rpcResNodeInfoHvInfo res) hvInfoMemoryDom0 |
|
90 |
nodeLiveFieldExtract "memory_total" res = |
|
91 |
jsonHead (rpcResNodeInfoHvInfo res) hvInfoMemoryTotal |
|
92 |
nodeLiveFieldExtract _ _ = J.JSNull |
|
93 |
|
|
94 |
-- | Helper for extracting field from RPC result. |
|
95 |
nodeLiveRpcCall :: FieldName -> NodeRuntime -> Node -> ResultEntry |
|
96 |
nodeLiveRpcCall fname (Right res) _ = |
|
97 |
rsNormal (nodeLiveFieldExtract fname res) |
|
98 |
nodeLiveRpcCall _ (Left err) _ = |
|
99 |
ResultEntry (rpcErrorToStatus err) Nothing |
|
100 |
|
|
69 | 101 |
-- | Builder for node live fields. |
70 | 102 |
nodeLiveFieldBuilder :: (FieldName, FieldTitle, FieldType, String, FieldDoc) |
71 | 103 |
-> FieldData Node NodeRuntime |
72 | 104 |
nodeLiveFieldBuilder (fname, ftitle, ftype, _, fdoc) = |
73 |
(FieldDefinition fname ftitle ftype fdoc, missingRuntime) |
|
105 |
( FieldDefinition fname ftitle ftype fdoc |
|
106 |
, FieldRuntime $ nodeLiveRpcCall fname) |
|
74 | 107 |
|
75 | 108 |
-- | The docstring for the node role. Note that we use 'reverse in |
76 | 109 |
-- order to keep the same order as Python. |
Also available in: Unified diff