Revision 96a12113 htools/Ganeti/HTools/IAlloc.hs
b/htools/Ganeti/HTools/IAlloc.hs | ||
---|---|---|
125 | 125 |
return (u, Group.create name u apol) |
126 | 126 |
|
127 | 127 |
-- | Top-level parser. |
128 |
parseData :: String -- ^ The JSON message as received from Ganeti |
|
129 |
-> Result Request -- ^ A (possible valid) request |
|
128 |
-- |
|
129 |
-- The result is a tuple of eventual warning messages and the parsed |
|
130 |
-- request; if parsing the input data fails, we'll return a 'Bad' |
|
131 |
-- value. |
|
132 |
parseData :: String -- ^ The JSON message as received from Ganeti |
|
133 |
-> Result ([String], Request) -- ^ Result tuple |
|
130 | 134 |
parseData body = do |
131 | 135 |
decoded <- fromJResult "Parsing input IAllocator message" (decodeStrict body) |
132 | 136 |
let obj = fromJSObject decoded |
... | ... | |
151 | 155 |
let (kti, il) = assignIndices iobj |
152 | 156 |
-- cluster tags |
153 | 157 |
ctags <- extrObj "cluster_tags" |
154 |
cdata <- mergeData [] [] [] [] (ClusterData gl nl il ctags) |
|
155 |
let map_n = cdNodes cdata |
|
158 |
cdata1 <- mergeData [] [] [] [] (ClusterData gl nl il ctags) |
|
159 |
let (msgs, fix_nl) = checkData (cdNodes cdata1) (cdInstances cdata1) |
|
160 |
cdata = cdata1 { cdNodes = fix_nl } |
|
161 |
map_n = cdNodes cdata |
|
156 | 162 |
map_i = cdInstances cdata |
157 | 163 |
map_g = cdGroups cdata |
158 | 164 |
optype <- extrReq "type" |
... | ... | |
203 | 209 |
return $ NodeEvacuate rl_idx rl_mode |
204 | 210 |
|
205 | 211 |
| otherwise -> fail ("Invalid request type '" ++ optype ++ "'") |
206 |
return $ Request rqtype cdata
|
|
212 |
return $ (msgs, Request rqtype cdata)
|
|
207 | 213 |
|
208 | 214 |
-- | Formats the result into a valid IAllocator response message. |
209 | 215 |
formatResponse :: Bool -- ^ Whether the request was successful |
... | ... | |
300 | 306 |
Bad err -> do |
301 | 307 |
hPutStrLn stderr $ "Error: " ++ err |
302 | 308 |
exitWith $ ExitFailure 1 |
303 |
Ok rq -> return rq
|
|
309 |
Ok (fix_msgs, rq) -> maybeShowWarnings fix_msgs >> return rq
|
|
304 | 310 |
(if isJust (optDataFile opts) || (not . null . optNodeSim) opts |
305 | 311 |
then do |
306 | 312 |
cdata <- loadExternalData opts |
Also available in: Unified diff