Revision 7c3a6391 src/Ganeti/HTools/Program/Hbal.hs

b/src/Ganeti/HTools/Program/Hbal.hs
33 33
import Control.Exception (bracket)
34 34
import Control.Monad
35 35
import Data.List
36
import Data.Maybe (isJust, isNothing, fromJust)
36
import Data.Maybe (isNothing)
37 37
import Data.IORef
38 38
import System.Exit
39 39
import System.IO
......
168 168
  printf "Final:    mem=%d disk=%d\n"
169 169
             (Cluster.csFmem fin_cs) (Cluster.csFdsk fin_cs)
170 170

  
171
-- | Saves the rebalance commands to a text file.
172
saveBalanceCommands :: Options -> String -> IO ()
173
saveBalanceCommands opts cmd_data = do
174
  let out_path = fromJust $ optShowCmds opts
175
  putStrLn ""
176
  if out_path == "-"
177
    then printf "Commands to run to reach the above solution:\n%s"
178
           (unlines . map ("  " ++) .
179
            filter (/= "  check") .
180
            lines $ cmd_data)
181
    else do
182
      writeFile out_path (shTemplate ++ cmd_data)
183
      printf "The commands have been written to file '%s'\n" out_path
184

  
185 171
-- | Wrapper over execJobSet checking for early termination via an IORef.
186 172
execCancelWrapper :: Annotator -> String -> Node.List
187 173
                  -> Instance.List -> IORef Int -> [JobSet] -> IO (Result ())
......
409 395

  
410 396
  let cmd_jobs = Cluster.splitJobs cmd_strs
411 397

  
412
  when (isJust $ optShowCmds opts) .
413
       saveBalanceCommands opts $ Cluster.formatCmds cmd_jobs
398
  maybeSaveCommands "Commands to run to reach the above solution:" opts
399
    $ Cluster.formatCmds cmd_jobs
414 400

  
415 401
  maybeSaveData (optSaveCluster opts) "balanced" "after balancing"
416 402
                ini_cdata { cdNodes = fin_nl, cdInstances = fin_il }

Also available in: Unified diff