Commit 284e9822 authored by Iustin Pop's avatar Iustin Pop
Browse files

Change meaning of the --max-cpu option



Instead of always overriding, we should update the nodes's maxcpu
setting only when the option is specified. Otherwise this will be read
from the cluster or from the Ganeti constant for non-live backends.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 5f3b040a
...@@ -122,7 +122,7 @@ data Options = Options ...@@ -122,7 +122,7 @@ data Options = Options
, optMachineReadable :: Bool -- ^ Output machine-readable format , optMachineReadable :: Bool -- ^ Output machine-readable format
, optMaster :: String -- ^ Collect data from RAPI , optMaster :: String -- ^ Collect data from RAPI
, optMaxLength :: Int -- ^ Stop after this many steps , optMaxLength :: Int -- ^ Stop after this many steps
, optMcpu :: Double -- ^ Max cpu ratio for nodes , optMcpu :: Maybe Double -- ^ Override max cpu ratio for nodes
, optMdsk :: Double -- ^ Max disk usage ratio for nodes , optMdsk :: Double -- ^ Max disk usage ratio for nodes
, optMinGain :: Score -- ^ Min gain we aim for in a step , optMinGain :: Score -- ^ Min gain we aim for in a step
, optMinGainLim :: Score -- ^ Limit below which we apply mingain , optMinGainLim :: Score -- ^ Limit below which we apply mingain
...@@ -161,7 +161,7 @@ defaultOptions = Options ...@@ -161,7 +161,7 @@ defaultOptions = Options
, optMachineReadable = False , optMachineReadable = False
, optMaster = "" , optMaster = ""
, optMaxLength = -1 , optMaxLength = -1
, optMcpu = defVcpuRatio , optMcpu = Nothing
, optMdsk = defReservedDiskRatio , optMdsk = defReservedDiskRatio
, optMinGain = 1e-2 , optMinGain = 1e-2
, optMinGainLim = 1e-1 , optMinGainLim = 1e-1
...@@ -283,9 +283,14 @@ oMachineReadable = Option "" ["machine-readable"] ...@@ -283,9 +283,14 @@ oMachineReadable = Option "" ["machine-readable"]
oMaxCpu :: OptType oMaxCpu :: OptType
oMaxCpu = Option "" ["max-cpu"] oMaxCpu = Option "" ["max-cpu"]
(ReqArg (\ n opts -> Ok opts { optMcpu = read n }) "RATIO") (ReqArg (\ n opts -> do
"maximum virtual-to-physical cpu ratio for nodes (from 1\ mcpu <- tryRead "parsing max-cpu" n
\ upwards) [64]" when (mcpu <= 0) $
fail "Invalid value of the max-cpu ratio,\
\ expected >0"
return $ opts { optMcpu = Just mcpu }) "RATIO")
"maximum virtual-to-physical cpu ratio for nodes (from 0\
\ upwards) [default read from cluster]"
oMaxSolLength :: OptType oMaxSolLength :: OptType
oMaxSolLength = Option "l" ["max-length"] oMaxSolLength = Option "l" ["max-length"]
...@@ -517,6 +522,13 @@ maybeShowWarnings fix_msgs = ...@@ -517,6 +522,13 @@ maybeShowWarnings fix_msgs =
hPutStrLn stderr "Warning: cluster has inconsistent data:" hPutStrLn stderr "Warning: cluster has inconsistent data:"
hPutStrLn stderr . unlines . map (printf " - %s") $ fix_msgs hPutStrLn stderr . unlines . map (printf " - %s") $ fix_msgs
-- | Potentially set the node as offline based on passed offline list.
setNodeOffline :: [Ndx] -> Node.Node -> Node.Node
setNodeOffline offline_indices n =
if Node.idx n `elem` offline_indices
then Node.setOffline n True
else n
-- | Set node properties based on command line options. -- | Set node properties based on command line options.
setNodeStatus :: Options -> Node.List -> IO Node.List setNodeStatus :: Options -> Node.List -> IO Node.List
setNodeStatus opts fixed_nl = do setNodeStatus opts fixed_nl = do
...@@ -535,10 +547,10 @@ setNodeStatus opts fixed_nl = do ...@@ -535,10 +547,10 @@ setNodeStatus opts fixed_nl = do
hPrintf stderr "Error: Wrong node name(s) set as offline: %s\n" hPrintf stderr "Error: Wrong node name(s) set as offline: %s\n"
(commaJoin (map lrContent offline_wrong)) :: IO () (commaJoin (map lrContent offline_wrong)) :: IO ()
exitWith $ ExitFailure 1 exitWith $ ExitFailure 1
let setMCpuFn = case m_cpu of
let nm = Container.map (\n -> if Node.idx n `elem` offline_indices Nothing -> id
then Node.setOffline n True Just new_mcpu -> flip Node.setMcpu new_mcpu
else n) fixed_nl let nm = Container.map (setNodeOffline offline_indices .
nlf = Container.map (flip Node.setMdsk m_dsk . flip Node.setMcpu m_cpu) flip Node.setMdsk m_dsk .
nm setMCpuFn) fixed_nl
return nlf return nm
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment