Experimental support for non-redundant instances
[ganeti-local] / Ganeti / HTools / CLI.hs
index ba16766..3d14b4d 100644 (file)
@@ -9,10 +9,13 @@ and this is more IO oriented.
 module Ganeti.HTools.CLI
     (
       parseOpts
 module Ganeti.HTools.CLI
     (
       parseOpts
+    , parseEnv
     , showVersion
     , showVersion
+    , shTemplate
     ) where
 
 import System.Console.GetOpt
     ) where
 
 import System.Console.GetOpt
+import System.Posix.Env
 import System.IO
 import System.Info
 import System
 import System.IO
 import System.Info
 import System
@@ -45,6 +48,13 @@ parseOpts argv progname options defaultOptions fn =
       where header = printf "%s %s\nUsage: %s [OPTION...]"
                      progname Version.version progname
 
       where header = printf "%s %s\nUsage: %s [OPTION...]"
                      progname Version.version progname
 
+-- | Parse the environment and return the node/instance names.
+-- This also hardcodes here the default node/instance file names.
+parseEnv :: () -> IO (String, String)
+parseEnv () = do
+  a <- getEnvDefault "HTOOLS_NODES" "nodes"
+  b <- getEnvDefault "HTOOLS_INSTANCES" "instances"
+  return (a, b)
 
 -- | Return a version string for the program
 showVersion :: String -- ^ The program name
 
 -- | Return a version string for the program
 showVersion :: String -- ^ The program name
@@ -54,3 +64,17 @@ showVersion name =
            name Version.version
            compilerName (Data.Version.showVersion compilerVersion)
            os arch
            name Version.version
            compilerName (Data.Version.showVersion compilerVersion)
            os arch
+
+-- | A shell script template for autogenerated scripts
+shTemplate :: String
+shTemplate =
+    printf "#!/bin/sh\n\n\
+           \# Auto-generated script for executing cluster rebalancing\n\n\
+           \# To stop, touch the file /tmp/stop-htools\n\n\
+           \set -e\n\n\
+           \check() {\n\
+           \  if [ -f /tmp/stop-htools ]; then\n\
+           \    echo 'Stop requested, exiting'\n\
+           \    exit 0\n\
+           \  fi\n\
+           \}\n\n"