1 {-| Implementation of DataCollectors CLI functions.
3 This module holds the common command-line related functions for the
10 Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
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.
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.
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
29 module Ganeti.DataCollectors.CLI
47 import System.Console.GetOpt
49 import Ganeti.BasicTypes
50 import Ganeti.Common as Common
56 -- | Command line options structure.
57 data Options = Options
58 { optShowHelp :: Bool -- ^ Just show the help
59 , optShowComp :: Bool -- ^ Just show the completion info
60 , optShowVer :: Bool -- ^ Just show the program version
61 , optDrbdStatus :: Maybe FilePath -- ^ Path to the file containing DRBD
63 , optDrbdPairing :: Maybe FilePath -- ^ Path to the file containing pairings
64 -- between instances and DRBD minors
65 , optNode :: Maybe String -- ^ Info are requested for this node
66 , optConfdAddr :: Maybe String -- ^ IP address of the Confd server
67 , optConfdPort :: Maybe Int -- ^ The port of the Confd server to
69 , optInputFile :: Maybe FilePath -- ^ Path to the file containing the
70 -- information to be parsed
71 , optInstances :: Maybe FilePath -- ^ Path to the file contained a
72 -- serialized list of instances as in:
73 -- ([Primary], [Secondary])
76 -- | Default values for the command line options.
77 defaultOptions :: Options
78 defaultOptions = Options
82 , optDrbdStatus = Nothing
83 , optDrbdPairing = Nothing
85 , optConfdAddr = Nothing
86 , optConfdPort = Nothing
87 , optInputFile = Nothing
88 , optInstances = Nothing
91 -- | Abbreviation for the option type.
92 type OptType = GenericOptType Options
94 instance StandardOptions Options where
95 helpRequested = optShowHelp
96 verRequested = optShowVer
97 compRequested = optShowComp
98 requestHelp o = o { optShowHelp = True }
99 requestVer o = o { optShowVer = True }
100 requestComp o = o { optShowComp = True }
102 -- * Command line options
103 oDrbdPairing :: OptType
105 ( Option "p" ["drbd-pairing"]
106 (ReqArg (\ f o -> Ok o { optDrbdPairing = Just f}) "FILE")
107 "the FILE containing pairings between instances and DRBD minors",
110 oDrbdStatus :: OptType
112 ( Option "s" ["drbd-status"]
113 (ReqArg (\ f o -> Ok o { optDrbdStatus = Just f }) "FILE")
114 "the DRBD status FILE",
119 ( Option "n" ["node"]
120 (ReqArg (\ n o -> Ok o { optNode = Just n }) "NODE")
121 "the FQDN of the NODE about which information is requested",
124 oConfdAddr :: OptType
126 ( Option "a" ["address"]
127 (ReqArg (\ a o -> Ok o { optConfdAddr = Just a }) "IP_ADDR")
128 "the IP address of the Confd server to connect to",
131 oConfdPort :: OptType
134 (reqWithConversion (tryRead "reading port")
135 (\port opts -> Ok opts { optConfdPort = Just port }) "PORT")
136 "Network port of the Confd server to connect to",
139 oInputFile :: OptType
141 ( Option "f" ["file"]
142 (ReqArg (\ f o -> Ok o { optInputFile = Just f }) "FILE")
146 oInstances :: OptType
148 ( Option "i" ["instances"]
149 (ReqArg (\ f o -> Ok o { optInstances = Just f}) "FILE")
150 "the FILE containing serialized instances",
153 -- | Generic options.
154 genericOptions :: [GenericOptType Options]
155 genericOptions = [ oShowVer