Revision 41044e04 src/Ganeti/HTools/Backend/Text.hs
b/src/Ganeti/HTools/Backend/Text.hs | ||
---|---|---|
32 | 32 |
, loadInst |
33 | 33 |
, loadNode |
34 | 34 |
, loadISpec |
35 |
, loadMultipleMinMaxISpecs |
|
35 | 36 |
, loadIPolicy |
36 | 37 |
, serializeInstances |
37 | 38 |
, serializeNode |
38 | 39 |
, serializeNodes |
39 | 40 |
, serializeGroup |
40 | 41 |
, serializeISpec |
42 |
, serializeMultipleMinMaxISpecs |
|
41 | 43 |
, serializeIPolicy |
42 | 44 |
, serializeCluster |
43 | 45 |
) where |
... | ... | |
117 | 119 |
serializeInstances nl = |
118 | 120 |
unlines . map (serializeInstance nl) . Container.elems |
119 | 121 |
|
122 |
-- | Separator between ISpecs (in MinMaxISpecs). |
|
123 |
iSpecsSeparator :: Char |
|
124 |
iSpecsSeparator = ';' |
|
125 |
|
|
120 | 126 |
-- | Generate a spec data from a given ISpec object. |
121 | 127 |
serializeISpec :: ISpec -> String |
122 | 128 |
serializeISpec ispec = |
... | ... | |
130 | 136 |
serializeDiskTemplates :: [DiskTemplate] -> String |
131 | 137 |
serializeDiskTemplates = intercalate "," . map diskTemplateToRaw |
132 | 138 |
|
139 |
-- | Generate min/max instance specs data. |
|
140 |
serializeMultipleMinMaxISpecs :: [MinMaxISpecs] -> String |
|
141 |
serializeMultipleMinMaxISpecs minmaxes = |
|
142 |
intercalate [iSpecsSeparator] $ foldr serialpair [] minmaxes |
|
143 |
where serialpair (MinMaxISpecs minspec maxspec) acc = |
|
144 |
serializeISpec minspec : serializeISpec maxspec : acc |
|
145 |
|
|
133 | 146 |
-- | Generate policy data from a given policy object. |
134 | 147 |
serializeIPolicy :: String -> IPolicy -> String |
135 | 148 |
serializeIPolicy owner ipol = |
136 | 149 |
let IPolicy minmax stdspec dts vcpu_ratio spindle_ratio = ipol |
137 |
MinMaxISpecs minspec maxspec = minmax |
|
138 | 150 |
strings = [ owner |
139 | 151 |
, serializeISpec stdspec |
140 |
, serializeISpec minspec |
|
141 |
, serializeISpec maxspec |
|
152 |
, serializeMultipleMinMaxISpecs minmax |
|
142 | 153 |
, serializeDiskTemplates dts |
143 | 154 |
, show vcpu_ratio |
144 | 155 |
, show spindle_ratio |
... | ... | |
255 | 266 |
return $ ISpec xmem_s xcpu_c xdsk_s xdsk_c xnic_c xsu |
256 | 267 |
loadISpec owner s = fail $ "Invalid ispec data for " ++ owner ++ ": " ++ show s |
257 | 268 |
|
269 |
-- | Load a single min/max ISpec pair |
|
270 |
loadMinMaxISpecs :: String -> String -> String -> Result MinMaxISpecs |
|
271 |
loadMinMaxISpecs owner minspec maxspec = do |
|
272 |
xminspec <- loadISpec (owner ++ "/minspec") (commaSplit minspec) |
|
273 |
xmaxspec <- loadISpec (owner ++ "/maxspec") (commaSplit maxspec) |
|
274 |
return $ MinMaxISpecs xminspec xmaxspec |
|
275 |
|
|
276 |
-- | Break a list of ispecs strings into a list of (min/max) ispecs pairs |
|
277 |
breakISpecsPairs :: String -> [String] -> Result [(String, String)] |
|
278 |
breakISpecsPairs _ [] = |
|
279 |
return [] |
|
280 |
breakISpecsPairs owner (x:y:xs) = do |
|
281 |
rest <- breakISpecsPairs owner xs |
|
282 |
return $ (x, y) : rest |
|
283 |
breakISpecsPairs owner _ = |
|
284 |
fail $ "Odd number of min/max specs for " ++ owner |
|
285 |
|
|
286 |
-- | Load a list of min/max ispecs pairs |
|
287 |
loadMultipleMinMaxISpecs :: String -> [String] -> Result [MinMaxISpecs] |
|
288 |
loadMultipleMinMaxISpecs owner ispecs = do |
|
289 |
pairs <- breakISpecsPairs owner ispecs |
|
290 |
mapM (uncurry $ loadMinMaxISpecs owner) pairs |
|
291 |
|
|
258 | 292 |
-- | Loads an ipolicy from a field list. |
259 | 293 |
loadIPolicy :: [String] -> Result (String, IPolicy) |
260 |
loadIPolicy [owner, stdspec, minspec, maxspec, dtemplates,
|
|
294 |
loadIPolicy [owner, stdspec, minmaxspecs, dtemplates,
|
|
261 | 295 |
vcpu_ratio, spindle_ratio] = do |
262 | 296 |
xstdspec <- loadISpec (owner ++ "/stdspec") (commaSplit stdspec) |
263 |
xminspec <- loadISpec (owner ++ "/minspec") (commaSplit minspec)
|
|
264 |
xmaxspec <- loadISpec (owner ++ "/maxspec") (commaSplit maxspec)
|
|
297 |
xminmaxspecs <- loadMultipleMinMaxISpecs owner $
|
|
298 |
sepSplit iSpecsSeparator minmaxspecs
|
|
265 | 299 |
xdts <- mapM diskTemplateFromRaw $ commaSplit dtemplates |
266 | 300 |
xvcpu_ratio <- tryRead (owner ++ "/vcpu_ratio") vcpu_ratio |
267 | 301 |
xspindle_ratio <- tryRead (owner ++ "/spindle_ratio") spindle_ratio |
268 | 302 |
return (owner, |
269 |
IPolicy (MinMaxISpecs xminspec xmaxspec) xstdspec
|
|
303 |
IPolicy xminmaxspecs xstdspec
|
|
270 | 304 |
xdts xvcpu_ratio xspindle_ratio) |
271 | 305 |
loadIPolicy s = fail $ "Invalid ipolicy data: '" ++ show s ++ "'" |
272 | 306 |
|
Also available in: Unified diff