Allowing rebalance to run silently
authorAgata Murawska <agatamurawska@google.com>
Wed, 20 Jun 2012 15:00:57 +0000 (17:00 +0200)
committerAgata Murawska <agatamurawska@google.com>
Mon, 25 Jun 2012 08:55:24 +0000 (10:55 +0200)
Part of hcheck's simulation required us to silently run hbal. For that
purpose we expose iterateDepth and allow it to run silently.

Signed-off-by: Agata Murawska <agatamurawska@google.com>
Reviewed-by: RenĂ© Nussbaumer <rn@google.com>

htools/Ganeti/HTools/Program/Hbal.hs

index c6cb629..7f542a5 100644 (file)
@@ -23,7 +23,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
 -}
 
-module Ganeti.HTools.Program.Hbal (main, options) where
+module Ganeti.HTools.Program.Hbal
+    ( main
+    , options
+    , iterateDepth
+    ) where
 
 import Control.Concurrent (threadDelay)
 import Control.Exception (bracket)
@@ -90,7 +94,8 @@ options =
 we find a valid solution or we exceed the maximum depth.
 
 -}
-iterateDepth :: Cluster.Table    -- ^ The starting table
+iterateDepth :: Bool             -- ^ Whether to print moves
+             -> Cluster.Table    -- ^ The starting table
              -> Int              -- ^ Remaining length
              -> Bool             -- ^ Allow disk moves
              -> Bool             -- ^ Allow instance moves
@@ -103,7 +108,7 @@ iterateDepth :: Cluster.Table    -- ^ The starting table
              -> Bool             -- ^ Enable evacuation mode
              -> IO (Cluster.Table, [MoveJob]) -- ^ The resulting table
                                               -- and commands
-iterateDepth ini_tbl max_rounds disk_moves inst_moves nmlen imlen
+iterateDepth printmove ini_tbl max_rounds disk_moves inst_moves nmlen imlen
              cmd_strs min_score mg_limit min_gain evac_mode =
   let Cluster.Table ini_nl ini_il _ _ = ini_tbl
       allowed_next = Cluster.doNextBalance ini_tbl max_rounds min_score
@@ -121,9 +126,10 @@ iterateDepth ini_tbl max_rounds disk_moves inst_moves nmlen imlen
                                   nmlen imlen cur_plc fin_plc_len
                afn = Cluster.involvedNodes ini_il cur_plc
                upd_cmd_strs = (afn, idx, move, cmds):cmd_strs
-           putStrLn sol_line
-           hFlush stdout
-           iterateDepth fin_tbl max_rounds disk_moves inst_moves
+           when printmove $ do
+               putStrLn sol_line
+               hFlush stdout
+           iterateDepth printmove fin_tbl max_rounds disk_moves inst_moves
                         nmlen imlen upd_cmd_strs min_score
                         mg_limit min_gain evac_mode
        Nothing -> return (ini_tbl, cmd_strs)
@@ -382,7 +388,7 @@ main opts args = do
   let imlen = maximum . map (length . Instance.alias) $ Container.elems il
       nmlen = maximum . map (length . Node.alias) $ Container.elems nl
 
-  (fin_tbl, cmd_strs) <- iterateDepth ini_tbl (optMaxLength opts)
+  (fin_tbl, cmd_strs) <- iterateDepth True ini_tbl (optMaxLength opts)
                          (optDiskMoves opts)
                          (optInstMoves opts)
                          nmlen imlen [] min_cv