LGTM, thanks.

On Thu, Nov 14, 2013 at 11:06 PM, Klaus Aehlig <[email protected]> wrote:

> Move the function that saves a list of a command in a file
> to CLI.hs. In this way, it is reusable by other htools.
>
> Signed-off-by: Klaus Aehlig <[email protected]>
> ---
>  src/Ganeti/HTools/CLI.hs          | 17 +++++++++++++++++
>  src/Ganeti/HTools/Program/Hbal.hs | 20 +++-----------------
>  2 files changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/src/Ganeti/HTools/CLI.hs b/src/Ganeti/HTools/CLI.hs
> index 7c06f57..515c023 100644
> --- a/src/Ganeti/HTools/CLI.hs
> +++ b/src/Ganeti/HTools/CLI.hs
> @@ -36,6 +36,7 @@ module Ganeti.HTools.CLI
>    , parseYesNo
>    , parseISpecString
>    , shTemplate
> +  , maybeSaveCommands
>    , maybePrintNodes
>    , maybePrintInsts
>    , maybeShowWarnings
> @@ -720,6 +721,22 @@ shTemplate =
>           \  fi\n\
>           \}\n\n"
>
> +-- | Optionally show or save a list of commands
> +maybeSaveCommands :: String -- ^ Informal description
> +                  -> Options
> +                  -> String -- ^ commands
> +                  -> IO ()
> +maybeSaveCommands msg opts cmds =
> +  case optShowCmds opts of
> +    Nothing -> return ()
> +    Just "-" -> do
> +      putStrLn ""
> +      putStrLn msg
> +      putStr . unlines .  map ("  " ++) . filter (/= "  check") . lines $
> cmds
> +    Just out_path -> do
> +      writeFile out_path (shTemplate ++ cmds)
> +      printf "The commands have been written to file '%s'\n" out_path
> +
>  -- | Optionally print the node list.
>  maybePrintNodes :: Maybe [String]       -- ^ The field list
>                  -> String               -- ^ Informational message
> diff --git a/src/Ganeti/HTools/Program/Hbal.hs
> b/src/Ganeti/HTools/Program/Hbal.hs
> index 3fdc30a..73fc6b4 100644
> --- a/src/Ganeti/HTools/Program/Hbal.hs
> +++ b/src/Ganeti/HTools/Program/Hbal.hs
> @@ -33,7 +33,7 @@ module Ganeti.HTools.Program.Hbal
>  import Control.Exception (bracket)
>  import Control.Monad
>  import Data.List
> -import Data.Maybe (isJust, isNothing, fromJust)
> +import Data.Maybe (isNothing)
>  import Data.IORef
>  import System.Exit
>  import System.IO
> @@ -168,20 +168,6 @@ printStats ini_nl fin_nl = do
>    printf "Final:    mem=%d disk=%d\n"
>               (Cluster.csFmem fin_cs) (Cluster.csFdsk fin_cs)
>
> --- | Saves the rebalance commands to a text file.
> -saveBalanceCommands :: Options -> String -> IO ()
> -saveBalanceCommands opts cmd_data = do
> -  let out_path = fromJust $ optShowCmds opts
> -  putStrLn ""
> -  if out_path == "-"
> -    then printf "Commands to run to reach the above solution:\n%s"
> -           (unlines . map ("  " ++) .
> -            filter (/= "  check") .
> -            lines $ cmd_data)
> -    else do
> -      writeFile out_path (shTemplate ++ cmd_data)
> -      printf "The commands have been written to file '%s'\n" out_path
> -
>  -- | Wrapper over execJobSet checking for early termination via an IORef.
>  execCancelWrapper :: Annotator -> String -> Node.List
>                    -> Instance.List -> IORef Int -> [JobSet] -> IO (Result
> ())
> @@ -409,8 +395,8 @@ main opts args = do
>
>    let cmd_jobs = Cluster.splitJobs cmd_strs
>
> -  when (isJust $ optShowCmds opts) .
> -       saveBalanceCommands opts $ Cluster.formatCmds cmd_jobs
> +  maybeSaveCommands "Commands to run to reach the above solution:" opts
> +    $ Cluster.formatCmds cmd_jobs
>
>    maybeSaveData (optSaveCluster opts) "balanced" "after balancing"
>                  ini_cdata { cdNodes = fin_nl, cdInstances = fin_il }
> --
> 1.8.4.1
>
>


Hrvoje Ribicic
Ganeti Engineering
Google Germany GmbH
Dienerstr. 12, 80331, München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores
Steuernummer: 48/725/00206
Umsatzsteueridentifikationsnummer: DE813741370

Reply via email to