Commit aa5b2f07 authored by Iustin Pop's avatar Iustin Pop
Browse files

Obey instance policy in allocation routines



This currently checks the minimum/maximum sizes and the disk
template. Unittests will come later.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent d6eec019
...@@ -7,7 +7,7 @@ goes into the /Main/ module for the individual binaries. ...@@ -7,7 +7,7 @@ goes into the /Main/ module for the individual binaries.
{- {-
Copyright (C) 2009, 2010, 2011 Google Inc. Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -454,7 +454,9 @@ allocateOnSingle :: Node.List -> Instance.Instance -> Ndx ...@@ -454,7 +454,9 @@ allocateOnSingle :: Node.List -> Instance.Instance -> Ndx
allocateOnSingle nl inst new_pdx = allocateOnSingle nl inst new_pdx =
let p = Container.find new_pdx nl let p = Container.find new_pdx nl
new_inst = Instance.setBoth inst new_pdx Node.noSecondary new_inst = Instance.setBoth inst new_pdx Node.noSecondary
in Node.addPri p inst >>= \new_p -> do in do
Instance.instMatchesPolicy inst (Node.iPolicy p)
new_p <- Node.addPri p inst
let new_nl = Container.add new_pdx new_p nl let new_nl = Container.add new_pdx new_p nl
new_score = compCV nl new_score = compCV nl
return (new_nl, new_inst, [new_p], new_score) return (new_nl, new_inst, [new_p], new_score)
...@@ -466,6 +468,7 @@ allocateOnPair nl inst new_pdx new_sdx = ...@@ -466,6 +468,7 @@ allocateOnPair nl inst new_pdx new_sdx =
let tgt_p = Container.find new_pdx nl let tgt_p = Container.find new_pdx nl
tgt_s = Container.find new_sdx nl tgt_s = Container.find new_sdx nl
in do in do
Instance.instMatchesPolicy inst (Node.iPolicy tgt_p)
new_p <- Node.addPri tgt_p inst new_p <- Node.addPri tgt_p inst
new_s <- Node.addSec tgt_s inst new_pdx new_s <- Node.addSec tgt_s inst new_pdx
let new_inst = Instance.setBoth inst new_pdx new_sdx let new_inst = Instance.setBoth inst new_pdx new_sdx
......
...@@ -7,7 +7,7 @@ intelligence is in the "Node" and "Cluster" modules. ...@@ -7,7 +7,7 @@ intelligence is in the "Node" and "Cluster" modules.
{- {-
Copyright (C) 2009, 2010, 2011 Google Inc. Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -43,6 +43,9 @@ module Ganeti.HTools.Instance ...@@ -43,6 +43,9 @@ module Ganeti.HTools.Instance
, setBoth , setBoth
, setMovable , setMovable
, specOf , specOf
, instBelowISpec
, instAboveISpec
, instMatchesPolicy
, shrinkByType , shrinkByType
, localStorageTemplates , localStorageTemplates
, hasSecondary , hasSecondary
...@@ -53,7 +56,6 @@ module Ganeti.HTools.Instance ...@@ -53,7 +56,6 @@ module Ganeti.HTools.Instance
import qualified Ganeti.HTools.Types as T import qualified Ganeti.HTools.Types as T
import qualified Ganeti.HTools.Container as Container import qualified Ganeti.HTools.Container as Container
import qualified Ganeti.Constants as C
import Ganeti.HTools.Utils import Ganeti.HTools.Utils
...@@ -230,6 +232,33 @@ specOf :: Instance -> T.RSpec ...@@ -230,6 +232,33 @@ specOf :: Instance -> T.RSpec
specOf Instance { mem = m, dsk = d, vcpus = c } = specOf Instance { mem = m, dsk = d, vcpus = c } =
T.RSpec { T.rspecCpu = c, T.rspecMem = m, T.rspecDsk = d } T.RSpec { T.rspecCpu = c, T.rspecMem = m, T.rspecDsk = d }
-- | Checks if an instance is smaller than a given spec. Returns
-- OpGood for a correct spec, otherwise OpFail one of the possible
-- failure modes.
instBelowISpec :: Instance -> T.ISpec -> T.OpResult ()
instBelowISpec inst ispec
| mem inst > T.iSpecMemorySize ispec = T.OpFail T.FailMem
| dsk inst > T.iSpecDiskSize ispec = T.OpFail T.FailDisk
| vcpus inst > T.iSpecCpuCount ispec = T.OpFail T.FailCPU
| otherwise = T.OpGood ()
-- | Checks if an instance is bigger than a given spec.
instAboveISpec :: Instance -> T.ISpec -> T.OpResult ()
instAboveISpec inst ispec
| mem inst < T.iSpecMemorySize ispec = T.OpFail T.FailMem
| dsk inst < T.iSpecDiskSize ispec = T.OpFail T.FailDisk
| vcpus inst < T.iSpecCpuCount ispec = T.OpFail T.FailCPU
| otherwise = T.OpGood ()
-- | Checks if an instance matches a policy.
instMatchesPolicy :: Instance -> T.IPolicy -> T.OpResult ()
instMatchesPolicy inst ipol = do
instAboveISpec inst (T.iPolicyMinSpec ipol)
instBelowISpec inst (T.iPolicyMaxSpec ipol)
if (diskTemplate inst `elem` T.iPolicyDiskTemplates ipol)
then T.OpGood ()
else T.OpFail T.FailDisk
-- | Checks whether the instance uses a secondary node. -- | Checks whether the instance uses a secondary node.
-- --
-- /Note:/ This should be reconciled with @'sNode' == -- /Note:/ This should be reconciled with @'sNode' ==
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment