hroller: option to ignore non-redundant instances
authorKlaus Aehlig <aehlig@google.com>
Thu, 16 May 2013 17:36:47 +0000 (19:36 +0200)
committerKlaus Aehlig <aehlig@google.com>
Wed, 22 May 2013 09:08:41 +0000 (11:08 +0200)
Add an option to hroller restoring the old behavior on not taking
any non-redundant instances into account when forming reboot
groups.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

src/Ganeti/HTools/CLI.hs
src/Ganeti/HTools/Program/Hroller.hs

index 3a88c9d..fcfd221 100644 (file)
@@ -55,6 +55,7 @@ module Ganeti.HTools.CLI
   , oForce
   , oGroup
   , oIAllocSrc
+  , oIgnoreNonRedundant
   , oInstMoves
   , oJobDelay
   , genOLuxiSocket
@@ -125,6 +126,7 @@ data Options = Options
   , optForce       :: Bool           -- ^ Force the execution
   , optGroup       :: Maybe GroupID  -- ^ The UUID of the group to process
   , optIAllocSrc   :: Maybe FilePath -- ^ The iallocation spec
+  , optIgnoreNonRedundant :: Bool    -- ^ Ignore non-redundant instances
   , optSelInst     :: [String]       -- ^ Instances to be excluded
   , optLuxi        :: Maybe FilePath -- ^ Collect data from Luxi
   , optJobDelay    :: Double         -- ^ Delay before executing first job
@@ -176,6 +178,7 @@ defaultOptions  = Options
   , optForce       = False
   , optGroup       = Nothing
   , optIAllocSrc   = Nothing
+  , optIgnoreNonRedundant = False
   , optSelInst     = []
   , optLuxi        = Nothing
   , optJobDelay    = 10
@@ -356,6 +359,13 @@ oIAllocSrc =
    "Specify an iallocator spec as the cluster data source",
    OptComplFile)
 
+oIgnoreNonRedundant :: OptType
+oIgnoreNonRedundant =
+  (Option "" ["ignore-non-redundant"]
+   (NoArg (\ opts -> Ok opts { optIgnoreNonRedundant = True }))
+    "Pretend that there are no non-redundant instances in the cluster",
+    OptComplNone)
+
 oJobDelay :: OptType
 oJobDelay =
   (Option "" ["job-delay"]
index f567ba5..4be13d5 100644 (file)
@@ -69,6 +69,7 @@ options = do
     , oSaveCluster
     , oGroup
     , oSkipNonRedundant
+    , oIgnoreNonRedundant
     , oForce
     , oOneStepOnly
     ]
@@ -234,15 +235,17 @@ main opts args = do
                         , ("Dcolor", colorDcolor)
                         ]
       colorings = map (\(v,a) -> (v,(colorVertMap.a) nodeGraph)) colorAlgorithms
-      smallestColoring =
+      smallestColoring = IntMap.elems $
         (snd . minimumBy (comparing (IntMap.size . snd))) colorings
       allNdx = map Node.idx $ Container.elems nlf
-      splitted = mapM (\ grp -> partitionNonRedundant grp allNdx (nlf,ilf)) $
-                 IntMap.elems smallestColoring
-  rebootGroups <- case splitted of
-                    Ok splitgroups -> return $ concat splitgroups
-                    Bad _ -> exitErr "Not enough capacity to move non-redundant\ 
-                                     \ instances"
+      splitted = mapM (\ grp -> partitionNonRedundant grp allNdx (nlf,ilf))
+                 smallestColoring
+  rebootGroups <- if optIgnoreNonRedundant opts
+                     then return smallestColoring
+                     else case splitted of
+                            Ok splitgroups -> return $ concat splitgroups
+                            Bad _ -> exitErr "Not enough capacity to move\ 
+                                             \ non-redundant instances"
   let idToNode = (`Container.find` nodes)
       nodesRebootGroups =
         map (map idToNode . filter (`IntMap.member` nodes)) rebootGroups