Fix prefix bug in Haskell ssconf implementation
[ganeti-local] / htools / Ganeti / HTools / Program / Hbal.hs
index 689e8aa..c6cb629 100644 (file)
@@ -4,7 +4,7 @@
 
 {-
 
-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
 it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
 -}
 
-module Ganeti.HTools.Program.Hbal (main) where
+module Ganeti.HTools.Program.Hbal (main, options) where
 
 import Control.Concurrent (threadDelay)
 import Control.Exception (bracket)
@@ -31,7 +31,6 @@ import Control.Monad
 import Data.List
 import Data.Maybe (isJust, isNothing, fromJust)
 import Data.IORef
-import System.Environment (getArgs)
 import System.Exit
 import System.IO
 import System.Posix.Process
@@ -64,6 +63,7 @@ options =
   , oEvacMode
   , oRapiMaster
   , oLuxiSocket
+  , oIAllocSrc
   , oExecJobs
   , oGroup
   , oMaxSolLength
@@ -338,11 +338,8 @@ checkNeedRebalance opts ini_cv = do
          exitWith ExitSuccess
 
 -- | Main function.
-main :: IO ()
-main = do
-  cmd_args <- getArgs
-  (opts, args) <- parseOpts cmd_args "hbal" options
-
+main :: Options -> [String] -> IO ()
+main opts args = do
   unless (null args) $ do
          hPutStrLn stderr "Error: this program doesn't take any arguments."
          exitWith $ ExitFailure 1
@@ -377,8 +374,8 @@ main = do
   checkNeedRebalance opts ini_cv
 
   if verbose > 2
-    then printf "Initial coefficients: overall %.8f, %s\n"
-           ini_cv (Cluster.printStats nl)::IO ()
+    then printf "Initial coefficients: overall %.8f\n%s"
+           ini_cv (Cluster.printStats "  " nl)::IO ()
     else printf "Initial score: %.8f\n" ini_cv
 
   putStrLn "Trying to minimize the CV..."
@@ -396,8 +393,8 @@ main = do
       sol_msg = case () of
                   _ | null fin_plc -> printf "No solution found\n"
                     | verbose > 2 ->
-                        printf "Final coefficients:   overall %.8f, %s\n"
-                        fin_cv (Cluster.printStats fin_nl)
+                        printf "Final coefficients:   overall %.8f\n%s"
+                        fin_cv (Cluster.printStats "  " fin_nl)
                     | otherwise ->
                         printf "Cluster score improved from %.8f to %.8f\n"
                         ini_cv fin_cv ::String