OpParams.hs 45.1 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
86
  , pMoveCompress
Iustin Pop's avatar
Iustin Pop committed
87
88
89
90
91
92
93
94
95
96
97
98
  , pStartupPaused
  , pVerbose
  , pDebugSimulateErrors
  , pErrorCodes
  , pSkipChecks
  , pIgnoreErrors
  , pOptGroupName
  , pDiskParams
  , pHvState
  , pDiskState
  , pIgnoreIpolicy
  , pAllowRuntimeChgs
99
100
  , pInstDisks
  , pDiskTemplate
101
  , pOptDiskTemplate
102
103
  , pFileDriver
  , pFileStorageDir
104
105
  , pClusterFileStorageDir
  , pClusterSharedFileStorageDir
Iustin Pop's avatar
Iustin Pop committed
106
107
  , pVgName
  , pEnabledHypervisors
108
  , pHypervisor
Iustin Pop's avatar
Iustin Pop committed
109
  , pClusterHvParams
110
  , pInstHvParams
Iustin Pop's avatar
Iustin Pop committed
111
  , pClusterBeParams
112
113
  , pInstBeParams
  , pResetDefaults
Iustin Pop's avatar
Iustin Pop committed
114
  , pOsHvp
115
116
  , pClusterOsParams
  , pInstOsParams
Iustin Pop's avatar
Iustin Pop committed
117
118
119
120
121
  , pCandidatePoolSize
  , pUidPool
  , pAddUids
  , pRemoveUids
  , pMaintainNodeHealth
122
  , pModifyEtcHosts
Iustin Pop's avatar
Iustin Pop committed
123
124
  , pPreallocWipeDisks
  , pNicParams
125
  , pInstNics
Iustin Pop's avatar
Iustin Pop committed
126
127
128
129
130
131
132
133
134
135
136
137
  , pNdParams
  , pIpolicy
  , pDrbdHelper
  , pDefaultIAllocator
  , pMasterNetdev
  , pMasterNetmask
  , pReservedLvs
  , pHiddenOs
  , pBlacklistedOs
  , pUseExternalMipScript
  , pQueryFields
  , pQueryFilter
Jose A. Lopes's avatar
Jose A. Lopes committed
138
  , pQueryFieldsFields
Iustin Pop's avatar
Iustin Pop committed
139
140
141
142
143
144
145
146
147
148
149
150
  , pOobCommand
  , pOobTimeout
  , pIgnoreStatus
  , pPowerDelay
  , pPrimaryIp
  , pSecondaryIp
  , pReadd
  , pNodeGroup
  , pMasterCapable
  , pVmCapable
  , pNames
  , pNodes
Iustin Pop's avatar
Iustin Pop committed
151
  , pRequiredNodes
Thomas Thrainer's avatar
Thomas Thrainer committed
152
  , pRequiredNodeUuids
Iustin Pop's avatar
Iustin Pop committed
153
  , pStorageType
154
  , pStorageTypeOptional
Iustin Pop's avatar
Iustin Pop committed
155
156
157
158
159
160
161
162
  , pStorageChanges
  , pMasterCandidate
  , pOffline
  , pDrained
  , pAutoPromote
  , pPowered
  , pIallocator
  , pRemoteNode
Thomas Thrainer's avatar
Thomas Thrainer committed
163
  , pRemoteNodeUuid
Iustin Pop's avatar
Iustin Pop committed
164
  , pEvacMode
165
166
167
168
  , pInstCreateMode
  , pNoInstall
  , pInstOs
  , pPrimaryNode
Thomas Thrainer's avatar
Thomas Thrainer committed
169
  , pPrimaryNodeUuid
170
  , pSecondaryNode
Thomas Thrainer's avatar
Thomas Thrainer committed
171
  , pSecondaryNodeUuid
172
173
174
175
176
  , pSourceHandshake
  , pSourceInstance
  , pSourceShutdownTimeout
  , pSourceX509Ca
  , pSrcNode
Thomas Thrainer's avatar
Thomas Thrainer committed
177
  , pSrcNodeUuid
178
179
180
  , pSrcPath
  , pStartInstance
  , pInstTags
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
  , 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
200
201
  , pExportMode
  , pExportTargetNode
Thomas Thrainer's avatar
Thomas Thrainer committed
202
  , pExportTargetNodeUuid
Iustin Pop's avatar
Iustin Pop committed
203
204
205
206
  , pRemoveInstance
  , pIgnoreRemoveFailures
  , pX509KeyName
  , pX509DestCA
207
  , pTagSearchPattern
Iustin Pop's avatar
Iustin Pop committed
208
  , pRestrictedCommand
209
210
211
212
213
214
  , pReplaceDisksMode
  , pReplaceDisksList
  , pAllowFailover
  , pDelayDuration
  , pDelayOnMaster
  , pDelayOnNodes
Thomas Thrainer's avatar
Thomas Thrainer committed
215
  , pDelayOnNodeUuids
216
  , pDelayRepeat
Iustin Pop's avatar
Iustin Pop committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  , pIAllocatorDirection
  , pIAllocatorMode
  , pIAllocatorReqName
  , pIAllocatorNics
  , pIAllocatorDisks
  , pIAllocatorMemory
  , pIAllocatorVCpus
  , pIAllocatorOs
  , pIAllocatorInstances
  , pIAllocatorEvacMode
  , pIAllocatorSpindleUse
  , pIAllocatorCount
  , pJQueueNotifyWaitLock
  , pJQueueNotifyExec
  , pJQueueLogMessages
  , pJQueueFail
  , pTestDummyResult
  , pTestDummyMessages
  , pTestDummyFail
  , pTestDummySubmitJobs
237
238
239
240
241
242
243
244
245
246
  , pNetworkName
  , pNetworkAddress4
  , pNetworkGateway4
  , pNetworkAddress6
  , pNetworkGateway6
  , pNetworkMacPrefix
  , pNetworkAddRsvdIps
  , pNetworkRemoveRsvdIps
  , pNetworkMode
  , pNetworkLink
247
248
249
250
251
  , pDryRun
  , pDebugLevel
  , pOpPriority
  , pDependencies
  , pComment
252
  , pReason
253
  , pEnabledDiskTemplates
254
255
  ) where

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

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

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

-- | 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 |]

295
296
297
298
299
300
301
302
303
-- | 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

304
305
306
307
308
-- ** Disks

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

-- | 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
322
323
324
325
326
327
328
329
330
331
332
-- ** 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
333
334
335
336
337
338
339
  [ 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
340
341
  ])

342
-- | Disk modification definition. FIXME: disksize should be VTYPE_UNIT.
Iustin Pop's avatar
Iustin Pop committed
343
$(buildObject "IDiskParams" "idisk"
344
345
346
347
348
  [ 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 |]
349
  , optionalField $ simpleField C.idiskName   [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
350
351
  ])

352
353
354
355
356
357
358
359
360
-- | 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))
361
    deriving (Eq, Show)
362
363
364
365
366
367
368
369
370

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"
371
                ++ " indices or list of disk parameters; value received:"
372
373
374
375
376
377
378
379
380
381
382
                ++ 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
383
                     deriving (Eq, Show)
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

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))
404
    deriving (Eq, Show)
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

-- | 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
420
-- | Custom type for target_node parameter of OpBackupExport, which
Jose A. Lopes's avatar
Jose A. Lopes committed
421
-- varies depending on mode. FIXME: this uses an [JSValue] since
Iustin Pop's avatar
Iustin Pop committed
422
423
424
-- 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
425
                  | ExportTargetRemote [JSValue]
426
                    deriving (Eq, Show)
Iustin Pop's avatar
Iustin Pop committed
427
428
429
430
431
432
433
434
435
436
437
438
439
440

-- | 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
441
-- * Common opcode parameters
Iustin Pop's avatar
Iustin Pop committed
442

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

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

Jose A. Lopes's avatar
Jose A. Lopes committed
453
454
455
456
457
458
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
459

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

546
547
548
549
550
551
552
553
554
555
556
-- | 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"
557

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

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

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

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

Iustin Pop's avatar
Iustin Pop committed
583
pOsHvp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
584
585
586
587
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
588

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

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

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

pUidPool :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
609
610
611
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
612
  optionalField $ simpleField "uid_pool" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
613
614

pAddUids :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
615
616
617
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
618
  optionalField $ simpleField "add_uids" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
619
620

pRemoveUids :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
621
622
623
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
624
  optionalField $ simpleField "remove_uids" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
625
626

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

631
632
633
634
-- | 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
635
636
-- | Whether to wipe disks before allocating them to instances.
pPreallocWipeDisks :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
637
638
639
pPreallocWipeDisks =
  withDoc "Whether to wipe disks before allocating them to instances" .
  optionalField $ booleanField "prealloc_wipe_disks"
Iustin Pop's avatar
Iustin Pop committed
640
641

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

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

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

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

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

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

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

pHiddenOs :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
677
678
679
680
681
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
682
683
684

pBlacklistedOs :: Field
pBlacklistedOs =
Jose A. Lopes's avatar
Jose A. Lopes committed
685
686
687
688
689
  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
690
691

pUseExternalMipScript :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
692
693
694
695
696
697
698
699
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
700
  simpleField "enabled_disk_templates" [t| [DiskTemplate] |]
Jose A. Lopes's avatar
Jose A. Lopes committed
701
702
703
704
705
706
707
708
709
710

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
711
712

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

pQueryFilter :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
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
737
738

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

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

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

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
758
759
  -- 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
760
761
762
  defaultField [| C.oobPowerDelay |] $
  simpleField "power_delay" [t| Double |]

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

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

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

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

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

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

Jose A. Lopes's avatar
Jose A. Lopes committed
821
822
823
824
825
pNdParams :: Field
pNdParams =
  withDoc "Node parameters" .
  renameField "genericNdParams" .
  optionalField $ simpleField "ndparams" [t| JSObject JSValue |]
Thomas Thrainer's avatar
Thomas Thrainer committed
826

Iustin Pop's avatar
Iustin Pop committed
827
pNames :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
828
829
830
pNames =
  withDoc "List of names" .
  defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
831
832

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

pStorageType :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
838
pStorageType =
839
840
841
842
843
844
845
  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
846
847
848
849
850
851

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

pStorageChanges :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
854
855
856
857
858
859
860
861
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
862
863

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

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

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

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

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

Jose A. Lopes's avatar
Jose A. Lopes committed
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"
Thomas Thrainer's avatar
Thomas Thrainer committed
920

Iustin Pop's avatar
Iustin Pop committed
921
pIallocator :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
922
923
924
925
926
927
928
929
930
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
931
932

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

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

Iustin Pop's avatar
Iustin Pop committed
942
pEvacMode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
943
944
pEvacMode =
  withDoc "Node evacuation mode" .
945
  renameField "EvacMode" $ simpleField "mode" [t| EvacMode |]
Jose A. Lopes's avatar
Jose A. Lopes committed
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
980

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
981
  withDoc "Disk template" $
Jose A. Lopes's avatar
Jose A. Lopes committed
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
1020
  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"
1021
1022
1023

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

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

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

pInstOs :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
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 |]
1048
1049

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

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

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

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

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

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

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

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

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

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

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

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

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

pMultiAllocInstances :: Field
pMultiAllocInstances =
Jose A. Lopes's avatar
Jose A. Lopes committed
1122
1123
  withDoc "List of instance create opcodes describing the instances to\
          \ allocate" .
1124
1125
  renameField "InstMultiAlloc" .
  defaultField [| [] |] $
Jose A. Lopes's avatar
Jose A. Lopes committed
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
1151
  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 |]
1152

Jose A. Lopes's avatar
Jose A. Lopes committed
1153
1154
1155
1156
1157
1158
1159
1160
1161
-- | 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 |]

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

pNewName :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1168
1169
1170
pNewName =
  withDoc "New group or instance name" $
  simpleField "new_name" [t| NonEmptyString |]
Thomas Thrainer's avatar
Thomas Thrainer committed
1171

Jose A. Lopes's avatar
Jose A. Lopes committed
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
1199
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"
1200
1201

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

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

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

Jose A. Lopes's avatar
Jose A. Lopes committed
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
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 |]

1245
1246
1247
1248
1249
1250
pMoveCompress :: Field
pMoveCompress =
  withDoc "Compression mode to use during instance moves" .
  defaultField [| None |] $
  simpleField "compress" [t| ImportExportCompression |]

Jose A. Lopes's avatar
Jose A. Lopes committed
1251
1252
1253
1254
pIgnoreDiskSize :: Field
pIgnoreDiskSize =
  withDoc "Whether to ignore recorded disk size" $
  defaultFalse "ignore_size"
Thomas Thrainer's avatar
Thomas Thrainer committed
1255

Jose A. Lopes's avatar
Jose A. Lopes committed
1256
1257
1258
1259
pWaitForSyncFalse :: Field
pWaitForSyncFalse =
  withDoc "Whether to wait for the disk to synchronize (defaults to false)" $
  defaultField [| False |] pWaitForSync
Thomas Thrainer's avatar
Thomas Thrainer committed
1260

1261
1262
pRecreateDisksInfo :: Field
pRecreateDisksInfo =
Jose A. Lopes's avatar
Jose A. Lopes committed
1263
  withDoc "Disk list for recreate disks" .
1264
1265
1266
1267
1268
  renameField "RecreateDisksInfo" .
  defaultField [| RecreateDisksAll |] $
  simpleField "disks" [t| RecreateDisksInfo |]

pStatic :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1269
1270
1271
pStatic =
  withDoc "Whether to only return configuration data without querying nodes" $
  defaultFalse "static"
1272
1273
1274

pInstParamsNicChanges :: Field
pInstParamsNicChanges =
Jose A. Lopes's avatar
Jose A. Lopes committed
1275
  withDoc "List of NIC changes" .
1276
1277
1278
1279
1280
1281
  renameField "InstNicChanges" .
  defaultField [| SetParamsEmpty |] $
  simpleField "nics" [t| SetParamsMods INicParams |]

pInstParamsDiskChanges :: Field
pInstParamsDiskChanges =
Jose A. Lopes's avatar
Jose A. Lopes committed
1282
  withDoc "List of disk changes" .
1283
1284
1285
1286
1287
  renameField "InstDiskChanges" .
  defaultField [| SetParamsEmpty |] $
  simpleField "disks" [t| SetParamsMods IDiskParams |]

pRuntimeMem :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
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 |]
1298
1299

pOsNameChange :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1300
1301
1302
pOsNameChange =
  withDoc "Change the instance's OS without reinstalling the instance" $
  optionalNEStringField "os_name"
1303
1304

pDiskIndex :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1305
1306
1307
pDiskIndex =
  withDoc "Disk index for e.g. grow disk" .
  renameField "DiskIndex " $ simpleField "disk" [t| DiskIndex |]
1308
1309
1310

pDiskChgAmount :: Field
pDiskChgAmount =
Jose A. Lopes's avatar
Jose A. Lopes committed
1311
  withDoc "Disk amount to add or grow to" .
1312
1313
1314
  renameField "DiskChgAmount" $ simpleField "amount" [t| NonNegative Int |]

pDiskChgAbsolute :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1315
1316
1317
1318
pDiskChgAbsolute =
  withDoc
    "Whether the amount parameter is an absolute target or a relative one" .
  renameField "DiskChkAbsolute" $ defaultFalse "absolute"
1319
1320
1321

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

Jose A. Lopes's avatar
Jose A. Lopes committed
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
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
1337
1338
pExportMode :: Field
pExportMode =
Jose A. Lopes's avatar
Jose A. Lopes committed
1339
  withDoc "Export mode" .
Iustin Pop's avatar
Iustin Pop committed
1340
1341
  renameField "ExportMode" $ simpleField "mode" [t| ExportMode |]

Jose A. Lopes's avatar
Jose A. Lopes committed
1342
1343
-- FIXME: Rename target_node as it changes meaning for different
-- export modes (e.g. "destination")
Iustin Pop's avatar
Iustin Pop committed
1344
1345
pExportTargetNode :: Field
pExportTargetNode =
Jose A. Lopes's avatar
Jose A. Lopes committed
1346
  withDoc "Target node (depends on export mode)" .
Iustin Pop's avatar
Iustin Pop committed
1347
1348
1349
  renameField "ExportTarget" $
  simpleField "target_node" [t| ExportTarget |]

Thomas Thrainer's avatar
Thomas Thrainer committed
<