[Pkg-ganeti-devel] [ganeti] 30/165: Add function for dedicated allocation on one node

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 3927e67a74c57999f3ae59cb00e59ab7652c6771
Author: Klaus Aehlig <aehlig at google.com>
Date:   Mon Jan 26 13:49:07 2015 +0100

    Add function for dedicated allocation on one node
    
    Add a function that tests whether an instance can be placed on a
    single node, and, if so, return metrics and new cluster.
    
    Signed-off-by: Klaus Aehlig <aehlig at google.com>
    Reviewed-by: Petr Pudlak <pudlak at google.com>
---
 src/Ganeti/HTools/Dedicated.hs | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/Ganeti/HTools/Dedicated.hs b/src/Ganeti/HTools/Dedicated.hs
index 5b1e2e8..4ba57ff 100644
--- a/src/Ganeti/HTools/Dedicated.hs
+++ b/src/Ganeti/HTools/Dedicated.hs
@@ -38,6 +38,7 @@ module Ganeti.HTools.Dedicated
   , allocationVector
   , Metric
   , lostAllocationsMetric
+  , allocateOnSingle
   ) where
 
 import Control.Applicative (liftA2)
@@ -48,6 +49,8 @@ import qualified Data.IntSet as IntSet
 import Data.List (sortBy)
 
 import Ganeti.BasicTypes (iterateOk)
+import qualified Ganeti.HTools.AlgorithmParams as Alg
+import qualified Ganeti.HTools.Container as Container
 import qualified Ganeti.HTools.Group as Group
 import qualified Ganeti.HTools.Instance as Instance
 import qualified Ganeti.HTools.Loader as Loader
@@ -117,3 +120,18 @@ lostAllocationsMetric opts insts inst node = do
   let after = allocVec node'
       disk = Node.fDsk node'
   return ((zipWith (-) before after, disk), node')
+
+-- | Allocate an instance on a given node.
+allocateOnSingle :: Alg.AlgorithmOptions
+                 -> Node.List -> Instance.Instance -> T.Ndx
+                 -> T.OpResult (Node.GenericAllocElement Metric)
+allocateOnSingle opts nl inst new_pdx = do
+  let primary = Container.find new_pdx nl
+      policy = Node.iPolicy primary
+      testInst = testInstances policy
+      excl = Node.exclStorage primary
+      new_inst = Instance.setBoth inst new_pdx Node.noSecondary
+  Instance.instMatchesPolicy inst policy excl
+  (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)

-- 
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