From f3d5316112e7ecd5a7c74d1bc8b29559fff0283f Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 1 Dec 2009 13:45:02 +0100 Subject: [PATCH] hail: add '-p' option intended for debugging use This prints the initial node list on stderr, since stdout is reserved for the iallocator protocol (even though ganeti won't pass -p itself). --- hail.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hail.hs b/hail.hs index 56143c0b1..dde30a0d9 100644 --- a/hail.hs +++ b/hail.hs @@ -27,6 +27,7 @@ module Main (main) where import Data.List import Data.Function +import Data.Maybe (isJust, fromJust) import Monad import System import System.IO @@ -44,7 +45,7 @@ import Ganeti.HTools.Loader (RqType(..), Request(..)) -- | Options list and functions options :: [OptType] -options = [oShowVer, oShowHelp] +options = [oPrintNodes, oShowVer, oShowHelp] processResults :: (Monad m) => Cluster.AllocSolution -> m (String, [Node.Node]) processResults (fstats, successes, sols) = @@ -71,13 +72,14 @@ processRequest request = main :: IO () main = do cmd_args <- System.getArgs - (_, args) <- parseOpts cmd_args "hail" options + (opts, args) <- parseOpts cmd_args "hail" options when (null args) $ do hPutStrLn stderr "Error: this program needs an input file." exitWith $ ExitFailure 1 let input_file = head args + shownodes = optShowNodes opts input_data <- readFile input_file request <- case (parseData input_data) of @@ -86,8 +88,13 @@ main = do exitWith $ ExitFailure 1 Ok rq -> return rq - let Request _ _ _ _ csf = request - sols = processRequest request >>= processResults + let Request _ nl _ _ csf = request + + when (isJust shownodes) $ do + hPutStrLn stderr "Initial cluster status:" + hPutStrLn stderr $ Cluster.printNodes nl (fromJust shownodes) + + let sols = processRequest request >>= processResults let (ok, info, rn) = case sols of Ok (ginfo, sn) -> (True, "Request successful: " ++ ginfo, -- GitLab