Switch the text file format to single-file
[ganeti-local] / Ganeti / HTools / CLI.hs
index 8dad35d..cfffee3 100644 (file)
@@ -39,8 +39,7 @@ module Ganeti.HTools.CLI
     , oOneline
     , oNoHeaders
     , oOutputDir
-    , oNodeFile
-    , oInstFile
+    , oDataFile
     , oNodeSim
     , oRapiMaster
     , oLuxiSocket
@@ -59,6 +58,7 @@ module Ganeti.HTools.CLI
     , oDiskMoves
     , oDynuFile
     , oTieredSpec
+    , oExTags
     , oShowVer
     , oShowHelp
     ) where
@@ -82,16 +82,13 @@ defaultLuxiSocket = "/var/run/ganeti/socket/ganeti-master"
 
 -- | Command line options structure.
 data Options = Options
-    { optShowNodes   :: Bool           -- ^ Whether to show node status
+    { optShowNodes   :: Maybe [String] -- ^ Whether to show node status
     , optShowInsts   :: Bool           -- ^ Whether to show the instance map
     , optShowCmds    :: Maybe FilePath -- ^ Whether to show the command list
     , optOneline     :: Bool           -- ^ Switch output to a single line
     , optOutPath     :: FilePath       -- ^ Path to the output directory
     , optNoHeaders   :: Bool           -- ^ Do not show a header line
-    , optNodeFile    :: FilePath       -- ^ Path to the nodes file
-    , optNodeSet     :: Bool           -- ^ The nodes have been set by options
-    , optInstFile    :: FilePath       -- ^ Path to the instances file
-    , optInstSet     :: Bool           -- ^ The insts have been set by options
+    , optDataFile    :: Maybe FilePath -- ^ Path to the cluster data file
     , optNodeSim     :: Maybe String   -- ^ Cluster simulation mode
     , optMaxLength   :: Int            -- ^ Stop after this many steps
     , optMaster      :: String         -- ^ Collect data from RAPI
@@ -106,6 +103,7 @@ data Options = Options
     , optMdsk        :: Double         -- ^ Max disk usage ratio for nodes
     , optDiskMoves   :: Bool           -- ^ Allow disk moves
     , optDynuFile    :: Maybe FilePath -- ^ Optional file with dynamic use data
+    , optExTags      :: Maybe [String] -- ^ Tags to use for exclusion
     , optVerbose     :: Int            -- ^ Verbosity level
     , optShowVer     :: Bool           -- ^ Just show the program version
     , optShowHelp    :: Bool           -- ^ Just show the help
@@ -114,16 +112,13 @@ data Options = Options
 -- | Default values for the command line options.
 defaultOptions :: Options
 defaultOptions  = Options
- { optShowNodes   = False
+ { optShowNodes   = Nothing
  , optShowInsts   = False
  , optShowCmds    = Nothing
  , optOneline     = False
  , optNoHeaders   = False
  , optOutPath     = "."
- , optNodeFile    = "nodes"
- , optNodeSet     = False
- , optInstFile    = "instances"
- , optInstSet     = False
+ , optDataFile    = Nothing
  , optNodeSim     = Nothing
  , optMaxLength   = -1
  , optMaster      = ""
@@ -138,6 +133,7 @@ defaultOptions  = Options
  , optMdsk        = -1
  , optDiskMoves   = True
  , optDynuFile    = Nothing
+ , optExTags      = Nothing
  , optVerbose     = 1
  , optShowVer     = False
  , optShowHelp    = False
@@ -148,7 +144,10 @@ type OptType = OptDescr (Options -> Result Options)
 
 oPrintNodes :: OptType
 oPrintNodes = Option "p" ["print-nodes"]
-              (NoArg (\ opts -> Ok opts { optShowNodes = True }))
+              (OptArg ((\ f opts ->
+                            let splitted = sepSplit ',' f
+                            in Ok opts { optShowNodes = Just splitted }) .
+                       fromMaybe []) "FIELDS")
               "print the final node list"
 
 oPrintInsts :: OptType
@@ -180,22 +179,15 @@ oOutputDir = Option "d" ["output-dir"]
              (ReqArg (\ d opts -> Ok opts { optOutPath = d }) "PATH")
              "directory in which to write output files"
 
-oNodeFile :: OptType
-oNodeFile = Option "n" ["nodes"]
-            (ReqArg (\ f o -> Ok o { optNodeFile = f,
-                                     optNodeSet = True }) "FILE")
-            "the node list FILE"
-
-oInstFile :: OptType
-oInstFile = Option "i" ["instances"]
-            (ReqArg (\ f o -> Ok o { optInstFile = f,
-                                     optInstSet = True }) "FILE")
-            "the instance list FILE"
+oDataFile :: OptType
+oDataFile = Option "t" ["text-data"]
+            (ReqArg (\ f o -> Ok o { optDataFile = Just f }) "FILE")
+            "the cluster data FILE"
 
 oNodeSim :: OptType
 oNodeSim = Option "" ["simulate"]
             (ReqArg (\ f o -> Ok o { optNodeSim = Just f }) "SPEC")
-            "simulate an empty cluster, given as 'num_nodes,disk,memory,cpus'"
+            "simulate an empty cluster, given as 'num_nodes,disk,ram,cpu'"
 
 oRapiMaster :: OptType
 oRapiMaster = Option "m" ["master"]
@@ -290,6 +282,11 @@ oDynuFile = Option "U" ["dynu-file"]
             (ReqArg (\ f opts -> Ok opts { optDynuFile = Just f }) "FILE")
             "Import dynamic utilisation data from the given FILE"
 
+oExTags :: OptType
+oExTags = Option "" ["exclusion-tags"]
+            (ReqArg (\ f opts -> Ok opts { optExTags = Just $ sepSplit ',' f })
+             "TAG,...") "Enable instance exclusion based on given tag prefix"
+
 oTieredSpec :: OptType
 oTieredSpec = Option "" ["tiered-alloc"]
              (ReqArg (\ inp opts -> do
@@ -297,12 +294,11 @@ oTieredSpec = Option "" ["tiered-alloc"]
                           prs <- mapM (tryRead "tiered specs") sp
                           tspec <-
                               case prs of
-                                [cpu, ram, dsk] -> return $ RSpec cpu ram dsk
+                                [dsk, ram, cpu] -> return $ RSpec cpu ram dsk
                                 _ -> Bad $ "Invalid specification: " ++ inp
                           return $ opts { optTieredSpec = Just tspec } )
               "TSPEC")
-             "enable tiered specs allocation, where we decrease the instance\
-             \ spec on failure to allocate and restart the allocation process"
+             "enable tiered specs allocation, given as 'disk,ram,cpu'"
 
 oShowVer :: OptType
 oShowVer = Option "V" ["version"]