Commit c14ba680 authored by Hrvoje Ribicic's avatar Hrvoje Ribicic
Browse files

Enable 'AllInstancesInfo' RPC call in Haskell



The AllInstancesInfo call appears to have been implemented but never
used. The commit makes it usable by modifying the parameter type and
serialization.
Signed-off-by: default avatarHrvoje Ribicic <riba@google.com>
Reviewed-by: default avatarJose A. Lopes <jabolopes@google.com>
parent d286d795
......@@ -81,6 +81,7 @@ import qualified Ganeti.Path as P
import Ganeti.BasicTypes
import qualified Ganeti.Constants as C
import Ganeti.JSON
import Ganeti.Logging
import Ganeti.Objects
import Ganeti.THH
......@@ -289,7 +290,7 @@ instance Rpc RpcCallInstanceInfo RpcResultInstanceInfo where
-- | AllInstancesInfo
-- Returns information about all running instances on the given nodes
$(buildObject "RpcCallAllInstancesInfo" "rpcCallAllInstInfo"
[ simpleField "hypervisors" [t| [Hypervisor] |] ])
[ simpleField "hypervisors" [t| [(Hypervisor, HvParams)] |] ])
$(buildObject "RpcResultAllInstancesInfo" "rpcResAllInstInfo"
[ simpleField "instances" [t| [(String, InstanceInfo)] |] ])
......@@ -298,7 +299,9 @@ instance RpcCall RpcCallAllInstancesInfo where
rpcCallName _ = "all_instances_info"
rpcCallTimeout _ = rpcTimeoutToRaw Urgent
rpcCallAcceptOffline _ = False
rpcCallData _ call = J.encode [rpcCallAllInstInfoHypervisors call]
rpcCallData _ call = J.encode (
map fst $ rpcCallAllInstInfoHypervisors call,
GenericContainer . Map.fromList $ rpcCallAllInstInfoHypervisors call)
instance Rpc RpcCallAllInstancesInfo RpcResultAllInstancesInfo where
-- FIXME: Is there a simpler way to do it?
......
......@@ -425,6 +425,10 @@ $(THH.makeJSONInstance ''Hypervisor)
instance THH.PyValue Hypervisor where
showValue = show . hypervisorToRaw
instance HasStringRepr Hypervisor where
fromStringRepr = hypervisorFromRaw
toStringRepr = hypervisorToRaw
-- | Oob command type.
$(THH.declareLADT ''String "OobCommand"
[ ("OobHealth", "health")
......
......@@ -44,15 +44,6 @@ import qualified Ganeti.Types as Types
import qualified Ganeti.JSON as JSON
import Ganeti.Types
instance Arbitrary Rpc.RpcCallAllInstancesInfo where
arbitrary = Rpc.RpcCallAllInstancesInfo <$> arbitrary
instance Arbitrary Rpc.RpcCallInstanceList where
arbitrary = Rpc.RpcCallInstanceList <$> arbitrary
instance Arbitrary Rpc.RpcCallNodeInfo where
arbitrary = Rpc.RpcCallNodeInfo <$> genStorageUnitMap <*> genHvSpecs
genStorageUnit :: Gen StorageUnit
genStorageUnit = do
storage_type <- arbitrary
......@@ -72,8 +63,13 @@ genStorageUnitMap = do
storage_units_list <- vectorOf num_nodes genStorageUnits
return $ Map.fromList (zip node_uuids storage_units_list)
-- FIXME: Generate more interesting hvparams
-- | Generate Hvparams
genHvParams :: Gen Objects.HvParams
genHvParams = return $ JSON.GenericContainer Map.empty
-- | Generate hypervisor specifications to be used for the NodeInfo call
genHvSpecs :: Gen [ (Types.Hypervisor, Objects.HvParams) ]
genHvSpecs :: Gen [(Types.Hypervisor, Objects.HvParams)]
genHvSpecs = do
numhv <- choose (0, 5)
hvs <- vectorOf numhv arbitrary
......@@ -81,10 +77,14 @@ genHvSpecs = do
let specs = zip hvs hvparams
return specs
-- FIXME: Generate more interesting hvparams
-- | Generate Hvparams
genHvParams :: Gen Objects.HvParams
genHvParams = return $ JSON.GenericContainer Map.empty
instance Arbitrary Rpc.RpcCallAllInstancesInfo where
arbitrary = Rpc.RpcCallAllInstancesInfo <$> genHvSpecs
instance Arbitrary Rpc.RpcCallInstanceList where
arbitrary = Rpc.RpcCallInstanceList <$> arbitrary
instance Arbitrary Rpc.RpcCallNodeInfo where
arbitrary = Rpc.RpcCallNodeInfo <$> genStorageUnitMap <*> genHvSpecs
-- | Monadic check that, for an offline node and a call that does not
-- offline nodes, we get a OfflineNodeError response.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment