Revision 5188fdb7

b/htools/Ganeti/Rpc.hs
41 41
  , rpcResultFill
42 42

  
43 43
  , InstanceInfo(..)
44
  , RpcCallInstanceInfo(..)
45
  , RpcResultInstanceInfo(..)
46

  
44 47
  , RpcCallAllInstancesInfo(..)
45 48
  , RpcResultAllInstancesInfo(..)
46 49

  
......
233 236

  
234 237
-- * RPC calls and results
235 238

  
236
-- | AllInstancesInfo
237
--   Returns information about all running instances on the given nodes.
238
$(buildObject "RpcCallAllInstancesInfo" "rpcCallAllInstInfo"
239
  [ simpleField "hypervisors" [t| [Hypervisor] |] ])
239
-- | InstanceInfo
240
--   Returns information about a single instance.
241

  
242
$(buildObject "RpcCallInstanceInfo" "rpcCallInstInfo"
243
  [ simpleField "instance" [t| String |]
244
  , simpleField "hname" [t| Hypervisor |]
245
  ])
240 246

  
241 247
$(buildObject "InstanceInfo" "instInfo"
242 248
  [ simpleField "memory" [t| Int|]
......
245 251
  , simpleField "time"   [t| Int |]
246 252
  ])
247 253

  
254
-- This is optional here because the result may be empty if instance is
255
-- not on a node - and this is not considered an error.
256
$(buildObject "RpcResultInstanceInfo" "rpcResInstInfo"
257
  [ optionalField $ simpleField "inst_info" [t| InstanceInfo |]])
258

  
259
instance RpcCall RpcCallInstanceInfo where
260
  rpcCallName _ = "instance_info"
261
  rpcCallTimeout _ = rpcTimeoutToRaw Urgent
262
  rpcCallAcceptOffline _ = False
263
  rpcCallData _ call = J.encode
264
    ( rpcCallInstInfoInstance call
265
    , rpcCallInstInfoHname call
266
    )
267

  
268
instance Rpc RpcCallInstanceInfo RpcResultInstanceInfo where
269
  rpcResultFill _ res =
270
    return $ case res of
271
      J.JSObject res' ->
272
        case J.fromJSObject res' of
273
          [] -> Right $ RpcResultInstanceInfo Nothing
274
          _ ->
275
            case J.readJSON res of
276
              J.Error err -> Left $ JsonDecodeError err
277
              J.Ok val -> Right . RpcResultInstanceInfo $ Just val
278
      _ -> Left $ JsonDecodeError
279
           ("Expected JSObject, got " ++ show res)
280

  
281
-- | AllInstancesInfo
282
--   Returns information about all running instances on the given nodes
283
$(buildObject "RpcCallAllInstancesInfo" "rpcCallAllInstInfo"
284
  [ simpleField "hypervisors" [t| [Hypervisor] |] ])
285

  
248 286
$(buildObject "RpcResultAllInstancesInfo" "rpcResAllInstInfo"
249 287
  [ simpleField "instances" [t| [(String, InstanceInfo)] |] ])
250 288

  

Also available in: Unified diff