Revision 525bfb36 htools/Ganeti/OpCodes.hs
b/htools/Ganeti/OpCodes.hs | ||
---|---|---|
36 | 36 |
|
37 | 37 |
import Ganeti.HTools.Utils |
38 | 38 |
|
39 |
-- | Replace disks type. |
|
39 | 40 |
data ReplaceDisksMode = ReplaceOnPrimary |
40 | 41 |
| ReplaceOnSecondary |
41 | 42 |
| ReplaceNewSecondary |
... | ... | |
55 | 56 |
J.Ok "replace_auto" -> J.Ok ReplaceAuto |
56 | 57 |
_ -> J.Error "Can't parse a valid ReplaceDisksMode" |
57 | 58 |
|
59 |
-- | OpCode representation. |
|
60 |
-- |
|
61 |
-- We only implement a subset of Ganeti opcodes, but only what we |
|
62 |
-- actually use in the htools codebase. |
|
58 | 63 |
data OpCode = OpTestDelay Double Bool [String] |
59 | 64 |
| OpInstanceReplaceDisks String (Maybe String) ReplaceDisksMode |
60 | 65 |
[Int] (Maybe String) |
... | ... | |
63 | 68 |
deriving (Show, Read, Eq) |
64 | 69 |
|
65 | 70 |
|
71 |
-- | Computes the OP_ID for an OpCode. |
|
66 | 72 |
opID :: OpCode -> String |
67 | 73 |
opID (OpTestDelay _ _ _) = "OP_TEST_DELAY" |
68 | 74 |
opID (OpInstanceReplaceDisks _ _ _ _ _) = "OP_INSTANCE_REPLACE_DISKS" |
69 | 75 |
opID (OpInstanceFailover _ _) = "OP_INSTANCE_FAILOVER" |
70 | 76 |
opID (OpInstanceMigrate _ _ _ _) = "OP_INSTANCE_MIGRATE" |
71 | 77 |
|
78 |
-- | Loads an OpCode from the JSON serialised form. |
|
72 | 79 |
loadOpCode :: JSValue -> J.Result OpCode |
73 | 80 |
loadOpCode v = do |
74 | 81 |
o <- liftM J.fromJSObject (readJSON v) |
... | ... | |
99 | 106 |
return $ OpInstanceMigrate inst live cleanup allow_failover |
100 | 107 |
_ -> J.Error $ "Unknown opcode " ++ op_id |
101 | 108 |
|
109 |
-- | Serialises an opcode to JSON. |
|
102 | 110 |
saveOpCode :: OpCode -> JSValue |
103 | 111 |
saveOpCode op@(OpTestDelay duration on_master on_nodes) = |
104 | 112 |
let ol = [ ("OP_ID", showJSON $ opID op) |
Also available in: Unified diff