Revision 284e9822 htools/Ganeti/HTools/CLI.hs

b/htools/Ganeti/HTools/CLI.hs
122 122
  , optMachineReadable :: Bool       -- ^ Output machine-readable format
123 123
  , optMaster      :: String         -- ^ Collect data from RAPI
124 124
  , optMaxLength   :: Int            -- ^ Stop after this many steps
125
  , optMcpu        :: Double         -- ^ Max cpu ratio for nodes
125
  , optMcpu        :: Maybe Double   -- ^ Override max cpu ratio for nodes
126 126
  , optMdsk        :: Double         -- ^ Max disk usage ratio for nodes
127 127
  , optMinGain     :: Score          -- ^ Min gain we aim for in a step
128 128
  , optMinGainLim  :: Score          -- ^ Limit below which we apply mingain
......
161 161
  , optMachineReadable = False
162 162
  , optMaster      = ""
163 163
  , optMaxLength   = -1
164
  , optMcpu        = defVcpuRatio
164
  , optMcpu        = Nothing
165 165
  , optMdsk        = defReservedDiskRatio
166 166
  , optMinGain     = 1e-2
167 167
  , optMinGainLim  = 1e-1
......
283 283

  
284 284
oMaxCpu :: OptType
285 285
oMaxCpu = Option "" ["max-cpu"]
286
          (ReqArg (\ n opts -> Ok opts { optMcpu = read n }) "RATIO")
287
          "maximum virtual-to-physical cpu ratio for nodes (from 1\
288
          \ upwards) [64]"
286
          (ReqArg (\ n opts -> do
287
                     mcpu <- tryRead "parsing max-cpu" n
288
                     when (mcpu <= 0) $
289
                          fail "Invalid value of the max-cpu ratio,\
290
                               \ expected >0"
291
                     return $ opts { optMcpu = Just mcpu }) "RATIO")
292
          "maximum virtual-to-physical cpu ratio for nodes (from 0\
293
          \ upwards) [default read from cluster]"
289 294

  
290 295
oMaxSolLength :: OptType
291 296
oMaxSolLength = Option "l" ["max-length"]
......
517 522
    hPutStrLn stderr "Warning: cluster has inconsistent data:"
518 523
    hPutStrLn stderr . unlines . map (printf "  - %s") $ fix_msgs
519 524

  
525
-- | Potentially set the node as offline based on passed offline list.
526
setNodeOffline :: [Ndx] -> Node.Node -> Node.Node
527
setNodeOffline offline_indices n =
528
  if Node.idx n `elem` offline_indices
529
    then Node.setOffline n True
530
    else n
531

  
520 532
-- | Set node properties based on command line options.
521 533
setNodeStatus :: Options -> Node.List -> IO Node.List
522 534
setNodeStatus opts fixed_nl = do
......
535 547
         hPrintf stderr "Error: Wrong node name(s) set as offline: %s\n"
536 548
                     (commaJoin (map lrContent offline_wrong)) :: IO ()
537 549
         exitWith $ ExitFailure 1
538

  
539
  let nm = Container.map (\n -> if Node.idx n `elem` offline_indices
540
                                then Node.setOffline n True
541
                                else n) fixed_nl
542
      nlf = Container.map (flip Node.setMdsk m_dsk . flip Node.setMcpu m_cpu)
543
            nm
544
  return nlf
550
  let setMCpuFn = case m_cpu of
551
                    Nothing -> id
552
                    Just new_mcpu -> flip Node.setMcpu new_mcpu
553
  let nm = Container.map (setNodeOffline offline_indices .
554
                          flip Node.setMdsk m_dsk .
555
                          setMCpuFn) fixed_nl
556
  return nm

Also available in: Unified diff