Add Template Haskell 'declareLADT'
[ganeti-local] / src / Ganeti / HsConstants.hs
1 {-| HsConstants contains the Haskell constants
2
3 This is a transitional module complementary to 'Ganeti.Constants'.  It
4 is intended to contain the Haskell constants that are meant to be
5 generated in Python.
6
7 Do not write any definitions in this file other than constants.  Do
8 not even write helper functions.  The definitions in this module are
9 automatically stripped to build the Makefile.am target
10 'ListConstants.hs'.  If there are helper functions in this module,
11 they will also be dragged and it will cause compilation to fail.
12 Therefore, all helper functions should go to a separate module and
13 imported.
14
15 -}
16
17 {-
18
19 Copyright (C) 2013 Google Inc.
20
21 This program is free software; you can redistribute it and/or modify
22 it under the terms of the GNU General Public License as published by
23 the Free Software Foundation; either version 2 of the License, or
24 (at your option) any later version.
25
26 This program is distributed in the hope that it will be useful, but
27 WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
29 General Public License for more details.
30
31 You should have received a copy of the GNU General Public License
32 along with this program; if not, write to the Free Software
33 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34 02110-1301, USA.
35
36 -}
37 module Ganeti.HsConstants where
38
39 import Data.Map (Map)
40 import qualified Data.Map as Map (fromList)
41
42 import AutoConf
43 import Ganeti.ConstantUtils (FrozenSet, Protocol(..))
44 import qualified Ganeti.ConstantUtils as ConstantUtils (mkSet, exitFailure)
45 import Ganeti.Runtime (GanetiDaemon(..), MiscGroup(..), GanetiGroup(..),
46                        ExtraLogReason(..))
47 import qualified Ganeti.Runtime as Runtime
48
49 -- * Admin states
50
51 adminstDown :: String
52 adminstDown = "down"
53
54 adminstOffline :: String
55 adminstOffline = "offline"
56
57 adminstUp :: String
58 adminstUp = "up"
59
60 adminstAll :: FrozenSet String
61 adminstAll = ConstantUtils.mkSet [adminstDown, adminstOffline, adminstUp]
62
63 -- * User separation
64
65 daemonsGroup :: String
66 daemonsGroup = Runtime.daemonGroup (ExtraGroup DaemonsGroup)
67
68 adminGroup :: String
69 adminGroup = Runtime.daemonGroup (ExtraGroup AdminGroup)
70
71 masterdUser :: String
72 masterdUser = Runtime.daemonUser GanetiMasterd
73
74 masterdGroup :: String
75 masterdGroup = Runtime.daemonGroup (DaemonGroup GanetiMasterd)
76
77 rapiUser :: String
78 rapiUser = Runtime.daemonUser GanetiRapi
79
80 rapiGroup :: String
81 rapiGroup = Runtime.daemonGroup (DaemonGroup GanetiRapi)
82
83 confdUser :: String
84 confdUser = Runtime.daemonUser GanetiConfd
85
86 confdGroup :: String
87 confdGroup = Runtime.daemonGroup (DaemonGroup GanetiConfd)
88
89 luxidUser :: String
90 luxidUser = Runtime.daemonUser GanetiLuxid
91
92 luxidGroup :: String
93 luxidGroup = Runtime.daemonGroup (DaemonGroup GanetiLuxid)
94
95 nodedUser :: String
96 nodedUser = Runtime.daemonUser GanetiNoded
97
98 nodedGroup :: String
99 nodedGroup = Runtime.daemonGroup (DaemonGroup GanetiNoded)
100
101 mondUser :: String
102 mondUser = Runtime.daemonUser GanetiMond
103
104 mondGroup :: String
105 mondGroup = Runtime.daemonGroup (DaemonGroup GanetiMond)
106
107 sshLoginUser :: String
108 sshLoginUser = AutoConf.sshLoginUser
109
110 sshConsoleUser :: String
111 sshConsoleUser = AutoConf.sshConsoleUser
112
113 -- * SSH constants
114
115 ssh :: String
116 ssh = "ssh"
117
118 scp :: String
119 scp = "scp"
120
121 -- * Daemons
122
123 confd :: String
124 confd = Runtime.daemonName GanetiConfd
125
126 masterd :: String
127 masterd = Runtime.daemonName GanetiMasterd
128
129 mond :: String
130 mond = Runtime.daemonName GanetiMond
131
132 noded :: String
133 noded = Runtime.daemonName GanetiNoded
134
135 luxid :: String
136 luxid = Runtime.daemonName GanetiLuxid
137
138 rapi :: String
139 rapi = Runtime.daemonName GanetiRapi
140
141 daemons :: FrozenSet String
142 daemons =
143   ConstantUtils.mkSet [confd,
144                        luxid,
145                        masterd,
146                        mond,
147                        noded,
148                        rapi]
149
150 defaultConfdPort :: Int
151 defaultConfdPort = 1814
152
153 defaultMondPort :: Int
154 defaultMondPort = 1815
155
156 defaultNodedPort :: Int
157 defaultNodedPort = 1811
158
159 defaultRapiPort :: Int
160 defaultRapiPort = 5080
161
162 daemonsPorts :: Map String (Protocol, Int)
163 daemonsPorts =
164   Map.fromList [(confd, (Udp, defaultConfdPort)),
165                 (mond, (Tcp, defaultMondPort)),
166                 (noded, (Tcp, defaultNodedPort)),
167                 (rapi, (Tcp, defaultRapiPort)),
168                 (ssh, (Tcp, 22))]
169
170 daemonsLogbase :: Map String String
171 daemonsLogbase =
172   Map.fromList
173   [ (Runtime.daemonName d, Runtime.daemonLogBase d) | d <- [minBound..] ]
174
175 extraLogreasonAccess :: String
176 extraLogreasonAccess = Runtime.daemonsExtraLogbase GanetiMond AccessLog
177
178 extraLogreasonError :: String
179 extraLogreasonError = Runtime.daemonsExtraLogbase GanetiMond ErrorLog
180
181 -- * Common exit codes
182
183 exitSuccess :: Int
184 exitSuccess = 0
185
186 exitFailure :: Int
187 exitFailure = ConstantUtils.exitFailure
188
189 exitNotcluster :: Int
190 exitNotcluster = 5
191
192 exitNotmaster :: Int
193 exitNotmaster = 11
194
195 exitNodesetupError :: Int
196 exitNodesetupError = 12
197
198 -- | Need user confirmation
199 exitConfirmation :: Int
200 exitConfirmation = 13
201
202 -- | Exit code for query operations with unknown fields
203 exitUnknownField :: Int
204 exitUnknownField = 14
205
206 -- * Possible values for NodeGroup.alloc_policy
207
208 allocPolicyLastResort :: String
209 allocPolicyLastResort = "last_resort"
210
211 allocPolicyPreferred :: String
212 allocPolicyPreferred = "preferred"
213
214 allocPolicyUnallocable :: String
215 allocPolicyUnallocable = "unallocable"
216
217 validAllocPolicies :: [String]
218 validAllocPolicies =
219   [allocPolicyLastResort,
220    allocPolicyPreferred,
221    allocPolicyUnallocable]
222
223 -- | Temporary external/shared storage parameters
224 blockdevDriverManual :: String
225 blockdevDriverManual = "manual"
226
227 -- * Auto-repair tag prefixes
228
229 autoRepairTagPrefix :: String
230 autoRepairTagPrefix = "ganeti:watcher:autorepair:"
231
232 autoRepairTagEnabled :: String
233 autoRepairTagEnabled = autoRepairTagPrefix
234
235 autoRepairTagPending :: String
236 autoRepairTagPending = autoRepairTagPrefix ++ "pending:"
237
238 autoRepairTagResult :: String
239 autoRepairTagResult = autoRepairTagPrefix ++ "result:"
240
241 autoRepairTagSuspended :: String
242 autoRepairTagSuspended = autoRepairTagPrefix ++ "suspend:"
243
244 -- * Auto-repair levels
245
246 autoRepairFailover :: String
247 autoRepairFailover = "failover"
248
249 autoRepairFixStorage :: String
250 autoRepairFixStorage = "fix-storage"
251
252 autoRepairMigrate :: String
253 autoRepairMigrate = "migrate"
254
255 autoRepairReinstall :: String
256 autoRepairReinstall = "reinstall"
257
258 autoRepairAllTypes :: FrozenSet String
259 autoRepairAllTypes =
260   ConstantUtils.mkSet [autoRepairFailover,
261                        autoRepairFixStorage,
262                        autoRepairMigrate,
263                        autoRepairReinstall]
264
265 -- * Auto-repair results
266
267 autoRepairEnoperm :: String
268 autoRepairEnoperm = "enoperm"
269
270 autoRepairFailure :: String
271 autoRepairFailure = "failure"
272
273 autoRepairSuccess :: String
274 autoRepairSuccess = "success"
275
276 autoRepairAllResults :: FrozenSet String
277 autoRepairAllResults =
278   ConstantUtils.mkSet [autoRepairEnoperm, autoRepairFailure, autoRepairSuccess]
279
280 -- | The version identifier for builtin data collectors
281 builtinDataCollectorVersion :: String
282 builtinDataCollectorVersion = "B"