Revision 8032b3b5
b/Ganeti/HTools/CLI.hs | ||
---|---|---|
9 | 9 |
module Ganeti.HTools.CLI |
10 | 10 |
( |
11 | 11 |
parseOpts |
12 |
, parseEnv |
|
12 | 13 |
, showVersion |
13 | 14 |
, shTemplate |
14 | 15 |
) where |
15 | 16 |
|
16 | 17 |
import System.Console.GetOpt |
18 |
import System.Posix.Env |
|
17 | 19 |
import System.IO |
18 | 20 |
import System.Info |
19 | 21 |
import System |
... | ... | |
46 | 48 |
where header = printf "%s %s\nUsage: %s [OPTION...]" |
47 | 49 |
progname Version.version progname |
48 | 50 |
|
51 |
-- | Parse the environment and return the node/instance names. |
|
52 |
-- This also hardcodes here the default node/instance file names. |
|
53 |
parseEnv :: () -> IO (String, String) |
|
54 |
parseEnv () = do |
|
55 |
a <- getEnvDefault "HTOOLS_NODES" "nodes" |
|
56 |
b <- getEnvDefault "HTOOLS_INSTANCES" "instances" |
|
57 |
return (a, b) |
|
49 | 58 |
|
50 | 59 |
-- | Return a version string for the program |
51 | 60 |
showVersion :: String -- ^ The program name |
b/hbal.hs | ||
---|---|---|
28 | 28 |
, optShowCmds :: Maybe FilePath -- ^ Whether to show the command list |
29 | 29 |
, optOneline :: Bool -- ^ Switch output to a single line |
30 | 30 |
, optNodef :: FilePath -- ^ Path to the nodes file |
31 |
, optNodeSet :: Bool -- ^ The nodes have been set by options |
|
31 | 32 |
, optInstf :: FilePath -- ^ Path to the instances file |
33 |
, optInstSet :: Bool -- ^ The insts have been set by options |
|
32 | 34 |
, optMaxLength :: Int -- ^ Stop after this many steps |
33 | 35 |
, optMaster :: String -- ^ Collect data from RAPI |
34 | 36 |
, optVerbose :: Int -- ^ Verbosity level |
... | ... | |
44 | 46 |
, optShowCmds = Nothing |
45 | 47 |
, optOneline = False |
46 | 48 |
, optNodef = "nodes" |
49 |
, optNodeSet = False |
|
47 | 50 |
, optInstf = "instances" |
51 |
, optInstSet = False |
|
48 | 52 |
, optMaxLength = -1 |
49 | 53 |
, optMaster = "" |
50 | 54 |
, optVerbose = 0 |
... | ... | |
69 | 73 |
(NoArg (\ opts -> opts { optOneline = True })) |
70 | 74 |
"print the ganeti command list for reaching the solution" |
71 | 75 |
, Option ['n'] ["nodes"] |
72 |
(ReqArg (\ f opts -> opts { optNodef = f }) "FILE") |
|
76 |
(ReqArg (\ f opts -> opts { optNodef = f, optNodeSet = True }) "FILE")
|
|
73 | 77 |
"the node list FILE" |
74 | 78 |
, Option ['i'] ["instances"] |
75 |
(ReqArg (\ f opts -> opts { optInstf = f }) "FILE") |
|
79 |
(ReqArg (\ f opts -> opts { optInstf = f, optInstSet = True }) "FILE")
|
|
76 | 80 |
"the instance list FILE" |
77 | 81 |
, Option ['m'] ["master"] |
78 | 82 |
(ReqArg (\ m opts -> opts { optMaster = m }) "ADDRESS") |
... | ... | |
152 | 156 |
putStr $ CLI.showVersion "hbal" |
153 | 157 |
exitWith ExitSuccess |
154 | 158 |
|
155 |
let oneline = optOneline opts |
|
159 |
(env_node, env_inst) <- CLI.parseEnv () |
|
160 |
let nodef = if optNodeSet opts then optNodef opts |
|
161 |
else env_node |
|
162 |
instf = if optInstSet opts then optInstf opts |
|
163 |
else env_inst |
|
164 |
oneline = optOneline opts |
|
156 | 165 |
verbose = optVerbose opts |
157 | 166 |
(node_data, inst_data) = |
158 | 167 |
case optMaster opts of |
159 |
"" -> (readFile $ optNodef opts,
|
|
160 |
readFile $ optInstf opts)
|
|
168 |
"" -> (readFile nodef,
|
|
169 |
readFile instf)
|
|
161 | 170 |
host -> (readData getNodes host, |
162 | 171 |
readData getInstances host) |
163 | 172 |
|
b/hn1.hs | ||
---|---|---|
26 | 26 |
{ optShowNodes :: Bool |
27 | 27 |
, optShowCmds :: Bool |
28 | 28 |
, optNodef :: FilePath |
29 |
, optInstf :: FilePath |
|
29 |
, optNodeSet :: Bool -- ^ The nodes have been set by options |
|
30 |
, optInstf :: FilePath -- ^ Path to the instances file |
|
31 |
, optInstSet :: Bool -- ^ The insts have been set by options |
|
30 | 32 |
, optMinDepth :: Int |
31 | 33 |
, optMaxRemovals :: Int |
32 | 34 |
, optMinDelta :: Int |
... | ... | |
42 | 44 |
{ optShowNodes = False |
43 | 45 |
, optShowCmds = False |
44 | 46 |
, optNodef = "nodes" |
47 |
, optNodeSet = False |
|
45 | 48 |
, optInstf = "instances" |
49 |
, optInstSet = False |
|
46 | 50 |
, optMinDepth = 1 |
47 | 51 |
, optMaxRemovals = -1 |
48 | 52 |
, optMinDelta = 0 |
49 | 53 |
, optMaxDelta = -1 |
50 |
, optMaster = "" |
|
51 |
, optShowVer = False |
|
52 |
, optShowHelp = False |
|
54 |
, optMaster = ""
|
|
55 |
, optShowVer = False
|
|
56 |
, optShowHelp = False
|
|
53 | 57 |
} |
54 | 58 |
|
55 | 59 |
{- | Start computing the solution at the given depth and recurse until |
... | ... | |
91 | 95 |
(NoArg (\ opts -> opts { optShowCmds = True })) |
92 | 96 |
"print the ganeti command list for reaching the solution" |
93 | 97 |
, Option ['n'] ["nodes"] |
94 |
(ReqArg (\ f opts -> opts { optNodef = f }) "FILE") |
|
98 |
(ReqArg (\ f opts -> opts { optNodef = f, optNodeSet = True }) "FILE")
|
|
95 | 99 |
"the node list FILE" |
96 | 100 |
, Option ['i'] ["instances"] |
97 |
(ReqArg (\ f opts -> opts { optInstf = f }) "FILE") |
|
101 |
(ReqArg (\ f opts -> opts { optInstf = f, optInstSet = True }) "FILE")
|
|
98 | 102 |
"the instance list FILE" |
99 | 103 |
, Option ['d'] ["depth"] |
100 | 104 |
(ReqArg (\ i opts -> opts { optMinDepth = (read i)::Int }) "D") |
... | ... | |
134 | 138 |
printf $ CLI.showVersion "hn1" |
135 | 139 |
exitWith ExitSuccess |
136 | 140 |
|
137 |
let min_depth = optMinDepth opts |
|
138 |
let (node_data, inst_data) = |
|
141 |
(env_node, env_inst) <- CLI.parseEnv () |
|
142 |
let nodef = if optNodeSet opts then optNodef opts |
|
143 |
else env_node |
|
144 |
instf = if optInstSet opts then optInstf opts |
|
145 |
else env_inst |
|
146 |
min_depth = optMinDepth opts |
|
147 |
(node_data, inst_data) = |
|
139 | 148 |
case optMaster opts of |
140 |
"" -> (readFile $ optNodef opts,
|
|
141 |
readFile $ optInstf opts)
|
|
149 |
"" -> (readFile nodef,
|
|
150 |
readFile instf)
|
|
142 | 151 |
host -> (readData getNodes host, |
143 | 152 |
readData getInstances host) |
144 | 153 |
|
Also available in: Unified diff