import qualified Ganeti.HTools.Container as Container
import qualified Ganeti.HTools.Cluster as Cluster
-import qualified Ganeti.HTools.Version as Version
import qualified Ganeti.HTools.Node as Node
import qualified Ganeti.HTools.Instance as Instance
+import qualified Ganeti.HTools.CLI as CLI
import Ganeti.HTools.Rapi
import Ganeti.HTools.Utils
{ optShowNodes :: Bool -- ^ Whether to show node status
, optOutPath :: FilePath -- ^ Path to the output directory
, optVerbose :: Int -- ^ Verbosity level
- , optShowVer :: Bool -- ^ Just show the program version
, optNoHeader :: Bool -- ^ Do not show a header line
+ , optShowVer :: Bool -- ^ Just show the program version
+ , optShowHelp :: Bool -- ^ Just show the help
} deriving Show
-- | Default values for the command line options.
{ optShowNodes = False
, optOutPath = "."
, optVerbose = 0
- , optShowVer = False
, optNoHeader = False
+ , optShowVer = False
+ , optShowHelp = False
}
-- | Options list and functions
, Option ['v'] ["verbose"]
(NoArg (\ opts -> opts { optVerbose = (optVerbose opts) + 1 }))
"increase the verbosity level"
- , Option ['V'] ["version"]
- (NoArg (\ opts -> opts { optShowVer = True}))
- "show the version of the program"
, Option [] ["no-headers"]
(NoArg (\ opts -> opts { optNoHeader = True }))
"do not show a header line"
+ , Option ['V'] ["version"]
+ (NoArg (\ opts -> opts { optShowVer = True}))
+ "show the version of the program"
+ , Option ['h'] ["help"]
+ (NoArg (\ opts -> opts { optShowHelp = True}))
+ "show help"
]
--- | Command line parser, using the 'options' structure.
-parseOpts :: [String] -> IO (Options, [String])
-parseOpts argv =
- case getOpt Permute options argv of
- (o, n, []) ->
- return (foldl (flip id) defaultOptions o, n)
- (_, _, errs) ->
- ioError (userError (concat errs ++ usageInfo header options))
- where header = printf "hscan %s\nUsage: hscan [OPTION...] cluster..."
- Version.version
-
-- | Generate node file data from node objects
serializeNodes :: Cluster.NodeList -> String -> Cluster.NameList -> String
serializeNodes nl csf ktn =
t_mem = (truncate $ Node.t_mem node)::Int
t_dsk = (truncate $ Node.t_dsk node)::Int
in
- printf "%s|%d|%d|%d|%d|%d" name
+ printf "%s|%d|%d|%d|%d|%d|%c" name
t_mem (Node.n_mem node) (Node.f_mem node)
- t_dsk (Node.f_dsk node))
+ t_dsk (Node.f_dsk node)
+ (if Node.offline node then 'Y' else 'N')
+ )
nodes
in unlines nlines
pnode = fromJust $ lookup (Instance.pnode inst) etn
snode = fromJust $ lookup (Instance.snode inst) etn
in
- printf "%s|%d|%d|%s|%s"
+ printf "%s|%d|%d|%s|%s|%s"
iname (Instance.mem inst) (Instance.dsk inst)
+ (Instance.run_st inst)
pnode snode
)
instances
main :: IO ()
main = do
cmd_args <- System.getArgs
- (opts, clusters) <- parseOpts cmd_args
+ (opts, clusters) <- CLI.parseOpts cmd_args "hscan" options
+ defaultOptions optShowHelp
when (optShowVer opts) $ do
- putStr $ showVersion "hscan"
+ putStr $ CLI.showVersion "hscan"
exitWith ExitSuccess
let odir = optOutPath opts
hFlush stdout
node_data <- getNodes name
inst_data <- getInstances name
- (if isLeft(node_data)
- then putStrLn $ fromLeft node_data
- else if isLeft(inst_data)
- then putStrLn $ fromLeft inst_data
- else do
- let ndata = fromRight node_data
- idata = fromRight inst_data
- (nl, il, csf, ktn, kti) =
- Cluster.loadData ndata idata
- putStrLn $ printCluster nl il ktn kti
- when (optShowNodes opts) $
- putStr $ Cluster.printNodes ktn nl
- let ndata = serializeNodes nl csf ktn
- idata = serializeInstances il csf ktn kti
- oname = odir </> name
- writeFile (oname <.> "nodes") ndata
- writeFile (oname <.> "instances") idata)
+ (case node_data of
+ Bad err -> putStrLn err
+ Ok ndata ->
+ case inst_data of
+ Bad err -> putStrLn err
+ Ok idata ->
+ do
+ let (nl, il, csf, ktn, kti) =
+ Cluster.loadData ndata idata
+ (_, fix_nl) = Cluster.checkData nl il ktn kti
+ putStrLn $ printCluster fix_nl il ktn kti
+ when (optShowNodes opts) $ do
+ putStr $ Cluster.printNodes ktn fix_nl
+ let ndata = serializeNodes nl csf ktn
+ idata = serializeInstances il csf ktn kti
+ oname = odir </> name
+ writeFile (oname <.> "nodes") ndata
+ writeFile (oname <.> "instances") idata)
) clusters
exitWith ExitSuccess