Revision 7da760ca

b/htools/Ganeti/HTools/CLI.hs
184 184
-- | Abrreviation for the option type.
185 185
type OptType = OptDescr (Options -> Result Options)
186 186

  
187
-- * Helper functions
188

  
189
parseISpecString :: String -> String -> Result RSpec
190
parseISpecString descr inp = do
191
  let sp = sepSplit ',' inp
192
  prs <- mapM (\(fn, val) -> fn val) $
193
         zip [ annotateResult (descr ++ " specs memory") . parseUnit
194
             , annotateResult (descr ++ " specs disk") . parseUnit
195
             , tryRead (descr ++ " specs cpus")
196
             ] sp
197
  case prs of
198
    [dsk, ram, cpu] -> return $ RSpec cpu ram dsk
199
    _ -> Bad $ "Invalid " ++ descr ++ " specification: '" ++ inp ++
200
         "', expected disk,ram,cpu"
201

  
187 202
-- * Command line options
188 203

  
189 204
oDataFile :: OptType
......
396 411
oTieredSpec :: OptType
397 412
oTieredSpec = Option "" ["tiered-alloc"]
398 413
             (ReqArg (\ inp opts -> do
399
                        let sp = sepSplit ',' inp
400
                        prs <- mapM (\(fn, val) -> fn val) $
401
                               zip [ annotateResult "tiered specs memory" .
402
                                     parseUnit
403
                                   , annotateResult "tiered specs disk" .
404
                                     parseUnit
405
                                   , tryRead "tiered specs cpus"
406
                                   ] sp
407
                        tspec <-
408
                          case prs of
409
                            [dsk, ram, cpu] -> return $ RSpec cpu ram dsk
410
                            _ -> Bad $ "Invalid specification: " ++ inp ++
411
                                 ", expected disk,ram,cpu"
414
                        tspec <- parseISpecString "tiered" inp
412 415
                        return $ opts { optTieredSpec = Just tspec } )
413 416
              "TSPEC")
414 417
             "enable tiered specs allocation, given as 'disk,ram,cpu'"

Also available in: Unified diff