Revision 36162faf src/Ganeti/Query/Node.hs

b/src/Ganeti/Query/Node.hs
4 4

  
5 5
{-
6 6

  
7
Copyright (C) 2012 Google Inc.
7
Copyright (C) 2012, 2013 Google Inc.
8 8

  
9 9
This program is free software; you can redistribute it and/or modify
10 10
it under the terms of the GNU General Public License as published by
......
24 24
-}
25 25

  
26 26
module Ganeti.Query.Node
27
  ( NodeRuntime
28
  , nodeFieldsMap
29
  , maybeCollectLiveData
27
  ( Runtime
28
  , fieldsMap
29
  , collectLiveData
30 30
  ) where
31 31

  
32 32
import Control.Applicative
......
42 42
import Ganeti.Query.Common
43 43
import Ganeti.Query.Types
44 44

  
45
-- | NodeRuntime is the resulting type for NodeInfo call.
46
type NodeRuntime = Either RpcError RpcResultNodeInfo
45
-- | Runtime is the resulting type for NodeInfo call.
46
type Runtime = Either RpcError RpcResultNodeInfo
47 47

  
48 48
-- | List of node live fields.
49 49
nodeLiveFieldsDefs :: [(FieldName, FieldTitle, FieldType, String, FieldDoc)]
......
93 93
nodeLiveFieldExtract _ _ = J.JSNull
94 94

  
95 95
-- | Helper for extracting field from RPC result.
96
nodeLiveRpcCall :: FieldName -> NodeRuntime -> Node -> ResultEntry
96
nodeLiveRpcCall :: FieldName -> Runtime -> Node -> ResultEntry
97 97
nodeLiveRpcCall fname (Right res) _ =
98 98
  case nodeLiveFieldExtract fname res of
99 99
    J.JSNull -> rsNoData
......
103 103

  
104 104
-- | Builder for node live fields.
105 105
nodeLiveFieldBuilder :: (FieldName, FieldTitle, FieldType, String, FieldDoc)
106
                     -> FieldData Node NodeRuntime
106
                     -> FieldData Node Runtime
107 107
nodeLiveFieldBuilder (fname, ftitle, ftype, _, fdoc) =
108 108
  ( FieldDefinition fname ftitle ftype fdoc
109 109
  , FieldRuntime $ nodeLiveRpcCall fname
......
129 129
                  else rsNormal (nodePowered node)
130 130

  
131 131
-- | List of all node fields.
132
nodeFields :: FieldList Node NodeRuntime
132
nodeFields :: FieldList Node Runtime
133 133
nodeFields =
134 134
  [ (FieldDefinition "drained" "Drained" QFTBool "Whether node is drained",
135 135
     FieldSimple (rsNormal . nodeDrained), QffNormal)
......
208 208
  tagsFields
209 209

  
210 210
-- | The node fields map.
211
nodeFieldsMap :: FieldMap Node NodeRuntime
212
nodeFieldsMap =
211
fieldsMap :: FieldMap Node Runtime
212
fieldsMap =
213 213
  Map.fromList $ map (\v@(f, _, _) -> (fdefName f, v)) nodeFields
214 214

  
215 215
-- | Collect live data from RPC query if enabled.
216 216
--
217 217
-- FIXME: Check which fields we actually need and possibly send empty
218
-- hvs/vgs if no info from hypervisor/volume group respectively is
218
-- hvs\/vgs if no info from hypervisor\/volume group respectively is
219 219
-- required
220
maybeCollectLiveData:: Bool -> ConfigData -> [Node] -> IO [(Node, NodeRuntime)]
221
maybeCollectLiveData False _ nodes =
220
collectLiveData:: Bool -> ConfigData -> [Node] -> IO [(Node, Runtime)]
221
collectLiveData False _ nodes =
222 222
  return $ zip nodes (repeat $ Left (RpcResultError "Live data disabled"))
223
maybeCollectLiveData True cfg nodes = do
223
collectLiveData True cfg nodes = do
224 224
  let vgs = [clusterVolumeGroupName $ configCluster cfg]
225 225
      hvs = [getDefaultHypervisor cfg]
226 226
      step n (bn, gn, em) =

Also available in: Unified diff