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

Add a new function to compute allocation deltas

Given two cluster states, the new function can answer the following
questions:

- how much resources currently allocated
- how much resources finally allocated (delta from above is how much we
  can actually allocate on the cluster)
- unallocable resources (whatever is left free after the previous step)
parent 86ecce4a
No related merge requests found
...@@ -32,8 +32,10 @@ module Ganeti.HTools.Cluster ...@@ -32,8 +32,10 @@ module Ganeti.HTools.Cluster
AllocSolution AllocSolution
, Table(..) , Table(..)
, CStats(..) , CStats(..)
, AllocStats
-- * Generic functions -- * Generic functions
, totalResources , totalResources
, computeAllocationDelta
-- * First phase functions -- * First phase functions
, computeBadItems , computeBadItems
-- * Second phase functions -- * Second phase functions
...@@ -103,6 +105,9 @@ data CStats = CStats { csFmem :: Int -- ^ Cluster free mem ...@@ -103,6 +105,9 @@ data CStats = CStats { csFmem :: Int -- ^ Cluster free mem
, csNinst :: Int -- ^ The total number of instances , csNinst :: Int -- ^ The total number of instances
} }
-- | Currently used, possibly to allocate, unallocable
type AllocStats = (RSpec, RSpec, RSpec)
-- * Utility functions -- * Utility functions
-- | Verifies the N+1 status and return the affected nodes. -- | Verifies the N+1 status and return the affected nodes.
...@@ -179,6 +184,23 @@ totalResources nl = ...@@ -179,6 +184,23 @@ totalResources nl =
let cs = foldl' updateCStats emptyCStats . Container.elems $ nl let cs = foldl' updateCStats emptyCStats . Container.elems $ nl
in cs { csScore = compCV nl } in cs { csScore = compCV nl }
-- | Compute the delta between two cluster state.
--
-- This is used when doing allocations, to understand better the
-- available cluster resources.
computeAllocationDelta :: CStats -> CStats -> AllocStats
computeAllocationDelta cini cfin =
let CStats {csImem = i_imem, csIdsk = i_idsk, csIcpu = i_icpu} = cini
CStats {csImem = f_imem, csIdsk = f_idsk, csIcpu = f_icpu,
csTmem = t_mem, csTdsk = t_dsk, csVcpu = v_cpu } = cfin
rini = RSpec i_icpu i_imem i_idsk
rfin = RSpec f_icpu f_imem f_idsk
un_cpu = if v_cpu == Node.noLimitInt
then Node.noLimitInt
else v_cpu - f_icpu
runa = RSpec un_cpu (truncate t_mem - f_imem) (truncate t_dsk - f_idsk)
in (rini, rfin, runa)
-- | The names of the individual elements in the CV list -- | The names of the individual elements in the CV list
detailedCVNames :: [String] detailedCVNames :: [String]
detailedCVNames = [ "free_mem_cv" detailedCVNames = [ "free_mem_cv"
......
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