Skip to content
Snippets Groups Projects
Commit 836533fa authored by Iustin Pop's avatar Iustin Pop
Browse files

Add two new autocomputed vars to Nodes

Currently we track the max disk usage/max vcpus as percentages, however
sometimes it's easier to check against minimum free disk or maximum
number of cpus, as units instead of percentages.

This patch adds two new variables, lo_dsk, hi_cpu, which are recomputed
whenever we change the m_dsk/m_cpu 'master' values.
parent 1a7eff0e
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,7 @@ module Ganeti.HTools.Node
t_dsk, f_dsk,
t_cpu, u_cpu,
p_mem, p_dsk, p_rem, p_cpu,
m_dsk, m_cpu,
m_dsk, m_cpu, lo_dsk, hi_cpu,
plist, slist, offline)
, List
-- * Constructor
......@@ -93,6 +93,10 @@ data Node = Node { name :: String -- ^ The node name
, p_cpu :: Double -- ^ Ratio of virtual to physical CPUs
, m_dsk :: Double -- ^ Minimum free disk ratio
, m_cpu :: Double -- ^ Max ratio of virt-to-phys CPUs
, lo_dsk :: Int -- ^ Autocomputed from m_dsk low disk
-- threshold
, hi_cpu :: Int -- ^ Autocomputed from m_cpu high cpu
-- threshold
, offline :: Bool -- ^ Whether the node should not be used
-- for allocations and skipped from
-- score computations
......@@ -118,6 +122,10 @@ noSecondary = -1
noLimit :: Double
noLimit = -1
-- | No limit int value
noLimitInt :: Int
noLimitInt = -1
-- * Initialization functions
-- | Create a new node.
......@@ -151,7 +159,9 @@ create name_init mem_t_init mem_n_init mem_f_init
offline = offline_init,
x_mem = 0,
m_dsk = noLimit,
m_cpu = noLimit
m_cpu = noLimit,
lo_dsk = noLimitInt,
hi_cpu = noLimitInt
}
-- | Changes the index.
......@@ -176,11 +186,14 @@ setXmem t val = t { x_mem = val }
-- | Sets the max disk usage ratio
setMdsk :: Node -> Double -> Node
setMdsk t val = t { m_dsk = val }
setMdsk t val = t { m_dsk = val,
lo_dsk = if val == noLimit
then noLimitInt
else floor (val * (t_dsk t)) }
-- | Sets the max cpu usage ratio
setMcpu :: Node -> Double -> Node
setMcpu t val = t { m_cpu = val }
setMcpu t val = t { m_cpu = val, hi_cpu = floor (val * (t_cpu t)) }
-- | Computes the maximum reserved memory for peers from a peer map.
computeMaxRes :: PeerMap.PeerMap -> PeerMap.Elem
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment