Commit 9f8b97ce authored by Iustin Pop's avatar Iustin Pop
Browse files

htools: add JSON instance for EvacMode



This abstracts the JSON parsing of the type EvacMode near its
definition, and simplifies its conversion in IAlloc.parseData.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 375969eb
......@@ -184,13 +184,7 @@ parseData body = do
rl_names <- extrReq "instances"
rl_insts <- mapM (Container.findByName map_i) rl_names
let rl_idx = map Instance.idx rl_insts
rl_mode <-
case extrReq "evac_mode" of
Ok s | s == C.iallocatorNevacAll -> return ChangeAll
| s == C.iallocatorNevacPri -> return ChangePrimary
| s == C.iallocatorNevacSec -> return ChangeSecondary
| otherwise -> Bad $ "Invalid evacuate mode " ++ s
Bad x -> Bad x
rl_mode <- extrReq "evac_mode"
return $ NodeEvacuate rl_idx rl_mode
| otherwise -> fail ("Invalid request type '" ++ optype ++ "'")
......
......@@ -342,3 +342,17 @@ data EvacMode = ChangePrimary
| ChangeSecondary
| ChangeAll
deriving (Show, Read)
instance JSON.JSON EvacMode where
showJSON mode = case mode of
ChangeAll -> JSON.showJSON C.iallocatorNevacAll
ChangePrimary -> JSON.showJSON C.iallocatorNevacPri
ChangeSecondary -> JSON.showJSON C.iallocatorNevacSec
readJSON v =
case JSON.readJSON v of
JSON.Ok s | s == C.iallocatorNevacAll -> return ChangeAll
| s == C.iallocatorNevacPri -> return ChangePrimary
| s == C.iallocatorNevacSec -> return ChangeSecondary
| otherwise -> fail $ "Invalid evacuate mode " ++ s
JSON.Error e -> JSON.Error $
"Can't parse evacuate mode as string: " ++ e
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