OpParams.hs 45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE TemplateHaskell #-}

{-| Implementation of opcodes parameters.

These are defined in a separate module only due to TemplateHaskell
stage restrictions - expressions defined in the current module can't
be passed to splices. So we have to either parameters/repeat each
parameter definition multiple times, or separate them into this
module.

-}

{-

Copyright (C) 2012 Google Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.

-}

module Ganeti.OpParams
Jose A. Lopes's avatar
Jose A. Lopes committed
35
  ( ReplaceDisksMode(..)
36
37
38
  , DiskIndex
  , mkDiskIndex
  , unDiskIndex
39
  , DiskAccess(..)
Iustin Pop's avatar
Iustin Pop committed
40
41
  , INicParams(..)
  , IDiskParams(..)
42
43
44
  , RecreateDisksInfo(..)
  , DdmOldChanges(..)
  , SetParamsMods(..)
Iustin Pop's avatar
Iustin Pop committed
45
  , ExportTarget(..)
46
  , pInstanceName
47
  , pInstanceUuid
Iustin Pop's avatar
Iustin Pop committed
48
49
  , pInstances
  , pName
50
51
  , pTagsList
  , pTagsObject
Jose A. Lopes's avatar
Jose A. Lopes committed
52
  , pTagsName
Iustin Pop's avatar
Iustin Pop committed
53
54
  , pOutputFields
  , pShutdownTimeout
Jose A. Lopes's avatar
Jose A. Lopes committed
55
  , pShutdownTimeout'
56
  , pShutdownInstance
Iustin Pop's avatar
Iustin Pop committed
57
58
59
  , pForce
  , pIgnoreOfflineNodes
  , pNodeName
Thomas Thrainer's avatar
Thomas Thrainer committed
60
  , pNodeUuid
Iustin Pop's avatar
Iustin Pop committed
61
  , pNodeNames
Thomas Thrainer's avatar
Thomas Thrainer committed
62
  , pNodeUuids
Iustin Pop's avatar
Iustin Pop committed
63
64
65
  , pGroupName
  , pMigrationMode
  , pMigrationLive
66
  , pMigrationCleanup
Iustin Pop's avatar
Iustin Pop committed
67
68
69
70
71
72
  , pForceVariant
  , pWaitForSync
  , pWaitForSyncFalse
  , pIgnoreConsistency
  , pStorageName
  , pUseLocking
73
  , pOpportunisticLocking
Iustin Pop's avatar
Iustin Pop committed
74
75
76
77
78
  , pNameCheck
  , pNodeGroupAllocPolicy
  , pGroupNodeParams
  , pQueryWhat
  , pEarlyRelease
79
80
  , pIpCheck
  , pIpConflictsCheck
Iustin Pop's avatar
Iustin Pop committed
81
82
  , pNoRemember
  , pMigrationTargetNode
Thomas Thrainer's avatar
Thomas Thrainer committed
83
  , pMigrationTargetNodeUuid
84
  , pMoveTargetNode
Thomas Thrainer's avatar
Thomas Thrainer committed
85
  , pMoveTargetNodeUuid
Iustin Pop's avatar
Iustin Pop committed
86
87
88
89
90
91
92
93
94
95
96
97
  , pStartupPaused
  , pVerbose
  , pDebugSimulateErrors
  , pErrorCodes
  , pSkipChecks
  , pIgnoreErrors
  , pOptGroupName
  , pDiskParams
  , pHvState
  , pDiskState
  , pIgnoreIpolicy
  , pAllowRuntimeChgs
98
99
  , pInstDisks
  , pDiskTemplate
100
  , pOptDiskTemplate
101
102
  , pFileDriver
  , pFileStorageDir
103
104
  , pClusterFileStorageDir
  , pClusterSharedFileStorageDir
Iustin Pop's avatar
Iustin Pop committed
105
106
  , pVgName
  , pEnabledHypervisors
107
  , pHypervisor
Iustin Pop's avatar
Iustin Pop committed
108
  , pClusterHvParams
109
  , pInstHvParams
Iustin Pop's avatar
Iustin Pop committed
110
  , pClusterBeParams
111
112
  , pInstBeParams
  , pResetDefaults
Iustin Pop's avatar
Iustin Pop committed
113
  , pOsHvp
114
115
  , pClusterOsParams
  , pInstOsParams
Iustin Pop's avatar
Iustin Pop committed
116
117
118
119
120
  , pCandidatePoolSize
  , pUidPool
  , pAddUids
  , pRemoveUids
  , pMaintainNodeHealth
121
  , pModifyEtcHosts
Iustin Pop's avatar
Iustin Pop committed
122
123
  , pPreallocWipeDisks
  , pNicParams
124
  , pInstNics
Iustin Pop's avatar
Iustin Pop committed
125
126
127
128
129
130
131
132
133
134
135
136
  , pNdParams
  , pIpolicy
  , pDrbdHelper
  , pDefaultIAllocator
  , pMasterNetdev
  , pMasterNetmask
  , pReservedLvs
  , pHiddenOs
  , pBlacklistedOs
  , pUseExternalMipScript
  , pQueryFields
  , pQueryFilter
Jose A. Lopes's avatar
Jose A. Lopes committed
137
  , pQueryFieldsFields
Iustin Pop's avatar
Iustin Pop committed
138
139
140
141
142
143
144
145
146
147
148
149
  , pOobCommand
  , pOobTimeout
  , pIgnoreStatus
  , pPowerDelay
  , pPrimaryIp
  , pSecondaryIp
  , pReadd
  , pNodeGroup
  , pMasterCapable
  , pVmCapable
  , pNames
  , pNodes
Iustin Pop's avatar
Iustin Pop committed
150
  , pRequiredNodes
Thomas Thrainer's avatar
Thomas Thrainer committed
151
  , pRequiredNodeUuids
Iustin Pop's avatar
Iustin Pop committed
152
  , pStorageType
153
  , pStorageTypeOptional
Iustin Pop's avatar
Iustin Pop committed
154
155
156
157
158
159
160
161
  , pStorageChanges
  , pMasterCandidate
  , pOffline
  , pDrained
  , pAutoPromote
  , pPowered
  , pIallocator
  , pRemoteNode
Thomas Thrainer's avatar
Thomas Thrainer committed
162
  , pRemoteNodeUuid
Iustin Pop's avatar
Iustin Pop committed
163
  , pEvacMode
164
165
166
167
  , pInstCreateMode
  , pNoInstall
  , pInstOs
  , pPrimaryNode
Thomas Thrainer's avatar
Thomas Thrainer committed
168
  , pPrimaryNodeUuid
169
  , pSecondaryNode
Thomas Thrainer's avatar
Thomas Thrainer committed
170
  , pSecondaryNodeUuid
171
172
173
174
175
  , pSourceHandshake
  , pSourceInstance
  , pSourceShutdownTimeout
  , pSourceX509Ca
  , pSrcNode
Thomas Thrainer's avatar
Thomas Thrainer committed
176
  , pSrcNodeUuid
177
178
179
  , pSrcPath
  , pStartInstance
  , pInstTags
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
  , pMultiAllocInstances
  , pTempOsParams
  , pTempHvParams
  , pTempBeParams
  , pIgnoreFailures
  , pNewName
  , pIgnoreSecondaries
  , pRebootType
  , pIgnoreDiskSize
  , pRecreateDisksInfo
  , pStatic
  , pInstParamsNicChanges
  , pInstParamsDiskChanges
  , pRuntimeMem
  , pOsNameChange
  , pDiskIndex
  , pDiskChgAmount
  , pDiskChgAbsolute
  , pTargetGroups
Iustin Pop's avatar
Iustin Pop committed
199
200
  , pExportMode
  , pExportTargetNode
Thomas Thrainer's avatar
Thomas Thrainer committed
201
  , pExportTargetNodeUuid
Iustin Pop's avatar
Iustin Pop committed
202
203
204
205
  , pRemoveInstance
  , pIgnoreRemoveFailures
  , pX509KeyName
  , pX509DestCA
206
  , pTagSearchPattern
Iustin Pop's avatar
Iustin Pop committed
207
  , pRestrictedCommand
208
209
210
211
212
213
  , pReplaceDisksMode
  , pReplaceDisksList
  , pAllowFailover
  , pDelayDuration
  , pDelayOnMaster
  , pDelayOnNodes
Thomas Thrainer's avatar
Thomas Thrainer committed
214
  , pDelayOnNodeUuids
215
  , pDelayRepeat
Iustin Pop's avatar
Iustin Pop committed
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
  , pIAllocatorDirection
  , pIAllocatorMode
  , pIAllocatorReqName
  , pIAllocatorNics
  , pIAllocatorDisks
  , pIAllocatorMemory
  , pIAllocatorVCpus
  , pIAllocatorOs
  , pIAllocatorInstances
  , pIAllocatorEvacMode
  , pIAllocatorSpindleUse
  , pIAllocatorCount
  , pJQueueNotifyWaitLock
  , pJQueueNotifyExec
  , pJQueueLogMessages
  , pJQueueFail
  , pTestDummyResult
  , pTestDummyMessages
  , pTestDummyFail
  , pTestDummySubmitJobs
236
237
238
239
240
241
242
243
244
245
  , pNetworkName
  , pNetworkAddress4
  , pNetworkGateway4
  , pNetworkAddress6
  , pNetworkGateway6
  , pNetworkMacPrefix
  , pNetworkAddRsvdIps
  , pNetworkRemoveRsvdIps
  , pNetworkMode
  , pNetworkLink
246
247
248
249
250
  , pDryRun
  , pDebugLevel
  , pOpPriority
  , pDependencies
  , pComment
251
  , pReason
252
  , pEnabledDiskTemplates
253
254
  ) where

255
import Control.Monad (liftM)
Jose A. Lopes's avatar
Jose A. Lopes committed
256
257
import Text.JSON (JSON, JSValue(..), JSObject (..), readJSON, showJSON,
                  fromJSString, toJSObject)
258
import qualified Text.JSON
259
260
import Text.JSON.Pretty (pp_value)

261
import Ganeti.BasicTypes
262
263
264
import qualified Ganeti.Constants as C
import Ganeti.THH
import Ganeti.JSON
Iustin Pop's avatar
Iustin Pop committed
265
266
import Ganeti.Types
import qualified Ganeti.Query.Language as Qlang
267

Jose A. Lopes's avatar
Jose A. Lopes committed
268
-- * Helper functions and types
Iustin Pop's avatar
Iustin Pop committed
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

-- | Build a boolean field.
booleanField :: String -> Field
booleanField = flip simpleField [t| Bool |]

-- | Default a field to 'False'.
defaultFalse :: String -> Field
defaultFalse = defaultField [| False |] . booleanField

-- | Default a field to 'True'.
defaultTrue :: String -> Field
defaultTrue = defaultField [| True |] . booleanField

-- | An alias for a 'String' field.
stringField :: String -> Field
stringField = flip simpleField [t| String |]

-- | An alias for an optional string field.
optionalStringField :: String -> Field
optionalStringField = optionalField . stringField

-- | An alias for an optional non-empty string field.
optionalNEStringField :: String -> Field
optionalNEStringField = optionalField . flip simpleField [t| NonEmptyString |]

294
295
296
297
298
299
300
301
302
-- | Function to force a non-negative value, without returning via a
-- monad. This is needed for, and should be used /only/ in the case of
-- forcing constants. In case the constant is wrong (< 0), this will
-- become a runtime error.
forceNonNeg :: (Num a, Ord a, Show a) => a -> NonNegative a
forceNonNeg i = case mkNonNegative i of
                  Ok n -> n
                  Bad msg -> error msg

303
304
305
306
307
-- ** Disks

-- | Disk index type (embedding constraints on the index value via a
-- smart constructor).
newtype DiskIndex = DiskIndex { unDiskIndex :: Int }
308
  deriving (Show, Eq, Ord)
309
310
311
312
313
314
315
316
317
318
319
320

-- | Smart constructor for 'DiskIndex'.
mkDiskIndex :: (Monad m) => Int -> m DiskIndex
mkDiskIndex i | i >= 0 && i < C.maxDisks = return (DiskIndex i)
              | otherwise = fail $ "Invalid value for disk index '" ++
                            show i ++ "', required between 0 and " ++
                            show C.maxDisks

instance JSON DiskIndex where
  readJSON v = readJSON v >>= mkDiskIndex
  showJSON = showJSON . unDiskIndex

Iustin Pop's avatar
Iustin Pop committed
321
322
323
324
325
326
327
328
329
330
331
-- ** I* param types

-- | Type holding disk access modes.
$(declareSADT "DiskAccess"
  [ ("DiskReadOnly",  'C.diskRdonly)
  , ("DiskReadWrite", 'C.diskRdwr)
  ])
$(makeJSONInstance ''DiskAccess)

-- | NIC modification definition.
$(buildObject "INicParams" "inic"
Jose A. Lopes's avatar
Jose A. Lopes committed
332
333
334
335
336
337
338
  [ optionalField $ simpleField C.inicMac    [t| NonEmptyString |]
  , optionalField $ simpleField C.inicIp     [t| String         |]
  , optionalField $ simpleField C.inicMode   [t| NonEmptyString |]
  , optionalField $ simpleField C.inicLink   [t| NonEmptyString |]
  , optionalField $ simpleField C.inicName   [t| NonEmptyString |]
  , optionalField $ simpleField C.inicVlan   [t| NonEmptyString |]
  , optionalField $ simpleField C.inicBridge [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
339
340
  ])

341
-- | Disk modification definition. FIXME: disksize should be VTYPE_UNIT.
Iustin Pop's avatar
Iustin Pop committed
342
$(buildObject "IDiskParams" "idisk"
343
344
345
346
347
  [ optionalField $ simpleField C.idiskSize   [t| Int            |]
  , optionalField $ simpleField C.idiskMode   [t| DiskAccess     |]
  , optionalField $ simpleField C.idiskAdopt  [t| NonEmptyString |]
  , optionalField $ simpleField C.idiskVg     [t| NonEmptyString |]
  , optionalField $ simpleField C.idiskMetavg [t| NonEmptyString |]
348
  , optionalField $ simpleField C.idiskName   [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
349
350
  ])

351
352
353
354
355
356
357
358
359
-- | Disk changes type for OpInstanceRecreateDisks. This is a bit
-- strange, because the type in Python is something like Either
-- [DiskIndex] [DiskChanges], but we can't represent the type of an
-- empty list in JSON, so we have to add a custom case for the empty
-- list.
data RecreateDisksInfo
  = RecreateDisksAll
  | RecreateDisksIndices (NonEmpty DiskIndex)
  | RecreateDisksParams (NonEmpty (DiskIndex, IDiskParams))
360
    deriving (Eq, Show)
361
362
363
364
365
366
367
368
369

readRecreateDisks :: JSValue -> Text.JSON.Result RecreateDisksInfo
readRecreateDisks (JSArray []) = return RecreateDisksAll
readRecreateDisks v =
  case readJSON v::Text.JSON.Result [DiskIndex] of
    Text.JSON.Ok indices -> liftM RecreateDisksIndices (mkNonEmpty indices)
    _ -> case readJSON v::Text.JSON.Result [(DiskIndex, IDiskParams)] of
           Text.JSON.Ok params -> liftM RecreateDisksParams (mkNonEmpty params)
           _ -> fail $ "Can't parse disk information as either list of disk"
370
                ++ " indices or list of disk parameters; value received:"
371
372
373
374
375
376
377
378
379
380
381
                ++ show (pp_value v)

instance JSON RecreateDisksInfo where
  readJSON = readRecreateDisks
  showJSON  RecreateDisksAll            = showJSON ()
  showJSON (RecreateDisksIndices idx)   = showJSON idx
  showJSON (RecreateDisksParams params) = showJSON params

-- | Simple type for old-style ddm changes.
data DdmOldChanges = DdmOldIndex (NonNegative Int)
                   | DdmOldMod DdmSimple
382
                     deriving (Eq, Show)
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

readDdmOldChanges :: JSValue -> Text.JSON.Result DdmOldChanges
readDdmOldChanges v =
  case readJSON v::Text.JSON.Result (NonNegative Int) of
    Text.JSON.Ok nn -> return $ DdmOldIndex nn
    _ -> case readJSON v::Text.JSON.Result DdmSimple of
           Text.JSON.Ok ddms -> return $ DdmOldMod ddms
           _ -> fail $ "Can't parse value '" ++ show (pp_value v) ++ "' as"
                ++ " either index or modification"

instance JSON DdmOldChanges where
  showJSON (DdmOldIndex i) = showJSON i
  showJSON (DdmOldMod m)   = showJSON m
  readJSON = readDdmOldChanges

-- | Instance disk or nic modifications.
data SetParamsMods a
  = SetParamsEmpty
  | SetParamsDeprecated (NonEmpty (DdmOldChanges, a))
  | SetParamsNew (NonEmpty (DdmFull, Int, a))
403
    deriving (Eq, Show)
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418

-- | Custom deserialiser for 'SetParamsMods'.
readSetParams :: (JSON a) => JSValue -> Text.JSON.Result (SetParamsMods a)
readSetParams (JSArray []) = return SetParamsEmpty
readSetParams v =
  case readJSON v::Text.JSON.Result [(DdmOldChanges, JSValue)] of
    Text.JSON.Ok _ -> liftM SetParamsDeprecated $ readJSON v
    _ -> liftM SetParamsNew $ readJSON v

instance (JSON a) => JSON (SetParamsMods a) where
  showJSON SetParamsEmpty = showJSON ()
  showJSON (SetParamsDeprecated v) = showJSON v
  showJSON (SetParamsNew v) = showJSON v
  readJSON = readSetParams

Iustin Pop's avatar
Iustin Pop committed
419
-- | Custom type for target_node parameter of OpBackupExport, which
Jose A. Lopes's avatar
Jose A. Lopes committed
420
-- varies depending on mode. FIXME: this uses an [JSValue] since
Iustin Pop's avatar
Iustin Pop committed
421
422
423
-- we don't care about individual rows (just like the Python code
-- tests). But the proper type could be parsed if we wanted.
data ExportTarget = ExportTargetLocal NonEmptyString
Jose A. Lopes's avatar
Jose A. Lopes committed
424
                  | ExportTargetRemote [JSValue]
425
                    deriving (Eq, Show)
Iustin Pop's avatar
Iustin Pop committed
426
427
428
429
430
431
432
433
434
435
436
437
438
439

-- | Custom reader for 'ExportTarget'.
readExportTarget :: JSValue -> Text.JSON.Result ExportTarget
readExportTarget (JSString s) = liftM ExportTargetLocal $
                                mkNonEmpty (fromJSString s)
readExportTarget (JSArray arr) = return $ ExportTargetRemote arr
readExportTarget v = fail $ "Invalid value received for 'target_node': " ++
                     show (pp_value v)

instance JSON ExportTarget where
  showJSON (ExportTargetLocal s)  = showJSON s
  showJSON (ExportTargetRemote l) = showJSON l
  readJSON = readExportTarget

Jose A. Lopes's avatar
Jose A. Lopes committed
440
-- * Common opcode parameters
Iustin Pop's avatar
Iustin Pop committed
441

Jose A. Lopes's avatar
Jose A. Lopes committed
442
443
444
445
pDryRun :: Field
pDryRun =
  withDoc "Run checks only, don't execute" .
  optionalField $ booleanField "dry_run"
Iustin Pop's avatar
Iustin Pop committed
446

Jose A. Lopes's avatar
Jose A. Lopes committed
447
448
449
450
pDebugLevel :: Field
pDebugLevel =
  withDoc "Debug level" .
  optionalField $ simpleField "debug_level" [t| NonNegative Int |]
Iustin Pop's avatar
Iustin Pop committed
451

Jose A. Lopes's avatar
Jose A. Lopes committed
452
453
454
455
456
457
pOpPriority :: Field
pOpPriority =
  withDoc "Opcode priority. Note: python uses a separate constant,\
          \ we're using the actual value we know it's the default" .
  defaultField [| OpPrioNormal |] $
  simpleField "priority" [t| OpSubmitPriority |]
Thomas Thrainer's avatar
Thomas Thrainer committed
458

Jose A. Lopes's avatar
Jose A. Lopes committed
459
460
461
462
pDependencies :: Field
pDependencies =
  withDoc "Job dependencies" .
  optionalNullSerField $ simpleField "depends" [t| [JobDependency] |]
463

Jose A. Lopes's avatar
Jose A. Lopes committed
464
465
466
467
pComment :: Field
pComment =
  withDoc "Comment field" .
  optionalNullSerField $ stringField "comment"
Thomas Thrainer's avatar
Thomas Thrainer committed
468

Jose A. Lopes's avatar
Jose A. Lopes committed
469
470
471
472
pReason :: Field
pReason =
  withDoc "Reason trail field" $
  simpleField C.opcodeReason [t| ReasonTrail |]
Iustin Pop's avatar
Iustin Pop committed
473

Jose A. Lopes's avatar
Jose A. Lopes committed
474
-- * Parameters
Iustin Pop's avatar
Iustin Pop committed
475
476

pDebugSimulateErrors :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
477
478
479
pDebugSimulateErrors =
  withDoc "Whether to simulate errors (useful for debugging)" $
  defaultFalse "debug_simulate_errors"
Iustin Pop's avatar
Iustin Pop committed
480
481

pErrorCodes :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
482
483
484
pErrorCodes = 
  withDoc "Error codes" $
  defaultFalse "error_codes"
Iustin Pop's avatar
Iustin Pop committed
485
486

pSkipChecks :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
487
488
pSkipChecks = 
  withDoc "Which checks to skip" .
489
490
  defaultField [| emptyListSet |] $
  simpleField "skip_checks" [t| ListSet VerifyOptionalChecks |]
Iustin Pop's avatar
Iustin Pop committed
491
492

pIgnoreErrors :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
493
494
pIgnoreErrors =
  withDoc "List of error codes that should be treated as warnings" .
495
496
  defaultField [| emptyListSet |] $
  simpleField "ignore_errors" [t| ListSet CVErrorCode |]
Iustin Pop's avatar
Iustin Pop committed
497

Jose A. Lopes's avatar
Jose A. Lopes committed
498
499
500
501
pVerbose :: Field
pVerbose =
  withDoc "Verbose mode" $
  defaultFalse "verbose"
Iustin Pop's avatar
Iustin Pop committed
502

Jose A. Lopes's avatar
Jose A. Lopes committed
503
504
505
506
507
pOptGroupName :: Field
pOptGroupName =
  withDoc "Optional group name" .
  renameField "OptGroupName" .
  optionalField $ simpleField "group_name" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
508

Jose A. Lopes's avatar
Jose A. Lopes committed
509
510
511
512
pGroupName :: Field
pGroupName =
  withDoc "Group name" $
  simpleField "group_name" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
513

Jose A. Lopes's avatar
Jose A. Lopes committed
514
515
516
517
518
pInstances :: Field
pInstances =
  withDoc "List of instances" .
  defaultField [| [] |] $
  simpleField "instances" [t| [NonEmptyString] |]
519

Jose A. Lopes's avatar
Jose A. Lopes committed
520
521
522
523
pOutputFields :: Field
pOutputFields =
  withDoc "Selected output fields" $
  simpleField "output_fields" [t| [NonEmptyString] |]
524

Jose A. Lopes's avatar
Jose A. Lopes committed
525
526
527
528
pName :: Field
pName =
  withDoc "A generic name" $
  simpleField "name" [t| NonEmptyString |]
529

Jose A. Lopes's avatar
Jose A. Lopes committed
530
531
532
533
pForce :: Field
pForce =
  withDoc "Whether to force the operation" $
  defaultFalse "force"
534

Jose A. Lopes's avatar
Jose A. Lopes committed
535
536
537
538
pHvState :: Field
pHvState =
  withDoc "Set hypervisor states" .
  optionalField $ simpleField "hv_state" [t| JSObject JSValue |]
539

Jose A. Lopes's avatar
Jose A. Lopes committed
540
541
542
543
pDiskState :: Field
pDiskState =
  withDoc "Set disk states" .
  optionalField $ simpleField "disk_state" [t| JSObject JSValue |]
Iustin Pop's avatar
Iustin Pop committed
544

545
546
547
548
549
550
551
552
553
554
555
-- | Cluster-wide default directory for storing file-backed disks.
pClusterFileStorageDir :: Field
pClusterFileStorageDir =
  renameField "ClusterFileStorageDir" $
  optionalStringField "file_storage_dir"

-- | Cluster-wide default directory for storing shared-file-backed disks.
pClusterSharedFileStorageDir :: Field
pClusterSharedFileStorageDir =
  renameField "ClusterSharedFileStorageDir" $
  optionalStringField "shared_file_storage_dir"
556

Iustin Pop's avatar
Iustin Pop committed
557
558
-- | Volume group name.
pVgName :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
559
560
561
pVgName =
  withDoc "Volume group name" $
  optionalStringField "vg_name"
Iustin Pop's avatar
Iustin Pop committed
562
563
564

pEnabledHypervisors :: Field
pEnabledHypervisors =
Jose A. Lopes's avatar
Jose A. Lopes committed
565
  withDoc "List of enabled hypervisors" .
Iustin Pop's avatar
Iustin Pop committed
566
  optionalField $
Jose A. Lopes's avatar
Jose A. Lopes committed
567
  simpleField "enabled_hypervisors" [t| [Hypervisor] |]
568

Iustin Pop's avatar
Iustin Pop committed
569
570
pClusterHvParams :: Field
pClusterHvParams =
Jose A. Lopes's avatar
Jose A. Lopes committed
571
  withDoc "Cluster-wide hypervisor parameters, hypervisor-dependent" .
572
  renameField "ClusterHvParams" .
Iustin Pop's avatar
Iustin Pop committed
573
  optionalField $
Jose A. Lopes's avatar
Jose A. Lopes committed
574
  simpleField "hvparams" [t| GenericContainer String (JSObject JSValue) |]
575

Iustin Pop's avatar
Iustin Pop committed
576
pClusterBeParams :: Field
577
pClusterBeParams =
Jose A. Lopes's avatar
Jose A. Lopes committed
578
  withDoc "Cluster-wide backend parameter defaults" .
579
  renameField "ClusterBeParams" .
Jose A. Lopes's avatar
Jose A. Lopes committed
580
  optionalField $ simpleField "beparams" [t| JSObject JSValue |]
581

Iustin Pop's avatar
Iustin Pop committed
582
pOsHvp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
583
584
585
586
pOsHvp =
  withDoc "Cluster-wide per-OS hypervisor parameter defaults" .
  optionalField $
  simpleField "os_hvp" [t| GenericContainer String (JSObject JSValue) |]
Iustin Pop's avatar
Iustin Pop committed
587

588
589
pClusterOsParams :: Field
pClusterOsParams =
Jose A. Lopes's avatar
Jose A. Lopes committed
590
  withDoc "Cluster-wide OS parameter defaults" .
591
  renameField "ClusterOsParams" .
Jose A. Lopes's avatar
Jose A. Lopes committed
592
593
  optionalField $
  simpleField "osparams" [t| GenericContainer String (JSObject JSValue) |]
594

Jose A. Lopes's avatar
Jose A. Lopes committed
595
596
597
598
599
600
pDiskParams :: Field
pDiskParams =
  withDoc "Disk templates' parameter defaults" .
  optionalField $
  simpleField "diskparams"
              [t| GenericContainer DiskTemplate (JSObject JSValue) |]
601

Iustin Pop's avatar
Iustin Pop committed
602
603
pCandidatePoolSize :: Field
pCandidatePoolSize =
Jose A. Lopes's avatar
Jose A. Lopes committed
604
  withDoc "Master candidate pool size" .
Iustin Pop's avatar
Iustin Pop committed
605
606
607
  optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]

pUidPool :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
608
609
610
pUidPool =
  withDoc "Set UID pool, must be list of lists describing UID ranges\
          \ (two items, start and end inclusive)" .
Jose A. Lopes's avatar
Jose A. Lopes committed
611
  optionalField $ simpleField "uid_pool" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
612
613

pAddUids :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
614
615
616
pAddUids =
  withDoc "Extend UID pool, must be list of lists describing UID\
          \ ranges (two items, start and end inclusive)" .
Jose A. Lopes's avatar
Jose A. Lopes committed
617
  optionalField $ simpleField "add_uids" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
618
619

pRemoveUids :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
620
621
622
pRemoveUids =
  withDoc "Shrink UID pool, must be list of lists describing UID\
          \ ranges (two items, start and end inclusive) to be removed" .
Jose A. Lopes's avatar
Jose A. Lopes committed
623
  optionalField $ simpleField "remove_uids" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
624
625

pMaintainNodeHealth :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
626
627
628
pMaintainNodeHealth =
  withDoc "Whether to automatically maintain node health" .
  optionalField $ booleanField "maintain_node_health"
Iustin Pop's avatar
Iustin Pop committed
629

630
631
632
633
-- | Whether to modify and keep in sync the @/etc/hosts@ files of nodes.
pModifyEtcHosts :: Field
pModifyEtcHosts = optionalField $ booleanField "modify_etc_hosts"

Iustin Pop's avatar
Iustin Pop committed
634
635
-- | Whether to wipe disks before allocating them to instances.
pPreallocWipeDisks :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
636
637
638
pPreallocWipeDisks =
  withDoc "Whether to wipe disks before allocating them to instances" .
  optionalField $ booleanField "prealloc_wipe_disks"
Iustin Pop's avatar
Iustin Pop committed
639
640

pNicParams :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
641
642
643
pNicParams =
  withDoc "Cluster-wide NIC parameter defaults" .
  optionalField $ simpleField "nicparams" [t| INicParams |]
Iustin Pop's avatar
Iustin Pop committed
644
645

pIpolicy :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
646
647
648
pIpolicy =
  withDoc "Ipolicy specs" .
  optionalField $ simpleField "ipolicy" [t| JSObject JSValue |]
Iustin Pop's avatar
Iustin Pop committed
649
650

pDrbdHelper :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
651
652
653
pDrbdHelper =
  withDoc "DRBD helper program" $
  optionalStringField "drbd_helper"
Iustin Pop's avatar
Iustin Pop committed
654
655

pDefaultIAllocator :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
656
657
658
pDefaultIAllocator =
  withDoc "Default iallocator for cluster" $
  optionalStringField "default_iallocator"
Iustin Pop's avatar
Iustin Pop committed
659
660

pMasterNetdev :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
661
662
663
pMasterNetdev =
  withDoc "Master network device" $
  optionalStringField "master_netdev"
Iustin Pop's avatar
Iustin Pop committed
664
665

pMasterNetmask :: Field
666
pMasterNetmask =
Jose A. Lopes's avatar
Jose A. Lopes committed
667
  withDoc "Netmask of the master IP" .
668
  optionalField $ simpleField "master_netmask" [t| NonNegative Int |]
Iustin Pop's avatar
Iustin Pop committed
669
670
671

pReservedLvs :: Field
pReservedLvs =
Jose A. Lopes's avatar
Jose A. Lopes committed
672
  withDoc "List of reserved LVs" .
Iustin Pop's avatar
Iustin Pop committed
673
674
675
  optionalField $ simpleField "reserved_lvs" [t| [NonEmptyString] |]

pHiddenOs :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
676
677
678
679
680
pHiddenOs =
  withDoc "Modify list of hidden operating systems: each modification\
          \ must have two items, the operation and the OS name; the operation\
          \ can be add or remove" .
  optionalField $ simpleField "hidden_os" [t| [(DdmSimple, NonEmptyString)] |]
Iustin Pop's avatar
Iustin Pop committed
681
682
683

pBlacklistedOs :: Field
pBlacklistedOs =
Jose A. Lopes's avatar
Jose A. Lopes committed
684
685
686
687
688
  withDoc "Modify list of blacklisted operating systems: each\
          \ modification must have two items, the operation and the OS name;\
          \ the operation can be add or remove" .
  optionalField $
  simpleField "blacklisted_os" [t| [(DdmSimple, NonEmptyString)] |]
Iustin Pop's avatar
Iustin Pop committed
689
690

pUseExternalMipScript :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
691
692
693
694
695
696
697
698
pUseExternalMipScript =
  withDoc "Whether to use an external master IP address setup script" .
  optionalField $ booleanField "use_external_mip_script"

pEnabledDiskTemplates :: Field
pEnabledDiskTemplates =
  withDoc "List of enabled disk templates" .
  optionalField $
Jose A. Lopes's avatar
Jose A. Lopes committed
699
  simpleField "enabled_disk_templates" [t| [DiskTemplate] |]
Jose A. Lopes's avatar
Jose A. Lopes committed
700
701
702
703
704
705
706
707
708
709

pQueryWhat :: Field
pQueryWhat =
  withDoc "Resource(s) to query for" $
  simpleField "what" [t| Qlang.QueryTypeOp |]

pUseLocking :: Field
pUseLocking =
  withDoc "Whether to use synchronization" $
  defaultFalse "use_locking"
Iustin Pop's avatar
Iustin Pop committed
710
711

pQueryFields :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
712
713
714
pQueryFields =
  withDoc "Requested fields" $
  simpleField "fields" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
715
716

pQueryFilter :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
pQueryFilter =
  withDoc "Query filter" .
  optionalField $ simpleField "qfilter" [t| [JSValue] |]

pQueryFieldsFields :: Field
pQueryFieldsFields =
  withDoc "Requested fields; if not given, all are returned" .
  renameField "QueryFieldsFields" $
  optionalField pQueryFields

pNodeNames :: Field
pNodeNames =
  withDoc "List of node names to run the OOB command against" .
  defaultField [| [] |] $ simpleField "node_names" [t| [NonEmptyString] |]

pNodeUuids :: Field
pNodeUuids =
  withDoc "List of node UUIDs" .
  optionalField $ simpleField "node_uuids" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
736
737

pOobCommand :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
738
739
740
pOobCommand =
  withDoc "OOB command to run" $
  simpleField "command" [t| OobCommand |]
Iustin Pop's avatar
Iustin Pop committed
741
742
743

pOobTimeout :: Field
pOobTimeout =
Jose A. Lopes's avatar
Jose A. Lopes committed
744
745
746
  withDoc "Timeout before the OOB helper will be terminated" .
  defaultField [| C.oobTimeout |] $
  simpleField "timeout" [t| Int |]
Iustin Pop's avatar
Iustin Pop committed
747
748

pIgnoreStatus :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
749
750
751
pIgnoreStatus =
  withDoc "Ignores the node offline status for power off" $
  defaultFalse "ignore_status"
Iustin Pop's avatar
Iustin Pop committed
752
753
754
755
756

pPowerDelay :: Field
pPowerDelay =
  -- FIXME: we can't use the proper type "NonNegative Double", since
  -- the default constant is a plain Double, not a non-negative one.
Jose A. Lopes's avatar
Jose A. Lopes committed
757
758
  -- And trying to fix the constant introduces a cyclic import.
  withDoc "Time in seconds to wait between powering on nodes" .
Iustin Pop's avatar
Iustin Pop committed
759
760
761
  defaultField [| C.oobPowerDelay |] $
  simpleField "power_delay" [t| Double |]

Jose A. Lopes's avatar
Jose A. Lopes committed
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
pRequiredNodes :: Field
pRequiredNodes =
  withDoc "Required list of node names" .
  renameField "ReqNodes " $ simpleField "nodes" [t| [NonEmptyString] |]

pRequiredNodeUuids :: Field
pRequiredNodeUuids =
  withDoc "Required list of node UUIDs" .
  renameField "ReqNodeUuids " . optionalField $
  simpleField "node_uuids" [t| [NonEmptyString] |]

pRestrictedCommand :: Field
pRestrictedCommand =
  withDoc "Restricted command name" .
  renameField "RestrictedCommand" $
  simpleField "command" [t| NonEmptyString |]

pNodeName :: Field
pNodeName =
  withDoc "A required node name (for single-node LUs)" $
  simpleField "node_name" [t| NonEmptyString |]

pNodeUuid :: Field
pNodeUuid =
  withDoc "A node UUID (for single-node LUs)" .
  optionalField $ simpleField "node_uuid" [t| NonEmptyString |]

Iustin Pop's avatar
Iustin Pop committed
789
pPrimaryIp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
790
pPrimaryIp =
Jose A. Lopes's avatar
Jose A. Lopes committed
791
792
  withDoc "Primary IP address" .
  optionalField $
Jose A. Lopes's avatar
Jose A. Lopes committed
793
  simpleField "primary_ip" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
794
795

pSecondaryIp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
796
797
798
pSecondaryIp =
  withDoc "Secondary IP address" $
  optionalNEStringField "secondary_ip"
Iustin Pop's avatar
Iustin Pop committed
799
800

pReadd :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
801
802
803
pReadd =
  withDoc "Whether node is re-added to cluster" $
  defaultFalse "readd"
Iustin Pop's avatar
Iustin Pop committed
804
805

pNodeGroup :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
806
807
808
pNodeGroup =
  withDoc "Initial node group" $
  optionalNEStringField "group"
Iustin Pop's avatar
Iustin Pop committed
809
810

pMasterCapable :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
811
812
813
pMasterCapable =
  withDoc "Whether node can become master or master candidate" .
  optionalField $ booleanField "master_capable"
Iustin Pop's avatar
Iustin Pop committed
814
815

pVmCapable :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
816
817
818
pVmCapable =
  withDoc "Whether node can host instances" .
  optionalField $ booleanField "vm_capable"
Iustin Pop's avatar
Iustin Pop committed
819

Jose A. Lopes's avatar
Jose A. Lopes committed
820
821
822
823
824
825
pNdParams :: Field
pNdParams =
  withDoc "Node parameters" .
  renameField "genericNdParams" .
  optionalField $ simpleField "ndparams" [t| JSObject JSValue |]
  
Iustin Pop's avatar
Iustin Pop committed
826
pNames :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
827
828
829
pNames =
  withDoc "List of names" .
  defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
830
831

pNodes :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
832
833
834
pNodes =
  withDoc "List of nodes" .
  defaultField [| [] |] $ simpleField "nodes" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
835
836

pStorageType :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
837
pStorageType =
838
839
840
841
842
843
844
  withDoc "Storage type" $ simpleField "storage_type" [t| StorageType |]

pStorageTypeOptional :: Field
pStorageTypeOptional =
  withDoc "Storage type" .
  renameField "StorageTypeOptional" .
  optionalField $ simpleField "storage_type" [t| StorageType |]
Jose A. Lopes's avatar
Jose A. Lopes committed
845
846
847
848
849
850

pStorageName :: Field
pStorageName =
  withDoc "Storage name" .
  renameField "StorageName" .
  optionalField $ simpleField "name" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
851
852

pStorageChanges :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
853
854
855
856
857
858
859
860
pStorageChanges =
  withDoc "Requested storage changes" $
  simpleField "changes" [t| JSObject JSValue |]

pIgnoreConsistency :: Field
pIgnoreConsistency =
  withDoc "Whether to ignore disk consistency" $
  defaultFalse "ignore_consistency"
Iustin Pop's avatar
Iustin Pop committed
861
862

pMasterCandidate :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
863
864
865
pMasterCandidate =
  withDoc "Whether the node should become a master candidate" .
  optionalField $ booleanField "master_candidate"
Iustin Pop's avatar
Iustin Pop committed
866
867

pOffline :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
868
869
870
pOffline =
  withDoc "Whether to mark the node or instance offline" .
  optionalField $ booleanField "offline"
Iustin Pop's avatar
Iustin Pop committed
871
872

pDrained ::Field
Jose A. Lopes's avatar
Jose A. Lopes committed
873
874
875
pDrained =
  withDoc "Whether to mark the node as drained" .
  optionalField $ booleanField "drained"
Iustin Pop's avatar
Iustin Pop committed
876
877

pAutoPromote :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
878
879
880
881
pAutoPromote =
  withDoc "Whether node(s) should be promoted to master candidate if\
          \ necessary" $
  defaultFalse "auto_promote"
Iustin Pop's avatar
Iustin Pop committed
882
883

pPowered :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
884
885
886
pPowered =
  withDoc "Whether the node should be marked as powered" .
  optionalField $ booleanField "powered"
Iustin Pop's avatar
Iustin Pop committed
887

Jose A. Lopes's avatar
Jose A. Lopes committed
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
pMigrationMode :: Field
pMigrationMode =
  withDoc "Migration type (live/non-live)" .
  renameField "MigrationMode" .
  optionalField $
  simpleField "mode" [t| MigrationMode |]

pMigrationLive :: Field
pMigrationLive =
  withDoc "Obsolete \'live\' migration mode (do not use)" .
  renameField "OldLiveMode" . optionalField $ booleanField "live"

pMigrationTargetNode :: Field
pMigrationTargetNode =
  withDoc "Target node for instance migration/failover" $
  optionalNEStringField "target_node"

pMigrationTargetNodeUuid :: Field
pMigrationTargetNodeUuid =
  withDoc "Target node UUID for instance migration/failover" $
  optionalNEStringField "target_node_uuid"

pAllowRuntimeChgs :: Field
pAllowRuntimeChgs =
  withDoc "Whether to allow runtime changes while migrating" $
  defaultTrue "allow_runtime_changes"

pIgnoreIpolicy :: Field
pIgnoreIpolicy =
  withDoc "Whether to ignore ipolicy violations" $
  defaultFalse "ignore_ipolicy"
  
Iustin Pop's avatar
Iustin Pop committed
920
pIallocator :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
921
922
923
924
925
926
927
928
929
pIallocator =
  withDoc "Iallocator for deciding the target node for shared-storage\
          \ instances" $
  optionalNEStringField "iallocator"

pEarlyRelease :: Field
pEarlyRelease =
  withDoc "Whether to release locks as soon as possible" $
  defaultFalse "early_release"
Iustin Pop's avatar
Iustin Pop committed
930
931

pRemoteNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
932
933
934
pRemoteNode =
  withDoc "New secondary node" $
  optionalNEStringField "remote_node"
Iustin Pop's avatar
Iustin Pop committed
935

Thomas Thrainer's avatar
Thomas Thrainer committed
936
pRemoteNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
937
938
939
pRemoteNodeUuid =
  withDoc "New secondary node UUID" $
  optionalNEStringField "remote_node_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
940

Iustin Pop's avatar
Iustin Pop committed
941
pEvacMode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
942
943
pEvacMode =
  withDoc "Node evacuation mode" .
944
  renameField "EvacMode" $ simpleField "mode" [t| EvacMode |]
Jose A. Lopes's avatar
Jose A. Lopes committed
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979

pInstanceName :: Field
pInstanceName =
  withDoc "A required instance name (for single-instance LUs)" $
  simpleField "instance_name" [t| String |]

pForceVariant :: Field
pForceVariant =
  withDoc "Whether to force an unknown OS variant" $
  defaultFalse "force_variant"

pWaitForSync :: Field
pWaitForSync =
  withDoc "Whether to wait for the disk to synchronize" $
  defaultTrue "wait_for_sync"

pNameCheck :: Field
pNameCheck =
  withDoc "Whether to check name" $
  defaultTrue "name_check"

pInstBeParams :: Field
pInstBeParams =
  withDoc "Backend parameters for instance" .
  renameField "InstBeParams" .
  defaultField [| toJSObject [] |] $
  simpleField "beparams" [t| JSObject JSValue |]

pInstDisks :: Field
pInstDisks =
  withDoc "List of instance disks" .
  renameField "instDisks" $ simpleField "disks" [t| [IDiskParams] |]

pDiskTemplate :: Field
pDiskTemplate =
Jose A. Lopes's avatar
Jose A. Lopes committed
980
  withDoc "Disk template" $
Jose A. Lopes's avatar
Jose A. Lopes committed
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
  simpleField "disk_template" [t| DiskTemplate |]

pFileDriver :: Field
pFileDriver =
  withDoc "Driver for file-backed disks" .
  optionalField $ simpleField "file_driver" [t| FileDriver |]

pFileStorageDir :: Field
pFileStorageDir =
  withDoc "Directory for storing file-backed disks" $
  optionalNEStringField "file_storage_dir"

pInstHvParams :: Field
pInstHvParams =
  withDoc "Hypervisor parameters for instance, hypervisor-dependent" .
  renameField "InstHvParams" .
  defaultField [| toJSObject [] |] $
  simpleField "hvparams" [t| JSObject JSValue |]

pHypervisor :: Field
pHypervisor =
  withDoc "Selected hypervisor for an instance" .
  optionalField $
  simpleField "hypervisor" [t| Hypervisor |]

pResetDefaults :: Field
pResetDefaults =
  withDoc "Reset instance parameters to default if equal" $
  defaultFalse "identify_defaults"

pIpCheck :: Field
pIpCheck =
  withDoc "Whether to ensure instance's IP address is inactive" $
  defaultTrue "ip_check"

pIpConflictsCheck :: Field
pIpConflictsCheck =
  withDoc "Whether to check for conflicting IP addresses" $
  defaultTrue "conflicts_check"
1020
1021
1022

pInstCreateMode :: Field
pInstCreateMode =
Jose A. Lopes's avatar
Jose A. Lopes committed
1023
  withDoc "Instance creation mode" .
1024
1025
  renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]

Jose A. Lopes's avatar
Jose A. Lopes committed
1026
1027
1028
1029
1030
pInstNics :: Field
pInstNics =
  withDoc "List of NIC (network interface) definitions" $
  simpleField "nics" [t| [INicParams] |]

1031
pNoInstall :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1032
1033
1034
pNoInstall =
  withDoc "Do not install the OS (will disable automatic start)" .
  optionalField $ booleanField "no_install"
1035
1036

pInstOs :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
pInstOs =
  withDoc "OS type for instance installation" $
  optionalNEStringField "os_type"

pInstOsParams :: Field
pInstOsParams =
  withDoc "OS parameters for instance" .
  renameField "InstOsParams" .
  defaultField [| toJSObject [] |] $
  simpleField "osparams" [t| JSObject JSValue |]
1047
1048

pPrimaryNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1049
1050
1051
pPrimaryNode =
  withDoc "Primary node for an instance" $
  optionalNEStringField "pnode"
1052

Thomas Thrainer's avatar
Thomas Thrainer committed
1053
pPrimaryNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1054
1055
1056
pPrimaryNodeUuid =
  withDoc "Primary node UUID for an instance" $
  optionalNEStringField "pnode_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
1057

1058
pSecondaryNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1059
1060
1061
pSecondaryNode =
  withDoc "Secondary node for an instance" $
  optionalNEStringField "snode"
1062

Thomas Thrainer's avatar
Thomas Thrainer committed
1063
pSecondaryNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1064
1065
1066
pSecondaryNodeUuid =
  withDoc "Secondary node UUID for an instance" $
  optionalNEStringField "snode_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
1067

1068
1069
pSourceHandshake :: Field
pSourceHandshake =
Jose A. Lopes's avatar
Jose A. Lopes committed
1070
1071
  withDoc "Signed handshake from source (remote import only)" .
  optionalField $ simpleField "source_handshake" [t| [JSValue] |]
1072
1073

pSourceInstance :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1074
1075
1076
pSourceInstance =
  withDoc "Source instance name (remote import only)" $
  optionalNEStringField "source_instance_name"
1077
1078
1079
1080

-- FIXME: non-negative int, whereas the constant is a plain int.
pSourceShutdownTimeout :: Field
pSourceShutdownTimeout =
Jose A. Lopes's avatar
Jose A. Lopes committed
1081
1082
  withDoc "How long source instance was given to shut down (remote import\
          \ only)" .
1083
1084
1085
1086
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
  simpleField "source_shutdown_timeout" [t| NonNegative Int |]

pSourceX509Ca :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1087
1088
1089
pSourceX509Ca =
  withDoc "Source X509 CA in PEM format (remote import only)" $
  optionalNEStringField "source_x509_ca"
1090
1091

pSrcNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1092
1093
1094
pSrcNode =
  withDoc "Source node for import" $
  optionalNEStringField "src_node"
1095

Thomas Thrainer's avatar
Thomas Thrainer committed
1096
pSrcNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1097
1098
1099
pSrcNodeUuid =
  withDoc "Source node UUID for import" $
  optionalNEStringField "src_node_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
1100

1101
pSrcPath :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1102
1103
1104
pSrcPath =
  withDoc "Source directory for import" $
  optionalNEStringField "src_path"
1105
1106

pStartInstance :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1107
1108
1109
pStartInstance =
  withDoc "Whether to start instance after creation" $
  defaultTrue "start"
1110

Jose A. Lopes's avatar
Jose A. Lopes committed
1111
-- FIXME: unify/simplify with pTags, once that migrates to NonEmpty String"
1112
1113
pInstTags :: Field
pInstTags =
Jose A. Lopes's avatar
Jose A. Lopes committed
1114
  withDoc "Instance tags" .
1115
1116
1117
  renameField "InstTags" .
  defaultField [| [] |] $
  simpleField "tags" [t| [NonEmptyString] |]
1118
1119
1120

pMultiAllocInstances :: Field
pMultiAllocInstances =
Jose A. Lopes's avatar
Jose A. Lopes committed
1121
1122
  withDoc "List of instance create opcodes describing the instances to\
          \ allocate" .
1123
1124
  renameField "InstMultiAlloc" .
  defaultField [| [] |] $
Jose A. Lopes's avatar
Jose A. Lopes committed
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
  simpleField "instances"[t| [JSValue] |]

pOpportunisticLocking :: Field
pOpportunisticLocking =
  withDoc "Whether to employ opportunistic locking for nodes, meaning\
          \ nodes already locked by another opcode won't be considered for\
          \ instance allocation (only when an iallocator is used)" $
  defaultFalse "opportunistic_locking"

pInstanceUuid :: Field
pInstanceUuid =
  withDoc "An instance UUID (for single-instance LUs)" .
  optionalField $ simpleField "instance_uuid" [t| NonEmptyString |]

pTempOsParams :: Field
pTempOsParams =
  withDoc "Temporary OS parameters (currently only in reinstall, might be\
          \ added to install as well)" .
  renameField "TempOsParams" .
  optionalField $ simpleField "osparams" [t| JSObject JSValue |]

pShutdownTimeout :: Field
pShutdownTimeout =
  withDoc "How long to wait for instance to shut down" .
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
  simpleField "shutdown_timeout" [t| NonNegative Int |]
1151

Jose A. Lopes's avatar
Jose A. Lopes committed
1152
1153
1154
1155
1156
1157
1158
1159
1160
-- | Another name for the shutdown timeout, because we like to be
-- inconsistent.
pShutdownTimeout' :: Field
pShutdownTimeout' =
  withDoc "How long to wait for instance to shut down" .
  renameField "InstShutdownTimeout" .
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
  simpleField "timeout" [t| NonNegative Int |]

1161
pIgnoreFailures :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1162
1163
1164
pIgnoreFailures =
  withDoc "Whether to ignore failures during removal" $
  defaultFalse "ignore_failures"
1165
1166

pNewName :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
pNewName =
  withDoc "New group or instance name" $
  simpleField "new_name" [t| NonEmptyString |]
  
pIgnoreOfflineNodes :: Field
pIgnoreOfflineNodes =
  withDoc "Whether to ignore offline nodes" $
  defaultFalse "ignore_offline_nodes"

pTempHvParams :: Field
pTempHvParams =
  withDoc "Temporary hypervisor parameters, hypervisor-dependent" .
  renameField "TempHvParams" .
  defaultField [| toJSObject [] |] $
  simpleField "hvparams" [t| JSObject JSValue |]

pTempBeParams :: Field
pTempBeParams =
  withDoc "Temporary backend parameters" .
  renameField "TempBeParams" .
  defaultField [| toJSObject [] |] $
  simpleField "beparams" [t| JSObject JSValue |]

pNoRemember :: Field
pNoRemember =
  withDoc "Do not remember instance state changes" $
  defaultFalse "no_remember"

pStartupPaused :: Field
pStartupPaused =
  withDoc "Pause instance at startup" $
  defaultFalse "startup_paused"
1199
1200

pIgnoreSecondaries :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1201
1202
1203
pIgnoreSecondaries =
  withDoc "Whether to start the instance even if secondary disks are failing" $
  defaultFalse "ignore_secondaries"
1204
1205

pRebootType :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1206
1207
1208
pRebootType =
  withDoc "How to reboot the instance" $
  simpleField "reboot_type" [t| RebootType |]
1209

Jose A. Lopes's avatar
Jose A. Lopes committed
1210
1211
1212
1213
pReplaceDisksMode :: Field
pReplaceDisksMode =
  withDoc "Replacement mode" .
  renameField "ReplaceDisksMode" $ simpleField "mode" [t| ReplaceDisksMode |]
1214

Jose A. Lopes's avatar
Jose A. Lopes committed
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
pReplaceDisksList :: Field
pReplaceDisksList =
  withDoc "List of disk indices" .
  renameField "ReplaceDisksList" .
  defaultField [| [] |] $
  simpleField "disks" [t| [DiskIndex] |]

pMigrationCleanup :: Field
pMigrationCleanup =
  withDoc "Whether a previously failed migration should be cleaned up" .
  renameField "MigrationCleanup" $ defaultFalse "cleanup"

pAllowFailover :: Field
pAllowFailover =
  withDoc "Whether we can fallback to failover if migration is not possible" $
  defaultFalse "allow_failover"

pMoveTargetNode :: Field
pMoveTargetNode =
  withDoc "Target node for instance move" .
  renameField "MoveTargetNode" $
  simpleField "target_node" [t| NonEmptyString |]

pMoveTargetNodeUuid :: Field
pMoveTargetNodeUuid =
  withDoc "Target node UUID for instance move" .
  renameField "MoveTargetNodeUuid" . optionalField $
  simpleField "target_node_uuid" [t| NonEmptyString |]

pIgnoreDiskSize :: Field
pIgnoreDiskSize =
  withDoc "Whether to ignore recorded disk size" $
  defaultFalse "ignore_size"
  
pWaitForSyncFalse :: Field
pWaitForSyncFalse =
  withDoc "Whether to wait for the disk to synchronize (defaults to false)" $
  defaultField [| False |] pWaitForSync
  
1254
1255
pRecreateDisksInfo :: Field
pRecreateDisksInfo =
Jose A. Lopes's avatar
Jose A. Lopes committed
1256
  withDoc "Disk list for recreate disks" .
1257
1258
1259
1260
1261
  renameField "RecreateDisksInfo" .
  defaultField [| RecreateDisksAll |] $
  simpleField "disks" [t| RecreateDisksInfo |]

pStatic :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1262
1263
1264
pStatic =
  withDoc "Whether to only return configuration data without querying nodes" $
  defaultFalse "static"
1265
1266
1267

pInstParamsNicChanges :: Field
pInstParamsNicChanges =
Jose A. Lopes's avatar
Jose A. Lopes committed
1268
  withDoc "List of NIC changes" .
1269
1270
1271
1272
1273
1274
  renameField "InstNicChanges" .
  defaultField [| SetParamsEmpty |] $
  simpleField "nics" [t| SetParamsMods INicParams |]

pInstParamsDiskChanges :: Field
pInstParamsDiskChanges =
Jose A. Lopes's avatar
Jose A. Lopes committed
1275
  withDoc "List of disk changes" .
1276
1277
1278
1279
1280
  renameField "InstDiskChanges" .
  defaultField [| SetParamsEmpty |] $
  simpleField "disks" [t| SetParamsMods IDiskParams |]

pRuntimeMem :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
pRuntimeMem =
  withDoc "New runtime memory" .
  optionalField $ simpleField "runtime_mem" [t| Positive Int |]

pOptDiskTemplate :: Field
pOptDiskTemplate =
  withDoc "Instance disk template" .
  optionalField .
  renameField "OptDiskTemplate" $
  simpleField "disk_template" [t| DiskTemplate |]
1291
1292

pOsNameChange :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1293
1294
1295
pOsNameChange =
  withDoc "Change the instance's OS without reinstalling the instance" $
  optionalNEStringField "os_name"
1296
1297

pDiskIndex :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1298
1299
1300
pDiskIndex =
  withDoc "Disk index for e.g. grow disk" .
  renameField "DiskIndex " $ simpleField "disk" [t| DiskIndex |]
1301
1302
1303

pDiskChgAmount :: Field
pDiskChgAmount =
Jose A. Lopes's avatar
Jose A. Lopes committed
1304
  withDoc "Disk amount to add or grow to" .
1305
1306
1307
  renameField "DiskChgAmount" $ simpleField "amount" [t| NonNegative Int |]

pDiskChgAbsolute :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1308
1309
1310
1311
pDiskChgAbsolute =
  withDoc
    "Whether the amount parameter is an absolute target or a relative one" .
  renameField "DiskChkAbsolute" $ defaultFalse "absolute"
1312
1313
1314

pTargetGroups :: Field
pTargetGroups =
Jose A. Lopes's avatar
Jose A. Lopes committed
1315
1316
  withDoc
    "Destination group names or UUIDs (defaults to \"all but current group\")" .
1317
  optionalField $ simpleField "target_groups" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
1318

Jose A. Lopes's avatar
Jose A. Lopes committed
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
pNodeGroupAllocPolicy :: Field
pNodeGroupAllocPolicy =
  withDoc "Instance allocation policy" .
  optionalField $
  simpleField "alloc_policy" [t| AllocPolicy |]

pGroupNodeParams :: Field
pGroupNodeParams =
  withDoc "Default node parameters for group" .
  optionalField $ simpleField "ndparams" [t| JSObject JSValue |]

Iustin Pop's avatar
Iustin Pop committed
1330
1331
pExportMode :: Field
pExportMode =
Jose A. Lopes's avatar
Jose A. Lopes committed
1332
  withDoc "Export mode" .
Iustin Pop's avatar
Iustin Pop committed
1333
1334
  renameField "ExportMode" $ simpleField "mode" [t| ExportMode |]

Jose A. Lopes's avatar
Jose A. Lopes committed
1335
1336
-- FIXME: Rename target_node as it changes meaning for different
-- export modes (e.g. "destination")
Iustin Pop's avatar
Iustin Pop committed
1337
1338
pExportTargetNode :: Field
pExportTargetNode =
Jose A. Lopes's avatar
Jose A. Lopes committed
1339
  withDoc "Target node (depends on export mode)" .
Iustin Pop's avatar
Iustin Pop committed
1340
1341
1342
  renameField "ExportTarget" $
  simpleField "target_node" [t| ExportTarget |]

Thomas Thrainer's avatar
Thomas Thrainer committed
1343
1344
pExportTargetNodeUuid :: Field
pExportTargetNodeUuid =
Jose A. Lopes's avatar
Jose A. Lopes committed
1345
  withDoc "Target node UUID (if local export)" .
Thomas Thrainer's avatar
Thomas Thrainer committed
1346
1347
1348
  renameField "ExportTargetNodeUuid" . optionalField $
  simpleField "target_node_uuid" [t| NonEmptyString |]

Jose A. Lopes's avatar
Jose A. Lopes committed
1349
1350
1351
1352
1353
pShutdownInstance :: Field
pShutdownInstance =
  withDoc "Whether to shutdown the instance before export" $
  defaultTrue "shutdown"

Iustin Pop's avatar
Iustin Pop committed
1354
pRemoveInstance :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1355
1356
1357
pRemoveInstance =
  withDoc "Whether to remove instance after export" $
  defaultFalse "remove_instance"
Iustin Pop's avatar
Iustin Pop committed
1358
1359

pIgnoreRemoveFailures :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1360
1361
1362
pIgnoreRemoveFailures =
  withDoc "Whether to ignore failures while removing instances" $
  defaultFalse "ignore_remove_failures"
Iustin Pop's avatar
Iustin Pop committed
1363
1364

pX509KeyName :: Field