Skip to content
Snippets Groups Projects
Commit 5188fdb7 authored by Agata Murawska's avatar Agata Murawska
Browse files

InstanceInfo RPC call


This patch implements single instance info call - somewhat similar to
all_instances_info, except we give a specific instance name.

Current implementation of reading the InstanceInfo value is somewhat
counter-intuitive because when we query a node on thich there is
no instance with such name, this is not considered an error - but
it does produce an empty answer. Therefore the resulting type is
optional.

Signed-off-by: default avatarAgata Murawska <agatamurawska@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 1cb97324
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,9 @@ module Ganeti.Rpc
, rpcResultFill
, InstanceInfo(..)
, RpcCallInstanceInfo(..)
, RpcResultInstanceInfo(..)
, RpcCallAllInstancesInfo(..)
, RpcResultAllInstancesInfo(..)
......@@ -233,10 +236,13 @@ sanitizeDictResults ((name, J.Ok val):xs) =
-- * RPC calls and results
-- | AllInstancesInfo
-- Returns information about all running instances on the given nodes.
$(buildObject "RpcCallAllInstancesInfo" "rpcCallAllInstInfo"
[ simpleField "hypervisors" [t| [Hypervisor] |] ])
-- | InstanceInfo
-- Returns information about a single instance.
$(buildObject "RpcCallInstanceInfo" "rpcCallInstInfo"
[ simpleField "instance" [t| String |]
, simpleField "hname" [t| Hypervisor |]
])
$(buildObject "InstanceInfo" "instInfo"
[ simpleField "memory" [t| Int|]
......@@ -245,6 +251,38 @@ $(buildObject "InstanceInfo" "instInfo"
, simpleField "time" [t| Int |]
])
-- This is optional here because the result may be empty if instance is
-- not on a node - and this is not considered an error.
$(buildObject "RpcResultInstanceInfo" "rpcResInstInfo"
[ optionalField $ simpleField "inst_info" [t| InstanceInfo |]])
instance RpcCall RpcCallInstanceInfo where
rpcCallName _ = "instance_info"
rpcCallTimeout _ = rpcTimeoutToRaw Urgent
rpcCallAcceptOffline _ = False
rpcCallData _ call = J.encode
( rpcCallInstInfoInstance call
, rpcCallInstInfoHname call
)
instance Rpc RpcCallInstanceInfo RpcResultInstanceInfo where
rpcResultFill _ res =
return $ case res of
J.JSObject res' ->
case J.fromJSObject res' of
[] -> Right $ RpcResultInstanceInfo Nothing
_ ->
case J.readJSON res of
J.Error err -> Left $ JsonDecodeError err
J.Ok val -> Right . RpcResultInstanceInfo $ Just val
_ -> Left $ JsonDecodeError
("Expected JSObject, got " ++ show res)
-- | AllInstancesInfo
-- Returns information about all running instances on the given nodes
$(buildObject "RpcCallAllInstancesInfo" "rpcCallAllInstInfo"
[ simpleField "hypervisors" [t| [Hypervisor] |] ])
$(buildObject "RpcResultAllInstancesInfo" "rpcResAllInstInfo"
[ simpleField "instances" [t| [(String, InstanceInfo)] |] ])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment