Revision 4a1dc2bf htools/Ganeti/OpCodes.hs
b/htools/Ganeti/OpCodes.hs | ||
---|---|---|
28 | 28 |
module Ganeti.OpCodes |
29 | 29 |
( OpCode(..) |
30 | 30 |
, ReplaceDisksMode(..) |
31 |
, DiskIndex |
|
32 |
, mkDiskIndex |
|
33 |
, unDiskIndex |
|
31 | 34 |
, opID |
32 | 35 |
, allOpIDs |
33 | 36 |
) where |
... | ... | |
48 | 51 |
]) |
49 | 52 |
$(makeJSONInstance ''ReplaceDisksMode) |
50 | 53 |
|
54 |
-- | Disk index type (embedding constraints on the index value via a |
|
55 |
-- smart constructor). |
|
56 |
newtype DiskIndex = DiskIndex { unDiskIndex :: Int } |
|
57 |
deriving (Show, Read, Eq, Ord) |
|
58 |
|
|
59 |
-- | Smart constructor for 'DiskIndex'. |
|
60 |
mkDiskIndex :: (Monad m) => Int -> m DiskIndex |
|
61 |
mkDiskIndex i | i >= 0 && i < C.maxDisks = return (DiskIndex i) |
|
62 |
| otherwise = fail $ "Invalid value for disk index '" ++ |
|
63 |
show i ++ "', required between 0 and " ++ |
|
64 |
show C.maxDisks |
|
65 |
|
|
66 |
instance JSON DiskIndex where |
|
67 |
readJSON v = readJSON v >>= mkDiskIndex |
|
68 |
showJSON = showJSON . unDiskIndex |
|
69 |
|
|
51 | 70 |
-- | OpCode representation. |
52 | 71 |
-- |
53 | 72 |
-- We only implement a subset of Ganeti opcodes, but only what we |
... | ... | |
62 | 81 |
[ simpleField "instance_name" [t| String |] |
63 | 82 |
, optionalField $ simpleField "remote_node" [t| String |] |
64 | 83 |
, simpleField "mode" [t| ReplaceDisksMode |] |
65 |
, simpleField "disks" [t| [Int] |]
|
|
84 |
, simpleField "disks" [t| [DiskIndex] |]
|
|
66 | 85 |
, optionalField $ simpleField "iallocator" [t| String |] |
67 | 86 |
]) |
68 | 87 |
, ("OpInstanceFailover", |
Also available in: Unified diff