Revision e9aaa3c6 htools/Ganeti/OpCodes.hs
b/htools/Ganeti/OpCodes.hs | ||
---|---|---|
1 |
{-# LANGUAGE TemplateHaskell #-} |
|
2 |
|
|
1 | 3 |
{-| Implementation of the opcodes. |
2 | 4 |
|
3 | 5 |
-} |
... | ... | |
34 | 36 |
import qualified Text.JSON as J |
35 | 37 |
import Text.JSON.Types |
36 | 38 |
|
39 |
import qualified Ganeti.Constants as C |
|
40 |
import qualified Ganeti.THH as THH |
|
41 |
|
|
37 | 42 |
import Ganeti.HTools.Utils |
38 | 43 |
|
39 | 44 |
-- | Replace disks type. |
40 |
data ReplaceDisksMode = ReplaceOnPrimary |
|
41 |
| ReplaceOnSecondary |
|
42 |
| ReplaceNewSecondary |
|
43 |
| ReplaceAuto |
|
44 |
deriving (Show, Read, Eq) |
|
45 |
|
|
46 |
instance JSON ReplaceDisksMode where |
|
47 |
showJSON m = case m of |
|
48 |
ReplaceOnPrimary -> showJSON "replace_on_primary" |
|
49 |
ReplaceOnSecondary -> showJSON "replace_on_secondary" |
|
50 |
ReplaceNewSecondary -> showJSON "replace_new_secondary" |
|
51 |
ReplaceAuto -> showJSON "replace_auto" |
|
52 |
readJSON s = case readJSON s of |
|
53 |
J.Ok "replace_on_primary" -> J.Ok ReplaceOnPrimary |
|
54 |
J.Ok "replace_on_secondary" -> J.Ok ReplaceOnSecondary |
|
55 |
J.Ok "replace_new_secondary" -> J.Ok ReplaceNewSecondary |
|
56 |
J.Ok "replace_auto" -> J.Ok ReplaceAuto |
|
57 |
_ -> J.Error "Can't parse a valid ReplaceDisksMode" |
|
45 |
$(THH.declareSADT "ReplaceDisksMode" |
|
46 |
[ ("ReplaceOnPrimary", 'C.replaceDiskPri) |
|
47 |
, ("ReplaceOnSecondary", 'C.replaceDiskSec) |
|
48 |
, ("ReplaceNewSecondary", 'C.replaceDiskChg) |
|
49 |
, ("ReplaceAuto", 'C.replaceDiskAuto) |
|
50 |
]) |
|
51 |
$(THH.makeJSONInstance ''ReplaceDisksMode) |
|
58 | 52 |
|
59 | 53 |
-- | OpCode representation. |
60 | 54 |
-- |
Also available in: Unified diff