Revision c14ba680
b/src/Ganeti/Rpc.hs | ||
---|---|---|
81 | 81 |
|
82 | 82 |
import Ganeti.BasicTypes |
83 | 83 |
import qualified Ganeti.Constants as C |
84 |
import Ganeti.JSON |
|
84 | 85 |
import Ganeti.Logging |
85 | 86 |
import Ganeti.Objects |
86 | 87 |
import Ganeti.THH |
... | ... | |
289 | 290 |
-- | AllInstancesInfo |
290 | 291 |
-- Returns information about all running instances on the given nodes |
291 | 292 |
$(buildObject "RpcCallAllInstancesInfo" "rpcCallAllInstInfo" |
292 |
[ simpleField "hypervisors" [t| [Hypervisor] |] ])
|
|
293 |
[ simpleField "hypervisors" [t| [(Hypervisor, HvParams)] |] ])
|
|
293 | 294 |
|
294 | 295 |
$(buildObject "RpcResultAllInstancesInfo" "rpcResAllInstInfo" |
295 | 296 |
[ simpleField "instances" [t| [(String, InstanceInfo)] |] ]) |
... | ... | |
298 | 299 |
rpcCallName _ = "all_instances_info" |
299 | 300 |
rpcCallTimeout _ = rpcTimeoutToRaw Urgent |
300 | 301 |
rpcCallAcceptOffline _ = False |
301 |
rpcCallData _ call = J.encode [rpcCallAllInstInfoHypervisors call] |
|
302 |
rpcCallData _ call = J.encode ( |
|
303 |
map fst $ rpcCallAllInstInfoHypervisors call, |
|
304 |
GenericContainer . Map.fromList $ rpcCallAllInstInfoHypervisors call) |
|
302 | 305 |
|
303 | 306 |
instance Rpc RpcCallAllInstancesInfo RpcResultAllInstancesInfo where |
304 | 307 |
-- FIXME: Is there a simpler way to do it? |
b/src/Ganeti/Types.hs | ||
---|---|---|
425 | 425 |
instance THH.PyValue Hypervisor where |
426 | 426 |
showValue = show . hypervisorToRaw |
427 | 427 |
|
428 |
instance HasStringRepr Hypervisor where |
|
429 |
fromStringRepr = hypervisorFromRaw |
|
430 |
toStringRepr = hypervisorToRaw |
|
431 |
|
|
428 | 432 |
-- | Oob command type. |
429 | 433 |
$(THH.declareLADT ''String "OobCommand" |
430 | 434 |
[ ("OobHealth", "health") |
b/test/hs/Test/Ganeti/Rpc.hs | ||
---|---|---|
44 | 44 |
import qualified Ganeti.JSON as JSON |
45 | 45 |
import Ganeti.Types |
46 | 46 |
|
47 |
instance Arbitrary Rpc.RpcCallAllInstancesInfo where |
|
48 |
arbitrary = Rpc.RpcCallAllInstancesInfo <$> arbitrary |
|
49 |
|
|
50 |
instance Arbitrary Rpc.RpcCallInstanceList where |
|
51 |
arbitrary = Rpc.RpcCallInstanceList <$> arbitrary |
|
52 |
|
|
53 |
instance Arbitrary Rpc.RpcCallNodeInfo where |
|
54 |
arbitrary = Rpc.RpcCallNodeInfo <$> genStorageUnitMap <*> genHvSpecs |
|
55 |
|
|
56 | 47 |
genStorageUnit :: Gen StorageUnit |
57 | 48 |
genStorageUnit = do |
58 | 49 |
storage_type <- arbitrary |
... | ... | |
72 | 63 |
storage_units_list <- vectorOf num_nodes genStorageUnits |
73 | 64 |
return $ Map.fromList (zip node_uuids storage_units_list) |
74 | 65 |
|
66 |
-- FIXME: Generate more interesting hvparams |
|
67 |
-- | Generate Hvparams |
|
68 |
genHvParams :: Gen Objects.HvParams |
|
69 |
genHvParams = return $ JSON.GenericContainer Map.empty |
|
70 |
|
|
75 | 71 |
-- | Generate hypervisor specifications to be used for the NodeInfo call |
76 |
genHvSpecs :: Gen [ (Types.Hypervisor, Objects.HvParams) ]
|
|
72 |
genHvSpecs :: Gen [(Types.Hypervisor, Objects.HvParams)]
|
|
77 | 73 |
genHvSpecs = do |
78 | 74 |
numhv <- choose (0, 5) |
79 | 75 |
hvs <- vectorOf numhv arbitrary |
... | ... | |
81 | 77 |
let specs = zip hvs hvparams |
82 | 78 |
return specs |
83 | 79 |
|
84 |
-- FIXME: Generate more interesting hvparams |
|
85 |
-- | Generate Hvparams |
|
86 |
genHvParams :: Gen Objects.HvParams |
|
87 |
genHvParams = return $ JSON.GenericContainer Map.empty |
|
80 |
instance Arbitrary Rpc.RpcCallAllInstancesInfo where |
|
81 |
arbitrary = Rpc.RpcCallAllInstancesInfo <$> genHvSpecs |
|
82 |
|
|
83 |
instance Arbitrary Rpc.RpcCallInstanceList where |
|
84 |
arbitrary = Rpc.RpcCallInstanceList <$> arbitrary |
|
85 |
|
|
86 |
instance Arbitrary Rpc.RpcCallNodeInfo where |
|
87 |
arbitrary = Rpc.RpcCallNodeInfo <$> genStorageUnitMap <*> genHvSpecs |
|
88 | 88 |
|
89 | 89 |
-- | Monadic check that, for an offline node and a call that does not |
90 | 90 |
-- offline nodes, we get a OfflineNodeError response. |
Also available in: Unified diff