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
45 import System.Console.GetOpt
47 import Ganeti.BasicTypes
48 import Ganeti.Common as Common
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
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
69 -- | Default values for the command line options.
70 defaultOptions :: Options
71 defaultOptions = Options
75 , optDrbdStatus = Nothing
76 , optDrbdPairing = Nothing
78 , optConfdAddr = Nothing
79 , optConfdPort = Nothing
82 -- | Abbreviation for the option type.
83 type OptType = GenericOptType Options
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 }
93 -- * Command line options
94 oDrbdPairing :: OptType
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",
101 oDrbdStatus :: OptType
103 ( Option "s" ["drbd-status"]
104 (ReqArg (\ f o -> Ok o { optDrbdStatus = Just f }) "FILE")
105 "the DRBD status FILE",
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",
115 oConfdAddr :: OptType
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",
122 oConfdPort :: OptType
125 (reqWithConversion (tryRead "reading port")
126 (\port opts -> Ok opts { optConfdPort = Just port }) "PORT")
127 "Network port of the Confd server to connect to",
130 -- | Generic options.
131 genericOptions :: [GenericOptType Options]
132 genericOptions = [ oShowVer