From c8db97e5ff3640a07e782a6e6bd192820718919d Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 30 Oct 2009 12:07:28 +0100 Subject: [PATCH] Add support for shrinking instance specs This patch adds a function that, for some given failure modes, shrinks a given instance in the hope that allocation will succeed when retried with the new spec. --- Ganeti/HTools/Instance.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Ganeti/HTools/Instance.hs b/Ganeti/HTools/Instance.hs index 0ec0644d3..72b27dadc 100644 --- a/Ganeti/HTools/Instance.hs +++ b/Ganeti/HTools/Instance.hs @@ -36,6 +36,7 @@ module Ganeti.HTools.Instance , setPri , setSec , setBoth + , shrinkByType ) where import qualified Ganeti.HTools.Types as T @@ -62,6 +63,16 @@ instance T.Element Instance where setName = setName setIdx = setIdx +-- | Base memory unit. +unitMem :: Int +unitMem = 64 +-- | Base disk unit. +unitDsk :: Int +unitDsk = 256 +-- | Base vcpus unit. +unitCpu :: Int +unitCpu = 1 + -- | A simple name for the int, instance association list. type AssocList = [(T.Idx, Instance)] @@ -124,3 +135,20 @@ setBoth :: Instance -- ^ the original instance -> T.Ndx -- ^ new secondary node index -> Instance -- ^ the modified instance setBoth t p s = t { pNode = p, sNode = s } + +-- | Try to shrink the instance based on the reason why we can't +-- allocate it. +shrinkByType :: Instance -> T.FailMode -> T.Result Instance +shrinkByType inst T.FailMem = let v = mem inst - unitMem + in if v < unitMem + then T.Bad "out of memory" + else T.Ok inst { mem = v } +shrinkByType inst T.FailDisk = let v = dsk inst - unitDsk + in if v < unitDsk + then T.Bad "out of disk" + else T.Ok inst { dsk = v } +shrinkByType inst T.FailCPU = let v = vcpus inst - unitCpu + in if v < unitCpu + then T.Bad "out of vcpus" + else T.Ok inst { vcpus = v } +shrinkByType _ f = T.Bad $ "Unhandled failure mode " ++ show f -- GitLab