[Pkg-ganeti-devel] [ganeti] 31/165: Add a function for dedicated allocation on a pair

Apollon Oikonomopoulos apoikos at moszumanska.debian.org
Tue Aug 11 13:53:10 UTC 2015


This is an automated email from the git hooks/post-receive script.

apoikos pushed a commit to branch master
in repository ganeti.

commit c2e5b4f08fe149e9aa69c5eec4a3cc16949bd7da
Author: Klaus Aehlig <aehlig at google.com>
Date:   Wed Jan 28 18:37:41 2015 +0100

    Add a function for dedicated allocation on a pair
    
    Here the metric is the sum of the two allocation metrics
    for primary and secondary.
    
    Signed-off-by: Klaus Aehlig <aehlig at google.com>
    Reviewed-by: Petr Pudlak <pudlak at google.com>
---
 src/Ganeti/HTools/Dedicated.hs | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/Ganeti/HTools/Dedicated.hs b/src/Ganeti/HTools/Dedicated.hs
index 4ba57ff..7503bf8 100644
--- a/src/Ganeti/HTools/Dedicated.hs
+++ b/src/Ganeti/HTools/Dedicated.hs
@@ -39,6 +39,7 @@ module Ganeti.HTools.Dedicated
   , Metric
   , lostAllocationsMetric
   , allocateOnSingle
+  , allocateOnPair
   ) where
 
 import Control.Applicative (liftA2)
@@ -135,3 +136,26 @@ allocateOnSingle opts nl inst new_pdx = do
   (metrics, new_p) <- lostAllocationsMetric opts testInst inst primary
   let new_nl = Container.add new_pdx new_p nl
   return (new_nl, new_inst, [new_p], metrics)
+
+-- | Allocate an instance on a given pair of nodes.
+allocateOnPair :: Alg.AlgorithmOptions
+               -> Node.List
+               -> Instance.Instance
+               -> T.Ndx
+               -> T.Ndx
+               -> T.OpResult (Node.GenericAllocElement Metric)
+allocateOnPair opts nl inst pdx sdx = do
+  let primary = Container.find pdx nl
+      secondary = Container.find sdx nl
+      policy = Node.iPolicy primary
+      testInst = testInstances policy
+      inst' = Instance.setBoth inst pdx sdx
+  Instance.instMatchesPolicy inst policy (Node.exclStorage primary)
+  ((lAllP, dskP), primary') <- lostAllocationsMetric opts testInst inst' primary
+  secondary' <- Node.addSec secondary inst' pdx
+  let lAllS =  zipWith (-) (allocationVector testInst secondary)
+                           (allocationVector testInst secondary')
+      dskS = Node.fDsk secondary'
+      metric = (zipWith (+) lAllP lAllS, dskP + dskS)
+      nl' = Container.addTwo pdx primary' sdx secondary' nl
+  return (nl', inst', [primary', secondary'], metric)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ganeti/ganeti.git



More information about the Pkg-ganeti-devel mailing list