Implementation of node version query.

Signed-off-by: Agata Murawska <[email protected]>
---
 htools/Ganeti/Rpc.hs |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/htools/Ganeti/Rpc.hs b/htools/Ganeti/Rpc.hs
index d21b834..cb9ee54 100644
--- a/htools/Ganeti/Rpc.hs
+++ b/htools/Ganeti/Rpc.hs
@@ -53,6 +53,9 @@ module Ganeti.Rpc
   , RpcCallNodeInfo(..)
   , RpcResultNodeInfo(..)
 
+  , RpcCallVersion(..)
+  , RpcResultVersion(..)
+
   , rpcTimeoutFromRaw -- FIXME: Not used anywhere
   ) where
 
@@ -333,3 +336,31 @@ instance RpcResult RpcResultNodeInfo where
           Right $ RpcResultNodeInfo boot_id vg_info hv_info
 
 instance Rpc RpcCallNodeInfo RpcResultNodeInfo
+
+-- | Version
+-- Query node version.
+-- Note: We can't use THH as it does not know what to do with empty dict
+data RpcCallVersion = RpcCallVersion {}
+  deriving (Show, Read, Eq)
+
+instance J.JSON RpcCallVersion where
+  showJSON _ = J.JSNull
+  readJSON _ = fail "Not implemented"
+
+$(buildObject "RpcResultVersion" "rpcResultVersion"
+  [ simpleField "version" [t| Int |]
+  ])
+
+instance RpcCall RpcCallVersion where
+  rpcCallName _ = "version"
+  rpcCallTimeout _ = rpcTimeoutToRaw Urgent
+  rpcCallAcceptOffline _ = True
+  rpcCallData call _ = J.encode [call]
+
+instance RpcResult RpcResultVersion where
+  rpcResultFill res =
+    case J.readJSON res of
+      J.Error err -> return . Left $ JsonDecodeError err
+      J.Ok ver -> return . Right $ RpcResultVersion ver
+
+instance Rpc RpcCallVersion RpcResultVersion
-- 
1.7.7.3

Reply via email to