htools: read the disk template in Luxi and Rapi
[ganeti-local] / htools / Ganeti / HTools / CLI.hs
index 213de9b..dd0d392 100644 (file)
@@ -1,8 +1,8 @@
 {-| Implementation of command-line functions.
 
 {-| Implementation of command-line functions.
 
-This module holds the common cli-related functions for the binaries,
-separated into this module since Utils.hs is used in many other places
-and this is more IO oriented.
+This module holds the common command-line related functions for the
+binaries, separated into this module since "Ganeti.HTools.Utils" is
+used in many other places and this is more IO oriented.
 
 -}
 
 
 -}
 
@@ -38,6 +38,7 @@ module Ganeti.HTools.CLI
     -- * The options
     , oDataFile
     , oDiskMoves
     -- * The options
     , oDataFile
     , oDiskMoves
+    , oSelInst
     , oInstMoves
     , oDynuFile
     , oEvacMode
     , oInstMoves
     , oDynuFile
     , oEvacMode
@@ -66,6 +67,7 @@ module Ganeti.HTools.CLI
     , oPrintNodes
     , oQuiet
     , oRapiMaster
     , oPrintNodes
     , oQuiet
     , oRapiMaster
+    , oReplay
     , oSaveCluster
     , oShowHelp
     , oShowVer
     , oSaveCluster
     , oShowHelp
     , oShowVer
@@ -73,9 +75,9 @@ module Ganeti.HTools.CLI
     , oVerbose
     ) where
 
     , oVerbose
     ) where
 
+import Control.Monad
 import Data.Maybe (fromMaybe)
 import qualified Data.Version
 import Data.Maybe (fromMaybe)
 import qualified Data.Version
-import Monad
 import System.Console.GetOpt
 import System.IO
 import System.Info
 import System.Console.GetOpt
 import System.IO
 import System.Info
@@ -87,10 +89,16 @@ import qualified Ganeti.Constants as C
 import Ganeti.HTools.Types
 import Ganeti.HTools.Utils
 
 import Ganeti.HTools.Types
 import Ganeti.HTools.Utils
 
--- | The default value for the luxi socket
+-- * Constants
+
+-- | The default value for the luxi socket.
+--
+-- This is re-exported from the "Ganeti.Constants" module.
 defaultLuxiSocket :: FilePath
 defaultLuxiSocket = C.masterSocket
 
 defaultLuxiSocket :: FilePath
 defaultLuxiSocket = C.masterSocket
 
+-- * Data types
+
 -- | Command line options structure.
 data Options = Options
     { optDataFile    :: Maybe FilePath -- ^ Path to the cluster data file
 -- | Command line options structure.
 data Options = Options
     { optDataFile    :: Maybe FilePath -- ^ Path to the cluster data file
@@ -102,6 +110,7 @@ data Options = Options
     , optExTags      :: Maybe [String] -- ^ Tags to use for exclusion
     , optExecJobs    :: Bool           -- ^ Execute the commands via Luxi
     , optGroup       :: Maybe GroupID  -- ^ The UUID of the group to process
     , optExTags      :: Maybe [String] -- ^ Tags to use for exclusion
     , optExecJobs    :: Bool           -- ^ Execute the commands via Luxi
     , optGroup       :: Maybe GroupID  -- ^ The UUID of the group to process
+    , optSelInst     :: [String]       -- ^ Instances to be excluded
     , optINodes      :: Int            -- ^ Nodes required for an instance
     , optISpec       :: RSpec          -- ^ Requested instance specs
     , optLuxi        :: Maybe FilePath -- ^ Collect data from Luxi
     , optINodes      :: Int            -- ^ Nodes required for an instance
     , optISpec       :: RSpec          -- ^ Requested instance specs
     , optLuxi        :: Maybe FilePath -- ^ Collect data from Luxi
@@ -124,6 +133,7 @@ data Options = Options
     , optShowNodes   :: Maybe [String] -- ^ Whether to show node status
     , optShowVer     :: Bool           -- ^ Just show the program version
     , optTieredSpec  :: Maybe RSpec    -- ^ Requested specs for tiered mode
     , optShowNodes   :: Maybe [String] -- ^ Whether to show node status
     , optShowVer     :: Bool           -- ^ Just show the program version
     , optTieredSpec  :: Maybe RSpec    -- ^ Requested specs for tiered mode
+    , optReplay      :: Maybe String   -- ^ Unittests: RNG state
     , optVerbose     :: Int            -- ^ Verbosity level
     } deriving Show
 
     , optVerbose     :: Int            -- ^ Verbosity level
     } deriving Show
 
@@ -139,6 +149,7 @@ defaultOptions  = Options
  , optExTags      = Nothing
  , optExecJobs    = False
  , optGroup       = Nothing
  , optExTags      = Nothing
  , optExecJobs    = False
  , optGroup       = Nothing
+ , optSelInst     = []
  , optINodes      = 2
  , optISpec       = RSpec 1 4096 102400
  , optLuxi        = Nothing
  , optINodes      = 2
  , optISpec       = RSpec 1 4096 102400
  , optLuxi        = Nothing
@@ -161,12 +172,15 @@ defaultOptions  = Options
  , optShowNodes   = Nothing
  , optShowVer     = False
  , optTieredSpec  = Nothing
  , optShowNodes   = Nothing
  , optShowVer     = False
  , optTieredSpec  = Nothing
+ , optReplay      = Nothing
  , optVerbose     = 1
  }
 
  , optVerbose     = 1
  }
 
--- | Abrreviation for the option type
+-- | Abrreviation for the option type.
 type OptType = OptDescr (Options -> Result Options)
 
 type OptType = OptDescr (Options -> Result Options)
 
+-- * Command line options
+
 oDataFile :: OptType
 oDataFile = Option "t" ["text-data"]
             (ReqArg (\ f o -> Ok o { optDataFile = Just f }) "FILE")
 oDataFile :: OptType
 oDataFile = Option "t" ["text-data"]
             (ReqArg (\ f o -> Ok o { optDataFile = Just f }) "FILE")
@@ -178,6 +192,11 @@ oDiskMoves = Option "" ["no-disk-moves"]
              "disallow disk moves from the list of allowed instance changes,\
              \ thus allowing only the 'cheap' failover/migrate operations"
 
              "disallow disk moves from the list of allowed instance changes,\
              \ thus allowing only the 'cheap' failover/migrate operations"
 
+oSelInst :: OptType
+oSelInst = Option "" ["select-instances"]
+          (ReqArg (\ f opts -> Ok opts { optSelInst = sepSplit ',' f }) "INSTS")
+          "only select given instances for any moves"
+
 oInstMoves :: OptType
 oInstMoves = Option "" ["no-instance-moves"]
              (NoArg (\ opts -> Ok opts { optInstMoves = False}))
 oInstMoves :: OptType
 oInstMoves = Option "" ["no-instance-moves"]
              (NoArg (\ opts -> Ok opts { optInstMoves = False}))
@@ -373,18 +392,25 @@ oTieredSpec = Option "" ["tiered-alloc"]
               "TSPEC")
              "enable tiered specs allocation, given as 'disk,ram,cpu'"
 
               "TSPEC")
              "enable tiered specs allocation, given as 'disk,ram,cpu'"
 
+oReplay :: OptType
+oReplay = Option "" ["replay"]
+          (ReqArg (\ stat opts -> Ok opts { optReplay = Just stat } ) "STATE")
+          "Pre-seed the random number generator with STATE"
+
 oVerbose :: OptType
 oVerbose = Option "v" ["verbose"]
            (NoArg (\ opts -> Ok opts { optVerbose = optVerbose opts + 1 }))
            "increase the verbosity level"
 
 oVerbose :: OptType
 oVerbose = Option "v" ["verbose"]
            (NoArg (\ opts -> Ok opts { optVerbose = optVerbose opts + 1 }))
            "increase the verbosity level"
 
--- | Usage info
+-- * Functions
+
+-- | Usage info.
 usageHelp :: String -> [OptType] -> String
 usageHelp progname =
     usageInfo (printf "%s %s\nUsage: %s [OPTION...]"
                progname Version.version progname)
 
 usageHelp :: String -> [OptType] -> String
 usageHelp progname =
     usageInfo (printf "%s %s\nUsage: %s [OPTION...]"
                progname Version.version progname)
 
--- | Command line parser, using the 'options' structure.
+-- | Command line parser, using the 'Options' structure.
 parseOpts :: [String]               -- ^ The command line arguments
           -> String                 -- ^ The program name
           -> [OptType]              -- ^ The supported command line options
 parseOpts :: [String]               -- ^ The command line arguments
           -> String                 -- ^ The program name
           -> [OptType]              -- ^ The supported command line options