Revision 2c9336a4 htools/Ganeti/HTools/Types.hs
b/htools/Ganeti/HTools/Types.hs | ||
---|---|---|
32 | 32 |
, Weight |
33 | 33 |
, GroupID |
34 | 34 |
, AllocPolicy(..) |
35 |
, apolFromString
|
|
36 |
, apolToString
|
|
35 |
, allocPolicyFromString
|
|
36 |
, allocPolicyToString
|
|
37 | 37 |
, RSpec(..) |
38 | 38 |
, DynUtil(..) |
39 | 39 |
, zeroUtil |
... | ... | |
49 | 49 |
, Placement |
50 | 50 |
, IMove(..) |
51 | 51 |
, DiskTemplate(..) |
52 |
, dtToString
|
|
53 |
, dtFromString
|
|
52 |
, diskTemplateToString
|
|
53 |
, diskTemplateFromString
|
|
54 | 54 |
, MoveJob |
55 | 55 |
, JobSet |
56 | 56 |
, Result(..) |
... | ... | |
110 | 110 |
deriving (Show, Read, Eq, Ord, Enum, Bounded) |
111 | 111 |
|
112 | 112 |
-- | Convert a string to an alloc policy. |
113 |
apolFromString :: (Monad m) => String -> m AllocPolicy
|
|
114 |
apolFromString s =
|
|
113 |
allocPolicyFromString :: (Monad m) => String -> m AllocPolicy
|
|
114 |
allocPolicyFromString s =
|
|
115 | 115 |
case () of |
116 | 116 |
_ | s == C.allocPolicyPreferred -> return AllocPreferred |
117 | 117 |
| s == C.allocPolicyLastResort -> return AllocLastResort |
... | ... | |
119 | 119 |
| otherwise -> fail $ "Invalid alloc policy mode: " ++ s |
120 | 120 |
|
121 | 121 |
-- | Convert an alloc policy to the Ganeti string equivalent. |
122 |
apolToString :: AllocPolicy -> String
|
|
123 |
apolToString AllocPreferred = C.allocPolicyPreferred
|
|
124 |
apolToString AllocLastResort = C.allocPolicyLastResort
|
|
125 |
apolToString AllocUnallocable = C.allocPolicyUnallocable
|
|
122 |
allocPolicyToString :: AllocPolicy -> String
|
|
123 |
allocPolicyToString AllocPreferred = C.allocPolicyPreferred
|
|
124 |
allocPolicyToString AllocLastResort = C.allocPolicyLastResort
|
|
125 |
allocPolicyToString AllocUnallocable = C.allocPolicyUnallocable
|
|
126 | 126 |
|
127 | 127 |
instance JSON.JSON AllocPolicy where |
128 |
showJSON = JSON.showJSON . apolToString
|
|
128 |
showJSON = JSON.showJSON . allocPolicyToString
|
|
129 | 129 |
readJSON s = case JSON.readJSON s of |
130 |
JSON.Ok s' -> apolFromString s'
|
|
130 |
JSON.Ok s' -> allocPolicyFromString s'
|
|
131 | 131 |
JSON.Error e -> JSON.Error $ |
132 | 132 |
"Can't parse alloc_policy: " ++ e |
133 | 133 |
|
... | ... | |
191 | 191 |
deriving (Show, Read, Eq, Enum, Bounded) |
192 | 192 |
|
193 | 193 |
-- | Converts a DiskTemplate to String. |
194 |
dtToString :: DiskTemplate -> String
|
|
195 |
dtToString DTDiskless = C.dtDiskless
|
|
196 |
dtToString DTFile = C.dtFile
|
|
197 |
dtToString DTSharedFile = C.dtSharedFile
|
|
198 |
dtToString DTPlain = C.dtPlain
|
|
199 |
dtToString DTBlock = C.dtBlock
|
|
200 |
dtToString DTDrbd8 = C.dtDrbd8
|
|
194 |
diskTemplateToString :: DiskTemplate -> String
|
|
195 |
diskTemplateToString DTDiskless = C.dtDiskless
|
|
196 |
diskTemplateToString DTFile = C.dtFile
|
|
197 |
diskTemplateToString DTSharedFile = C.dtSharedFile
|
|
198 |
diskTemplateToString DTPlain = C.dtPlain
|
|
199 |
diskTemplateToString DTBlock = C.dtBlock
|
|
200 |
diskTemplateToString DTDrbd8 = C.dtDrbd8
|
|
201 | 201 |
|
202 | 202 |
-- | Converts a DiskTemplate from String. |
203 |
dtFromString :: (Monad m) => String -> m DiskTemplate
|
|
204 |
dtFromString s =
|
|
203 |
diskTemplateFromString :: (Monad m) => String -> m DiskTemplate
|
|
204 |
diskTemplateFromString s =
|
|
205 | 205 |
case () of |
206 | 206 |
_ | s == C.dtDiskless -> return DTDiskless |
207 | 207 |
| s == C.dtFile -> return DTFile |
... | ... | |
212 | 212 |
| otherwise -> fail $ "Invalid disk template: " ++ s |
213 | 213 |
|
214 | 214 |
instance JSON.JSON DiskTemplate where |
215 |
showJSON = JSON.showJSON . dtToString
|
|
215 |
showJSON = JSON.showJSON . diskTemplateToString
|
|
216 | 216 |
readJSON s = case JSON.readJSON s of |
217 |
JSON.Ok s' -> dtFromString s'
|
|
217 |
JSON.Ok s' -> diskTemplateFromString s'
|
|
218 | 218 |
JSON.Error e -> JSON.Error $ |
219 | 219 |
"Can't parse disk_template as string: " ++ e |
220 | 220 |
|
Also available in: Unified diff