Skip to content
Snippets Groups Projects
Commit 16c2369c authored by Iustin Pop's avatar Iustin Pop
Browse files

Switch the text file format to single-file

This patch changes from the two separate files to a single file, with
sections separated by a blank line. Currently only the node and instance
data is accepted, later the cluster tags will be read too via this
format.

This makes all the programs accept the new format, but hscan doesn't yet
generate it.
parent f5197d89
No related branches found
No related tags found
No related merge requests found
...@@ -39,8 +39,7 @@ module Ganeti.HTools.CLI ...@@ -39,8 +39,7 @@ module Ganeti.HTools.CLI
, oOneline , oOneline
, oNoHeaders , oNoHeaders
, oOutputDir , oOutputDir
, oNodeFile , oDataFile
, oInstFile
, oNodeSim , oNodeSim
, oRapiMaster , oRapiMaster
, oLuxiSocket , oLuxiSocket
...@@ -89,10 +88,7 @@ data Options = Options ...@@ -89,10 +88,7 @@ data Options = Options
, optOneline :: Bool -- ^ Switch output to a single line , optOneline :: Bool -- ^ Switch output to a single line
, optOutPath :: FilePath -- ^ Path to the output directory , optOutPath :: FilePath -- ^ Path to the output directory
, optNoHeaders :: Bool -- ^ Do not show a header line , optNoHeaders :: Bool -- ^ Do not show a header line
, optNodeFile :: FilePath -- ^ Path to the nodes file , optDataFile :: Maybe FilePath -- ^ Path to the cluster data 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
, optNodeSim :: Maybe String -- ^ Cluster simulation mode , optNodeSim :: Maybe String -- ^ Cluster simulation mode
, optMaxLength :: Int -- ^ Stop after this many steps , optMaxLength :: Int -- ^ Stop after this many steps
, optMaster :: String -- ^ Collect data from RAPI , optMaster :: String -- ^ Collect data from RAPI
...@@ -122,10 +118,7 @@ defaultOptions = Options ...@@ -122,10 +118,7 @@ defaultOptions = Options
, optOneline = False , optOneline = False
, optNoHeaders = False , optNoHeaders = False
, optOutPath = "." , optOutPath = "."
, optNodeFile = "nodes" , optDataFile = Nothing
, optNodeSet = False
, optInstFile = "instances"
, optInstSet = False
, optNodeSim = Nothing , optNodeSim = Nothing
, optMaxLength = -1 , optMaxLength = -1
, optMaster = "" , optMaster = ""
...@@ -186,17 +179,10 @@ oOutputDir = Option "d" ["output-dir"] ...@@ -186,17 +179,10 @@ oOutputDir = Option "d" ["output-dir"]
(ReqArg (\ d opts -> Ok opts { optOutPath = d }) "PATH") (ReqArg (\ d opts -> Ok opts { optOutPath = d }) "PATH")
"directory in which to write output files" "directory in which to write output files"
oNodeFile :: OptType oDataFile :: OptType
oNodeFile = Option "n" ["nodes"] oDataFile = Option "t" ["text-data"]
(ReqArg (\ f o -> Ok o { optNodeFile = f, (ReqArg (\ f o -> Ok o { optDataFile = Just f }) "FILE")
optNodeSet = True }) "FILE") "the cluster data 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"
oNodeSim :: OptType oNodeSim :: OptType
oNodeSim = Option "" ["simulate"] oNodeSim = Option "" ["simulate"]
......
...@@ -35,7 +35,6 @@ module Ganeti.HTools.ExtLoader ...@@ -35,7 +35,6 @@ module Ganeti.HTools.ExtLoader
import Data.Maybe (isJust, fromJust) import Data.Maybe (isJust, fromJust)
import Monad import Monad
import System.Posix.Env
import System.IO import System.IO
import System import System
import Text.Printf (printf, hPrintf) import Text.Printf (printf, hPrintf)
...@@ -54,15 +53,6 @@ import Ganeti.HTools.Types ...@@ -54,15 +53,6 @@ import Ganeti.HTools.Types
import Ganeti.HTools.CLI import Ganeti.HTools.CLI
import Ganeti.HTools.Utils (sepSplit, tryRead) import Ganeti.HTools.Utils (sepSplit, tryRead)
-- | 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)
-- | Error beautifier -- | Error beautifier
wrapIO :: IO (Result a) -> IO (Result a) wrapIO :: IO (Result a) -> IO (Result a)
wrapIO = flip catch (return . Bad . show) wrapIO = flip catch (return . Bad . show)
...@@ -85,19 +75,15 @@ parseUtilisation line = ...@@ -85,19 +75,15 @@ parseUtilisation line =
loadExternalData :: Options loadExternalData :: Options
-> IO (Node.List, Instance.List, [String], String) -> IO (Node.List, Instance.List, [String], String)
loadExternalData opts = do loadExternalData opts = do
(env_node, env_inst) <- parseEnv () let mhost = optMaster opts
let nodef = if optNodeSet opts then optNodeFile opts
else env_node
instf = if optInstSet opts then optInstFile opts
else env_inst
mhost = optMaster opts
lsock = optLuxi opts lsock = optLuxi opts
tfile = optDataFile opts
simdata = optNodeSim opts simdata = optNodeSim opts
setRapi = mhost /= "" setRapi = mhost /= ""
setLuxi = isJust lsock setLuxi = isJust lsock
setSim = isJust simdata setSim = isJust simdata
setFiles = optNodeSet opts || optInstSet opts setFile = isJust tfile
allSet = filter id [setRapi, setLuxi, setFiles] allSet = filter id [setRapi, setLuxi, setFile]
exTags = case optExTags opts of exTags = case optExTags opts of
Nothing -> [] Nothing -> []
Just etl -> map (++ ":") etl Just etl -> map (++ ":") etl
...@@ -128,7 +114,8 @@ loadExternalData opts = do ...@@ -128,7 +114,8 @@ loadExternalData opts = do
#endif #endif
| setLuxi -> wrapIO $ Luxi.loadData $ fromJust lsock | setLuxi -> wrapIO $ Luxi.loadData $ fromJust lsock
| setSim -> Simu.loadData $ fromJust simdata | setSim -> Simu.loadData $ fromJust simdata
| otherwise -> wrapIO $ Text.loadData nodef instf | setFile -> wrapIO $ Text.loadData $ fromJust tfile
| otherwise -> return $ Bad "No backend selected! Exiting."
let ldresult = input_data >>= Loader.mergeData util_data' exTags let ldresult = input_data >>= Loader.mergeData util_data' exTags
(loaded_nl, il, tags, csf) <- (loaded_nl, il, tags, csf) <-
......
...@@ -87,16 +87,19 @@ loadTabular lines_data convert_fn = do ...@@ -87,16 +87,19 @@ loadTabular lines_data convert_fn = do
kerows <- mapM convert_fn rows kerows <- mapM convert_fn rows
return $ assignIndices kerows return $ assignIndices kerows
-- | Builds the cluster data from node\/instance files. -- | Builds the cluster data from text input.
loadData :: String -- ^ Node data in string format loadData :: String -- ^ Path to the text file
-> String -- ^ Instance data in string format
-> IO (Result (Node.AssocList, Instance.AssocList, [String])) -> IO (Result (Node.AssocList, Instance.AssocList, [String]))
loadData nfile ifile = do -- IO monad loadData afile = do -- IO monad
ndata <- readFile nfile fdata <- readFile afile
idata <- readFile ifile let flines = lines fdata
(nlines, ilines) = break null flines
return $ do return $ do
ifixed <- case ilines of
[] -> Bad "Invalid format of the input file (no instance data)"
_:xs -> Ok xs
{- node file: name t_mem n_mem f_mem t_disk f_disk -} {- node file: name t_mem n_mem f_mem t_disk f_disk -}
(ktn, nl) <- loadTabular (lines ndata) loadNode (ktn, nl) <- loadTabular nlines loadNode
{- instance file: name mem disk status pnode snode -} {- instance file: name mem disk status pnode snode -}
(_, il) <- loadTabular (lines idata) (loadInst ktn) (_, il) <- loadTabular ifixed (loadInst ktn)
return (nl, il, []) return (nl, il, [])
...@@ -59,8 +59,7 @@ options = ...@@ -59,8 +59,7 @@ options =
, oPrintInsts , oPrintInsts
, oPrintCommands , oPrintCommands
, oOneline , oOneline
, oNodeFile , oDataFile
, oInstFile
, oRapiMaster , oRapiMaster
, oLuxiSocket , oLuxiSocket
, oExecJobs , oExecJobs
......
...@@ -50,8 +50,7 @@ import Ganeti.HTools.ExtLoader ...@@ -50,8 +50,7 @@ import Ganeti.HTools.ExtLoader
options :: [OptType] options :: [OptType]
options = options =
[ oPrintNodes [ oPrintNodes
, oNodeFile , oDataFile
, oInstFile
, oNodeSim , oNodeSim
, oRapiMaster , oRapiMaster
, oLuxiSocket , oLuxiSocket
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment