diff --git a/Ganeti/HTools/CLI.hs b/Ganeti/HTools/CLI.hs index df9bbc82b04145a81e346c6496266229cb3187fe..4fd0ed0ba2faded5b0a0841d3525a40ab9a8da98 100644 --- a/Ganeti/HTools/CLI.hs +++ b/Ganeti/HTools/CLI.hs @@ -129,8 +129,8 @@ defaultOptions = Options , optLuxi = Nothing , optMaster = "" , optMaxLength = -1 - , optMcpu = -1 - , optMdsk = -1 + , optMcpu = defVcpuRatio + , optMdsk = defReservedDiskRatio , optMinScore = 1e-9 , optNoHeaders = False , optNodeSim = Nothing @@ -225,7 +225,8 @@ oLuxiSocket = Option "L" ["luxi"] oMaxCpu :: OptType oMaxCpu = Option "" ["max-cpu"] (ReqArg (\ n opts -> Ok opts { optMcpu = read n }) "RATIO") - "maximum virtual-to-physical cpu ratio for nodes" + "maximum virtual-to-physical cpu ratio for nodes (from 1\ + \ upwards) [64]" oMaxSolLength :: OptType oMaxSolLength = Option "l" ["max-length"] @@ -236,7 +237,7 @@ oMaxSolLength = Option "l" ["max-length"] oMinDisk :: OptType oMinDisk = Option "" ["min-disk"] (ReqArg (\ n opts -> Ok opts { optMdsk = read n }) "RATIO") - "minimum free disk space for nodes (between 0 and 1)" + "minimum free disk space for nodes (between 0 and 1) [0]" oMinScore :: OptType oMinScore = Option "e" ["min-score"] diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs index 1afc08c38ccb36bc98328179025a0227ac06017d..f4cd7661e63d7fdff57282bdc6135daa29f9be56 100644 --- a/Ganeti/HTools/Cluster.hs +++ b/Ganeti/HTools/Cluster.hs @@ -170,9 +170,7 @@ updateCStats cs node = , csTmem = x_tmem + Node.tMem node , csTdsk = x_tdsk + Node.tDsk node , csTcpu = x_tcpu + Node.tCpu node - , csVcpu = if inc_vcpu == Node.noLimitInt - then Node.noLimitInt - else x_vcpu + inc_vcpu + , csVcpu = x_vcpu + inc_vcpu , csXmem = x_xmem + Node.xMem node , csNmem = x_nmem + Node.nMem node , csNinst = x_ninst + length (Node.pList node) @@ -197,9 +195,7 @@ computeAllocationDelta cini cfin = csTmem = t_mem, csTdsk = t_dsk, csVcpu = v_cpu } = cfin rini = RSpec i_icpu i_imem i_idsk rfin = RSpec (f_icpu - i_icpu) (f_imem - i_imem) (f_idsk - i_idsk) - un_cpu = if v_cpu == Node.noLimitInt - then Node.noLimitInt - else v_cpu - f_icpu + un_cpu = v_cpu - f_icpu runa = RSpec un_cpu (truncate t_mem - f_imem) (truncate t_dsk - f_idsk) in (rini, rfin, runa) diff --git a/Ganeti/HTools/Node.hs b/Ganeti/HTools/Node.hs index 0abec278a22e8c7a796561e28a18466b8725b658..3e48f85145c8e612fc39c24680b3f2c62f111ea6 100644 --- a/Ganeti/HTools/Node.hs +++ b/Ganeti/HTools/Node.hs @@ -58,7 +58,6 @@ module Ganeti.HTools.Node , AssocList , AllocElement , noSecondary - , noLimitInt ) where import Data.List @@ -133,14 +132,6 @@ type AllocElement = (List, Instance.Instance, [Node]) noSecondary :: T.Ndx noSecondary = -1 --- | No limit value -noLimit :: Double -noLimit = -1 - --- | No limit int value -noLimitInt :: Int -noLimitInt = -1 - -- * Helper functions -- | Add a tag to a tagmap @@ -204,15 +195,23 @@ create name_init mem_t_init mem_n_init mem_f_init , pCpu = 0 , offline = offline_init , xMem = 0 - , mDsk = noLimit - , mCpu = noLimit - , loDsk = noLimitInt - , hiCpu = noLimitInt + , mDsk = T.defReservedDiskRatio + , mCpu = T.defVcpuRatio + , loDsk = mDskToloDsk T.defReservedDiskRatio dsk_t_init + , hiCpu = mCpuTohiCpu T.defVcpuRatio cpu_t_init , utilPool = T.baseUtil , utilLoad = T.zeroUtil , pTags = Map.empty } +-- | Conversion formula from mDsk/tDsk to loDsk +mDskToloDsk :: Double -> Double -> Int +mDskToloDsk mval tdsk = floor (mval * tdsk) + +-- | Conversion formula from mCpu/tCpu to hiCpu +mCpuTohiCpu :: Double -> Double -> Int +mCpuTohiCpu mval tcpu = floor (mval * tcpu) + -- | Changes the index. -- -- This is used only during the building of the data structures. @@ -235,18 +234,11 @@ setXmem t val = t { xMem = val } -- | Sets the max disk usage ratio setMdsk :: Node -> Double -> Node -setMdsk t val = t { mDsk = val, - loDsk = if val == noLimit - then noLimitInt - else floor (val * tDsk t) } +setMdsk t val = t { mDsk = val, loDsk = mDskToloDsk val (tDsk t) } -- | Sets the max cpu usage ratio setMcpu :: Node -> Double -> Node -setMcpu t val = t { mCpu = val, hiCpu = hcpu } - where new_hcpu = floor (val * tCpu t)::Int - hcpu = if new_hcpu < 0 - then noLimitInt - else new_hcpu +setMcpu t val = t { mCpu = val, hiCpu = mCpuTohiCpu val (tCpu t) } -- | Computes the maximum reserved memory for peers from a peer map. computeMaxRes :: P.PeerMap -> P.Elem @@ -401,12 +393,9 @@ availDisk :: Node -> Int availDisk t = let _f = fDsk t _l = loDsk t - in - if _l == noLimitInt - then _f - else if _f < _l - then 0 - else _f - _l + in if _f < _l + then 0 + else _f - _l -- * Display functions diff --git a/Ganeti/HTools/Types.hs b/Ganeti/HTools/Types.hs index fb6493e7b7531eccc8a742e36fa4ee2c786b1d40..438975399cae0ea77b0bbc382aaa505a355ef79b 100644 --- a/Ganeti/HTools/Types.hs +++ b/Ganeti/HTools/Types.hs @@ -35,6 +35,8 @@ module Ganeti.HTools.Types , baseUtil , addUtil , subUtil + , defVcpuRatio + , defReservedDiskRatio , Placement , IMove(..) , MoveJob @@ -124,6 +126,14 @@ connTimeout = 15 queryTimeout :: Int queryTimeout = 60 +-- | Default vcpu-to-pcpu ratio (randomly chosen value). +defVcpuRatio :: Double +defVcpuRatio = 64 + +-- | Default max disk usage ratio. +defReservedDiskRatio :: Double +defReservedDiskRatio = 0 + {-| This is similar to the JSON library Result type - *very* similar, but