Revision 619e89c8
b/htools/Ganeti/Luxi.hs | ||
---|---|---|
357 | 357 |
let rval = validateResult result |
358 | 358 |
return rval |
359 | 359 |
|
360 |
-- | Parses a job ID. |
|
361 |
parseJobId :: JSValue -> Result JobId |
|
362 |
parseJobId (JSString x) = Ok $ fromJSString x |
|
363 |
parseJobId x = Bad $ "Wrong type/value for job id: " ++ show x |
|
364 |
|
|
365 |
-- | Parse job submission result. |
|
366 |
parseSubmitJobResult :: JSValue -> Result JobId |
|
367 |
parseSubmitJobResult (JSArray [JSBool True, v]) = parseJobId v |
|
368 |
parseSubmitJobResult (JSArray [JSBool False, JSString x]) = |
|
369 |
Bad (fromJSString x) |
|
370 |
parseSubmitJobResult v = Bad $ "Unknown result from the master daemon" ++ |
|
371 |
show v |
|
372 |
|
|
360 | 373 |
-- | Specialized submitManyJobs call. |
361 | 374 |
submitManyJobs :: Client -> [[OpCode]] -> IO (Result [JobId]) |
362 | 375 |
submitManyJobs s jobs = do |
... | ... | |
364 | 377 |
-- map each result (status, payload) pair into a nice Result ADT |
365 | 378 |
return $ case rval of |
366 | 379 |
Bad x -> Bad x |
367 |
Ok (JSArray r) -> |
|
368 |
mapM (\v -> case v of |
|
369 |
JSArray [JSBool True, JSString x] -> |
|
370 |
Ok (fromJSString x) |
|
371 |
JSArray [JSBool False, JSString x] -> |
|
372 |
Bad (fromJSString x) |
|
373 |
_ -> Bad "Unknown result from the master daemon" |
|
374 |
) r |
|
380 |
Ok (JSArray r) -> mapM parseSubmitJobResult r |
|
375 | 381 |
x -> Bad ("Cannot parse response from Ganeti: " ++ show x) |
376 | 382 |
|
377 | 383 |
-- | Custom queryJobs call. |
Also available in: Unified diff