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