Revision 88a10df5 htools/Ganeti/HTools/ExtLoader.hs
b/htools/Ganeti/HTools/ExtLoader.hs | ||
---|---|---|
8 | 8 |
|
9 | 9 |
{- |
10 | 10 |
|
11 |
Copyright (C) 2009, 2010, 2011 Google Inc. |
|
11 |
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
|
|
12 | 12 |
|
13 | 13 |
This program is free software; you can redistribute it and/or modify |
14 | 14 |
it under the terms of the GNU General Public License as published by |
... | ... | |
37 | 37 |
import Data.Maybe (isJust, fromJust) |
38 | 38 |
import System.FilePath |
39 | 39 |
import System.IO |
40 |
import System.Exit |
|
41 | 40 |
import Text.Printf (hPrintf) |
42 | 41 |
|
43 | 42 |
import qualified Ganeti.HTools.Luxi as Luxi |
... | ... | |
50 | 49 |
|
51 | 50 |
import Ganeti.HTools.Types |
52 | 51 |
import Ganeti.HTools.CLI |
53 |
import Ganeti.HTools.Utils (sepSplit, tryRead) |
|
52 |
import Ganeti.HTools.Utils (sepSplit, tryRead, exitIfBad, exitWhen)
|
|
54 | 53 |
|
55 | 54 |
-- | Error beautifier. |
56 | 55 |
wrapIO :: IO (Result a) -> IO (Result a) |
... | ... | |
92 | 91 |
selInsts = optSelInst opts |
93 | 92 |
exInsts = optExInst opts |
94 | 93 |
|
95 |
when (length allSet > 1) $ |
|
96 |
do |
|
97 |
hPutStrLn stderr ("Error: Only one of the rapi, luxi, and data" ++ |
|
98 |
" files options should be given.") |
|
99 |
exitWith $ ExitFailure 1 |
|
94 |
exitWhen (length allSet > 1) "Only one of the rapi, luxi, and data\ |
|
95 |
\ files options should be given" |
|
100 | 96 |
|
101 | 97 |
util_contents <- maybe (return "") readFile (optDynuFile opts) |
102 |
let util_data = mapM parseUtilisation $ lines util_contents |
|
103 |
util_data' <- case util_data of |
|
104 |
Ok x -> return x |
|
105 |
Bad y -> do |
|
106 |
hPutStrLn stderr ("Error: can't parse utilisation" ++ |
|
107 |
" data: " ++ show y) |
|
108 |
exitWith $ ExitFailure 1 |
|
98 |
util_data <- exitIfBad "can't parse utilisation data" . |
|
99 |
mapM parseUtilisation $ lines util_contents |
|
109 | 100 |
input_data <- |
110 | 101 |
case () of |
111 | 102 |
_ | setRapi -> wrapIO $ Rapi.loadData mhost |
... | ... | |
115 | 106 |
| setIAllocSrc -> wrapIO $ IAlloc.loadData $ fromJust iallocsrc |
116 | 107 |
| otherwise -> return $ Bad "No backend selected! Exiting." |
117 | 108 |
|
118 |
let ldresult = input_data >>= mergeData util_data' exTags selInsts exInsts |
|
119 |
cdata <- |
|
120 |
case ldresult of |
|
121 |
Ok x -> return x |
|
122 |
Bad s -> do |
|
123 |
hPrintf stderr |
|
124 |
"Error: failed to load data, aborting. Details:\n%s\n" s:: IO () |
|
125 |
exitWith $ ExitFailure 1 |
|
109 |
let ldresult = input_data >>= mergeData util_data exTags selInsts exInsts |
|
110 |
cdata <- exitIfBad "failed to load data, aborting" ldresult |
|
126 | 111 |
let (fix_msgs, nl) = checkData (cdNodes cdata) (cdInstances cdata) |
127 | 112 |
|
128 | 113 |
unless (optVerbose opts == 0) $ maybeShowWarnings fix_msgs |
Also available in: Unified diff