From 53822ec41e6592b88915554a017fabe671e17ed7 Mon Sep 17 00:00:00 2001 From: Bernardo Dal Seno <bdalseno@google.com> Date: Tue, 23 Apr 2013 23:11:01 +0200 Subject: [PATCH] hspace: Handle multiple ipolicy specs With tiered allocation, hspace uses all the max specs in turn as the initial instance spec. Signed-off-by: Bernardo Dal Seno <bdalseno@google.com> Reviewed-by: Helga Velroyen <helgav@google.com> --- src/Ganeti/HTools/Cluster.hs | 1 + src/Ganeti/HTools/Program/Hspace.hs | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Ganeti/HTools/Cluster.hs b/src/Ganeti/HTools/Cluster.hs index ddd5c17f7..96ea8454d 100644 --- a/src/Ganeti/HTools/Cluster.hs +++ b/src/Ganeti/HTools/Cluster.hs @@ -33,6 +33,7 @@ module Ganeti.HTools.Cluster , EvacSolution(..) , Table(..) , CStats(..) + , AllocNodes , AllocResult , AllocMethod , AllocSolutionList diff --git a/src/Ganeti/HTools/Program/Hspace.hs b/src/Ganeti/HTools/Program/Hspace.hs index d26d5fe9b..78f068704 100644 --- a/src/Ganeti/HTools/Program/Hspace.hs +++ b/src/Ganeti/HTools/Program/Hspace.hs @@ -398,6 +398,18 @@ instFromSpec spx = Instance.create "new" (rspecMem spx) (rspecDsk spx) [rspecDsk spx] (rspecCpu spx) Running [] True (-1) (-1) +combineTiered :: Maybe Int -> Cluster.AllocNodes -> Cluster.AllocResult -> + Instance.Instance -> Result Cluster.AllocResult +combineTiered limit allocnodes result inst = do + let (_, nl, il, ixes, cstats) = result + ixes_cnt = length ixes + (stop, newlimit) = case limit of + Nothing -> (False, Nothing) + Just n -> (n <= ixes_cnt, Just (n - ixes_cnt)) + if stop + then return result + else Cluster.tieredAlloc nl il newlimit inst allocnodes ixes cstats + -- | Main function. main :: Options -> [String] -> IO () main opts args = do @@ -447,17 +459,18 @@ main opts args = do -- Run the tiered allocation let minmaxes = iPolicyMinMaxISpecs ipol - -- TODO: Go through all min/max specs pairs - tspec <- case minmaxes of - [] -> exitErr "Empty list of specs received from the cluster" - minmax:_ -> return $ fromMaybe - (rspecFromISpec (minMaxISpecsMaxSpec minmax)) - (optTieredSpec opts) + tspecs = case optTieredSpec opts of + Nothing -> map (rspecFromISpec . minMaxISpecsMaxSpec) + minmaxes + Just t -> [t] + tinsts = map (\ts -> instFromSpec ts disk_template su) tspecs + tspec <- case tspecs of + [] -> exitErr "Empty list of specs received from the cluster" + t:_ -> return t (treason, trl_nl, _, spec_map) <- runAllocation cdata stop_allocation - (Cluster.tieredAlloc nl il alloclimit - (instFromSpec tspec disk_template su) allocnodes [] []) + (foldM (combineTiered alloclimit allocnodes) ([], nl, il, [], []) tinsts) tspec disk_template SpecTiered opts printTiered machine_r spec_map nl trl_nl treason -- GitLab