Revision ebf38064 htools/Ganeti/HTools/ExtLoader.hs

b/htools/Ganeti/HTools/ExtLoader.hs
28 28
-}
29 29

  
30 30
module Ganeti.HTools.ExtLoader
31
    ( loadExternalData
32
    , commonSuffix
33
    , maybeSaveData
34
    ) where
31
  ( loadExternalData
32
  , commonSuffix
33
  , maybeSaveData
34
  ) where
35 35

  
36 36
import Control.Monad
37 37
import Data.Maybe (isJust, fromJust)
......
58 58
-- | Parses a user-supplied utilisation string.
59 59
parseUtilisation :: String -> Result (String, DynUtil)
60 60
parseUtilisation line =
61
    case sepSplit ' ' line of
62
      [name, cpu, mem, dsk, net] ->
63
          do
64
            rcpu <- tryRead name cpu
65
            rmem <- tryRead name mem
66
            rdsk <- tryRead name dsk
67
            rnet <- tryRead name net
68
            let du = DynUtil { cpuWeight = rcpu, memWeight = rmem
69
                             , dskWeight = rdsk, netWeight = rnet }
70
            return (name, du)
71
      _ -> Bad $ "Cannot parse line " ++ line
61
  case sepSplit ' ' line of
62
    [name, cpu, mem, dsk, net] ->
63
      do
64
        rcpu <- tryRead name cpu
65
        rmem <- tryRead name mem
66
        rdsk <- tryRead name dsk
67
        rnet <- tryRead name net
68
        let du = DynUtil { cpuWeight = rcpu, memWeight = rmem
69
                         , dskWeight = rdsk, netWeight = rnet }
70
        return (name, du)
71
    _ -> Bad $ "Cannot parse line " ++ line
72 72

  
73 73
-- | External tool data loader from a variety of sources.
74 74
loadExternalData :: Options
......
100 100
                      Nothing -> return "")
101 101
  let util_data = mapM parseUtilisation $ lines util_contents
102 102
  util_data' <- (case util_data of
103
                   Ok x -> return x
103
                   Ok x  -> return x
104 104
                   Bad y -> do
105 105
                     hPutStrLn stderr ("Error: can't parse utilisation" ++
106 106
                                       " data: " ++ show y)
107 107
                     exitWith $ ExitFailure 1)
108 108
  input_data <-
109
      case () of
110
        _ | setRapi -> wrapIO $ Rapi.loadData mhost
111
          | setLuxi -> wrapIO $ Luxi.loadData $ fromJust lsock
112
          | setSim -> Simu.loadData simdata
113
          | setFile -> wrapIO $ Text.loadData $ fromJust tfile
114
          | otherwise -> return $ Bad "No backend selected! Exiting."
109
    case () of
110
      _ | setRapi -> wrapIO $ Rapi.loadData mhost
111
        | setLuxi -> wrapIO $ Luxi.loadData $ fromJust lsock
112
        | setSim -> Simu.loadData simdata
113
        | setFile -> wrapIO $ Text.loadData $ fromJust tfile
114
        | otherwise -> return $ Bad "No backend selected! Exiting."
115 115

  
116 116
  let ldresult = input_data >>= mergeData util_data' exTags selInsts exInsts
117 117
  cdata <-
118
      (case ldresult of
119
         Ok x -> return x
120
         Bad s -> do
121
           hPrintf stderr
122
             "Error: failed to load data, aborting. Details:\n%s\n" s:: IO ()
123
           exitWith $ ExitFailure 1
124
      )
118
    (case ldresult of
119
       Ok x -> return x
120
       Bad s -> do
121
         hPrintf stderr
122
           "Error: failed to load data, aborting. Details:\n%s\n" s:: IO ()
123
         exitWith $ ExitFailure 1
124
    )
125 125
  let (fix_msgs, nl) = checkData (cdNodes cdata) (cdInstances cdata)
126 126

  
127 127
  unless (optVerbose opts == 0) $ maybeShowWarnings fix_msgs

Also available in: Unified diff