root / src / Ganeti / DataCollectors / CLI.hs @ 7dc27988
History | View | Annotate | Download (3.9 kB)
1 |
{-| Implementation of DataCollectors CLI functions. |
---|---|
2 |
|
3 |
This module holds the common command-line related functions for the |
4 |
collector binaries. |
5 |
|
6 |
-} |
7 |
|
8 |
{- |
9 |
|
10 |
Copyright (C) 2009, 2010, 2011, 2012 Google Inc. |
11 |
|
12 |
This program is free software; you can redistribute it and/or modify |
13 |
it under the terms of the GNU General Public License as published by |
14 |
the Free Software Foundation; either version 2 of the License, or |
15 |
(at your option) any later version. |
16 |
|
17 |
This program is distributed in the hope that it will be useful, but |
18 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 |
General Public License for more details. |
21 |
|
22 |
You should have received a copy of the GNU General Public License |
23 |
along with this program; if not, write to the Free Software |
24 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
25 |
02110-1301, USA. |
26 |
|
27 |
-} |
28 |
|
29 |
module Ganeti.DataCollectors.CLI |
30 |
( Options(..) |
31 |
, OptType |
32 |
, defaultOptions |
33 |
-- * The options |
34 |
, oShowHelp |
35 |
, oShowVer |
36 |
, oShowComp |
37 |
, oDrbdPairing |
38 |
, oDrbdStatus |
39 |
, oNode |
40 |
, oConfdAddr |
41 |
, oConfdPort |
42 |
, genericOptions |
43 |
) where |
44 |
|
45 |
import System.Console.GetOpt |
46 |
|
47 |
import Ganeti.BasicTypes |
48 |
import Ganeti.Common as Common |
49 |
import Ganeti.Utils |
50 |
|
51 |
|
52 |
-- * Data types |
53 |
|
54 |
-- | Command line options structure. |
55 |
data Options = Options |
56 |
{ optShowHelp :: Bool -- ^ Just show the help |
57 |
, optShowComp :: Bool -- ^ Just show the completion info |
58 |
, optShowVer :: Bool -- ^ Just show the program version |
59 |
, optDrbdStatus :: Maybe FilePath -- ^ Path to the file containing DRBD |
60 |
-- status information |
61 |
, optDrbdPairing :: Maybe FilePath -- ^ Path to the file containing pairings |
62 |
-- between instances and DRBD minors |
63 |
, optNode :: Maybe String -- ^ Info are requested for this node |
64 |
, optConfdAddr :: Maybe String -- ^ IP address of the Confd server |
65 |
, optConfdPort :: Maybe Int -- ^ The port of the Confd server to |
66 |
-- connect to |
67 |
} deriving Show |
68 |
|
69 |
-- | Default values for the command line options. |
70 |
defaultOptions :: Options |
71 |
defaultOptions = Options |
72 |
{ optShowHelp = False |
73 |
, optShowComp = False |
74 |
, optShowVer = False |
75 |
, optDrbdStatus = Nothing |
76 |
, optDrbdPairing = Nothing |
77 |
, optNode = Nothing |
78 |
, optConfdAddr = Nothing |
79 |
, optConfdPort = Nothing |
80 |
} |
81 |
|
82 |
-- | Abbreviation for the option type. |
83 |
type OptType = GenericOptType Options |
84 |
|
85 |
instance StandardOptions Options where |
86 |
helpRequested = optShowHelp |
87 |
verRequested = optShowVer |
88 |
compRequested = optShowComp |
89 |
requestHelp o = o { optShowHelp = True } |
90 |
requestVer o = o { optShowVer = True } |
91 |
requestComp o = o { optShowComp = True } |
92 |
|
93 |
-- * Command line options |
94 |
oDrbdPairing :: OptType |
95 |
oDrbdPairing = |
96 |
( Option "p" ["drbd-pairing"] |
97 |
(ReqArg (\ f o -> Ok o { optDrbdPairing = Just f}) "FILE") |
98 |
"the FILE containing pairings between instances and DRBD minors", |
99 |
OptComplFile) |
100 |
|
101 |
oDrbdStatus :: OptType |
102 |
oDrbdStatus = |
103 |
( Option "s" ["drbd-status"] |
104 |
(ReqArg (\ f o -> Ok o { optDrbdStatus = Just f }) "FILE") |
105 |
"the DRBD status FILE", |
106 |
OptComplFile) |
107 |
|
108 |
oNode :: OptType |
109 |
oNode = |
110 |
( Option "n" ["node"] |
111 |
(ReqArg (\ n o -> Ok o { optNode = Just n }) "NODE") |
112 |
"the FQDN of the NODE about which information is requested", |
113 |
OptComplFile) |
114 |
|
115 |
oConfdAddr :: OptType |
116 |
oConfdAddr = |
117 |
( Option "a" ["address"] |
118 |
(ReqArg (\ a o -> Ok o { optConfdAddr = Just a }) "IP_ADDR") |
119 |
"the IP address of the Confd server to connect to", |
120 |
OptComplFile) |
121 |
|
122 |
oConfdPort :: OptType |
123 |
oConfdPort = |
124 |
(Option "p" ["port"] |
125 |
(reqWithConversion (tryRead "reading port") |
126 |
(\port opts -> Ok opts { optConfdPort = Just port }) "PORT") |
127 |
"Network port of the Confd server to connect to", |
128 |
OptComplInteger) |
129 |
|
130 |
-- | Generic options. |
131 |
genericOptions :: [GenericOptType Options] |
132 |
genericOptions = [ oShowVer |
133 |
, oShowHelp |
134 |
, oShowComp |
135 |
] |