Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / DataCollectors / CLI.hs @ 67ebc173

History | View | Annotate | Download (4.3 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
  , oInputFile
43
  , genericOptions
44
  ) where
45

    
46
import System.Console.GetOpt
47

    
48
import Ganeti.BasicTypes
49
import Ganeti.Common as Common
50
import Ganeti.Utils
51

    
52

    
53
-- * Data types
54

    
55
-- | Command line options structure.
56
data Options = Options
57
  { optShowHelp    :: Bool           -- ^ Just show the help
58
  , optShowComp    :: Bool           -- ^ Just show the completion info
59
  , optShowVer     :: Bool           -- ^ Just show the program version
60
  , optDrbdStatus  :: Maybe FilePath -- ^ Path to the file containing DRBD
61
                                     -- status information
62
  , optDrbdPairing :: Maybe FilePath -- ^ Path to the file containing pairings
63
                                     -- between instances and DRBD minors
64
  , optNode        :: Maybe String   -- ^ Info are requested for this node
65
  , optConfdAddr   :: Maybe String   -- ^ IP address of the Confd server
66
  , optConfdPort   :: Maybe Int      -- ^ The port of the Confd server to
67
                                     -- connect to
68
  , optInputFile   :: Maybe FilePath -- ^ Path to the file containing the
69
                                     -- information to be parsed
70
  } deriving Show
71

    
72
-- | Default values for the command line options.
73
defaultOptions :: Options
74
defaultOptions  = Options
75
  { optShowHelp    = False
76
  , optShowComp    = False
77
  , optShowVer     = False
78
  , optDrbdStatus  = Nothing
79
  , optDrbdPairing = Nothing
80
  , optNode        = Nothing
81
  , optConfdAddr   = Nothing
82
  , optConfdPort   = Nothing
83
  , optInputFile   = Nothing
84
  }
85

    
86
-- | Abbreviation for the option type.
87
type OptType = GenericOptType Options
88

    
89
instance StandardOptions Options where
90
  helpRequested = optShowHelp
91
  verRequested  = optShowVer
92
  compRequested = optShowComp
93
  requestHelp o = o { optShowHelp = True }
94
  requestVer  o = o { optShowVer  = True }
95
  requestComp o = o { optShowComp = True }
96

    
97
-- * Command line options
98
oDrbdPairing :: OptType
99
oDrbdPairing =
100
  ( Option "p" ["drbd-pairing"]
101
      (ReqArg (\ f o -> Ok o { optDrbdPairing = Just f}) "FILE")
102
      "the FILE containing pairings between instances and DRBD minors",
103
    OptComplFile)
104

    
105
oDrbdStatus :: OptType
106
oDrbdStatus =
107
  ( Option "s" ["drbd-status"]
108
      (ReqArg (\ f o -> Ok o { optDrbdStatus = Just f }) "FILE")
109
      "the DRBD status FILE",
110
    OptComplFile)
111

    
112
oNode :: OptType
113
oNode =
114
  ( Option "n" ["node"]
115
      (ReqArg (\ n o -> Ok o { optNode = Just n }) "NODE")
116
      "the FQDN of the NODE about which information is requested",
117
    OptComplFile)
118

    
119
oConfdAddr :: OptType
120
oConfdAddr =
121
  ( Option "a" ["address"]
122
      (ReqArg (\ a o -> Ok o { optConfdAddr = Just a }) "IP_ADDR")
123
      "the IP address of the Confd server to connect to",
124
    OptComplFile)
125

    
126
oConfdPort :: OptType
127
oConfdPort =
128
  (Option "p" ["port"]
129
    (reqWithConversion (tryRead "reading port")
130
      (\port opts -> Ok opts { optConfdPort = Just port }) "PORT")
131
    "Network port of the Confd server to connect to",
132
    OptComplInteger)
133

    
134
oInputFile :: OptType
135
oInputFile =
136
  ( Option "f" ["file"]
137
      (ReqArg (\ f o -> Ok o { optInputFile = Just f }) "FILE")
138
      "the input FILE",
139
    OptComplFile)
140

    
141
-- | Generic options.
142
genericOptions :: [GenericOptType Options]
143
genericOptions =  [ oShowVer
144
                  , oShowHelp
145
                  , oShowComp
146
                  ]