Revision 5227de56

b/htools/Ganeti/Query/Common.hs
25 25

  
26 26
module Ganeti.Query.Common
27 27
  ( rsNoData
28
  , rsUnavail
28 29
  , rsNormal
29 30
  , rsMaybe
30 31
  , rsUnknown
......
66 67
rsNoData :: ResultEntry
67 68
rsNoData = ResultEntry RSNoData Nothing
68 69

  
70
-- | Helper for result for an entity which supports no such field.
71
rsUnavail :: ResultEntry
72
rsUnavail = ResultEntry RSUnavail Nothing
73

  
69 74
-- | Helper to declare a normal result.
70 75
rsNormal :: (JSON a) => a -> ResultEntry
71 76
rsNormal a = ResultEntry RSNormal $ Just (showJSON a)
b/htools/Ganeti/Query/Node.hs
117 117
          "\"" ++ nodeRoleToRaw role ++ "\" for " ++ roleDescription role)
118 118
   (reverse [minBound..maxBound]))
119 119

  
120
-- | Get node powered status.
121
getNodePower :: ConfigData -> Node -> ResultEntry
122
getNodePower cfg node =
123
  case getNodeNdParams cfg node of
124
    Nothing -> rsNoData
125
    Just ndp -> if null (ndpOobProgram ndp)
126
                  then rsUnavail
127
                  else rsNormal (nodePowered node)
128

  
120 129
-- | List of all node fields.
121 130
nodeFields :: FieldList Node NodeRuntime
122 131
nodeFields =
......
174 183
                          getNodeInstances cfg . nodeName))
175 184
  , (FieldDefinition "role" "Role" QFTText nodeRoleDoc,
176 185
     FieldConfig ((rsNormal .) . getNodeRole))
177
  -- FIXME: the powered state is special (has an different context,
178
  -- not runtime) in Python
179 186
  , (FieldDefinition "powered" "Powered" QFTBool
180 187
       "Whether node is thought to be powered on",
181
     missingRuntime)
188
     FieldConfig getNodePower)
182 189
  -- FIXME: the two fields below are incomplete in Python, part of the
183 190
  -- non-implemented node resource model; they are declared just for
184 191
  -- parity, but are not functional

Also available in: Unified diff