Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / OpParams.hs @ 015f1517

History | View | Annotate | Download (46.7 kB)

1
{-# LANGUAGE TemplateHaskell #-}
2

    
3
{-| Implementation of opcodes parameters.
4

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

    
11
-}
12

    
13
{-
14

    
15
Copyright (C) 2012, 2014 Google Inc.
16

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

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

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

    
32
-}
33

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

    
263
import Control.Monad (liftM, mplus)
264
import Text.JSON (JSON, JSValue(..), JSObject (..), readJSON, showJSON,
265
                  fromJSString, toJSObject)
266
import qualified Text.JSON
267
import Text.JSON.Pretty (pp_value)
268

    
269
import Ganeti.BasicTypes
270
import qualified Ganeti.Constants as C
271
import Ganeti.THH
272
import Ganeti.Utils
273
import Ganeti.JSON
274
import Ganeti.Types
275
import qualified Ganeti.Query.Language as Qlang
276

    
277
-- * Helper functions and types
278

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

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

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

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

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

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

    
303
-- | Function to force a non-negative value, without returning via a
304
-- monad. This is needed for, and should be used /only/ in the case of
305
-- forcing constants. In case the constant is wrong (< 0), this will
306
-- become a runtime error.
307
forceNonNeg :: (Num a, Ord a, Show a) => a -> NonNegative a
308
forceNonNeg i = case mkNonNegative i of
309
                  Ok n -> n
310
                  Bad msg -> error msg
311

    
312
-- ** Disks
313

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

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

    
326
instance JSON DiskIndex where
327
  readJSON v = readJSON v >>= mkDiskIndex
328
  showJSON = showJSON . unDiskIndex
329

    
330
-- ** I* param types
331

    
332
-- | Type holding disk access modes.
333
$(declareSADT "DiskAccess"
334
  [ ("DiskReadOnly",  'C.diskRdonly)
335
  , ("DiskReadWrite", 'C.diskRdwr)
336
  ])
337
$(makeJSONInstance ''DiskAccess)
338

    
339
-- | NIC modification definition.
340
$(buildObject "INicParams" "inic"
341
  [ optionalField $ simpleField C.inicMac    [t| NonEmptyString |]
342
  , optionalField $ simpleField C.inicIp     [t| String         |]
343
  , optionalField $ simpleField C.inicMode   [t| NonEmptyString |]
344
  , optionalField $ simpleField C.inicLink   [t| NonEmptyString |]
345
  , optionalField $ simpleField C.inicName   [t| NonEmptyString |]
346
  , optionalField $ simpleField C.inicVlan   [t| String         |]
347
  , optionalField $ simpleField C.inicBridge [t| NonEmptyString |]
348
  ])
349

    
350
-- | Disk modification definition.
351
$(buildObject "IDiskParams" "idisk"
352
  [ specialNumericalField 'parseUnitAssumeBinary . optionalField
353
      $ simpleField C.idiskSize               [t| Int            |]
354
  , optionalField $ simpleField C.idiskMode   [t| DiskAccess     |]
355
  , optionalField $ simpleField C.idiskAdopt  [t| NonEmptyString |]
356
  , optionalField $ simpleField C.idiskVg     [t| NonEmptyString |]
357
  , optionalField $ simpleField C.idiskMetavg [t| NonEmptyString |]
358
  , optionalField $ simpleField C.idiskName   [t| NonEmptyString |]
359
  , optionalField $ simpleField C.idiskProvider [t| NonEmptyString |]
360
  , optionalField $ simpleField C.idiskSpindles [t| Int          |]
361
  , andRestArguments "opaque"
362
  ])
363

    
364
-- | Disk changes type for OpInstanceRecreateDisks. This is a bit
365
-- strange, because the type in Python is something like Either
366
-- [DiskIndex] [DiskChanges], but we can't represent the type of an
367
-- empty list in JSON, so we have to add a custom case for the empty
368
-- list.
369
data RecreateDisksInfo
370
  = RecreateDisksAll
371
  | RecreateDisksIndices (NonEmpty DiskIndex)
372
  | RecreateDisksParams (NonEmpty (DiskIndex, IDiskParams))
373
    deriving (Eq, Show)
374

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

    
386
instance JSON RecreateDisksInfo where
387
  readJSON = readRecreateDisks
388
  showJSON  RecreateDisksAll            = showJSON ()
389
  showJSON (RecreateDisksIndices idx)   = showJSON idx
390
  showJSON (RecreateDisksParams params) = showJSON params
391

    
392
-- | Simple type for old-style ddm changes.
393
data DdmOldChanges = DdmOldIndex (NonNegative Int)
394
                   | DdmOldMod DdmSimple
395
                     deriving (Eq, Show)
396

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

    
406
instance JSON DdmOldChanges where
407
  showJSON (DdmOldIndex i) = showJSON i
408
  showJSON (DdmOldMod m)   = showJSON m
409
  readJSON = readDdmOldChanges
410

    
411
-- | Instance disk or nic modifications.
412
data SetParamsMods a
413
  = SetParamsEmpty
414
  | SetParamsDeprecated (NonEmpty (DdmOldChanges, a))
415
  | SetParamsNew (NonEmpty (DdmFull, Int, a))
416
  | SetParamsNewName (NonEmpty (DdmFull, String, a))
417
    deriving (Eq, Show)
418

    
419
-- | Custom deserialiser for 'SetParamsMods'.
420
readSetParams :: (JSON a) => JSValue -> Text.JSON.Result (SetParamsMods a)
421
readSetParams (JSArray []) = return SetParamsEmpty
422
readSetParams v =
423
  liftM SetParamsDeprecated (readJSON v)
424
  `mplus` liftM SetParamsNew (readJSON v)
425
  `mplus` liftM SetParamsNewName (readJSON v)
426

    
427
instance (JSON a) => JSON (SetParamsMods a) where
428
  showJSON SetParamsEmpty = showJSON ()
429
  showJSON (SetParamsDeprecated v) = showJSON v
430
  showJSON (SetParamsNew v) = showJSON v
431
  showJSON (SetParamsNewName v) = showJSON v
432
  readJSON = readSetParams
433

    
434
-- | Custom type for target_node parameter of OpBackupExport, which
435
-- varies depending on mode. FIXME: this uses an [JSValue] since
436
-- we don't care about individual rows (just like the Python code
437
-- tests). But the proper type could be parsed if we wanted.
438
data ExportTarget = ExportTargetLocal NonEmptyString
439
                  | ExportTargetRemote [JSValue]
440
                    deriving (Eq, Show)
441

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

    
450
instance JSON ExportTarget where
451
  showJSON (ExportTargetLocal s)  = showJSON s
452
  showJSON (ExportTargetRemote l) = showJSON l
453
  readJSON = readExportTarget
454

    
455
-- * Common opcode parameters
456

    
457
pDryRun :: Field
458
pDryRun =
459
  withDoc "Run checks only, don't execute" .
460
  optionalField $ booleanField "dry_run"
461

    
462
pDebugLevel :: Field
463
pDebugLevel =
464
  withDoc "Debug level" .
465
  optionalField $ simpleField "debug_level" [t| NonNegative Int |]
466

    
467
pOpPriority :: Field
468
pOpPriority =
469
  withDoc "Opcode priority. Note: python uses a separate constant,\
470
          \ we're using the actual value we know it's the default" .
471
  defaultField [| OpPrioNormal |] $
472
  simpleField "priority" [t| OpSubmitPriority |]
473

    
474
pDependencies :: Field
475
pDependencies =
476
  withDoc "Job dependencies" .
477
  optionalNullSerField $ simpleField "depends" [t| [JobDependency] |]
478

    
479
pComment :: Field
480
pComment =
481
  withDoc "Comment field" .
482
  optionalNullSerField $ stringField "comment"
483

    
484
pReason :: Field
485
pReason =
486
  withDoc "Reason trail field" $
487
  simpleField C.opcodeReason [t| ReasonTrail |]
488

    
489
-- * Parameters
490

    
491
pDebugSimulateErrors :: Field
492
pDebugSimulateErrors =
493
  withDoc "Whether to simulate errors (useful for debugging)" $
494
  defaultFalse "debug_simulate_errors"
495

    
496
pErrorCodes :: Field
497
pErrorCodes =
498
  withDoc "Error codes" $
499
  defaultFalse "error_codes"
500

    
501
pSkipChecks :: Field
502
pSkipChecks =
503
  withDoc "Which checks to skip" .
504
  defaultField [| emptyListSet |] $
505
  simpleField "skip_checks" [t| ListSet VerifyOptionalChecks |]
506

    
507
pIgnoreErrors :: Field
508
pIgnoreErrors =
509
  withDoc "List of error codes that should be treated as warnings" .
510
  defaultField [| emptyListSet |] $
511
  simpleField "ignore_errors" [t| ListSet CVErrorCode |]
512

    
513
pVerbose :: Field
514
pVerbose =
515
  withDoc "Verbose mode" $
516
  defaultFalse "verbose"
517

    
518
pOptGroupName :: Field
519
pOptGroupName =
520
  withDoc "Optional group name" .
521
  renameField "OptGroupName" .
522
  optionalField $ simpleField "group_name" [t| NonEmptyString |]
523

    
524
pGroupName :: Field
525
pGroupName =
526
  withDoc "Group name" $
527
  simpleField "group_name" [t| NonEmptyString |]
528

    
529
-- | Whether to hotplug device.
530
pHotplug :: Field
531
pHotplug = defaultFalse "hotplug"
532

    
533
pHotplugIfPossible :: Field
534
pHotplugIfPossible = defaultFalse "hotplug_if_possible"
535

    
536
pInstances :: Field
537
pInstances =
538
  withDoc "List of instances" .
539
  defaultField [| [] |] $
540
  simpleField "instances" [t| [NonEmptyString] |]
541

    
542
pOutputFields :: Field
543
pOutputFields =
544
  withDoc "Selected output fields" $
545
  simpleField "output_fields" [t| [NonEmptyString] |]
546

    
547
pName :: Field
548
pName =
549
  withDoc "A generic name" $
550
  simpleField "name" [t| NonEmptyString |]
551

    
552
pForce :: Field
553
pForce =
554
  withDoc "Whether to force the operation" $
555
  defaultFalse "force"
556

    
557
pHvState :: Field
558
pHvState =
559
  withDoc "Set hypervisor states" .
560
  optionalField $ simpleField "hv_state" [t| JSObject JSValue |]
561

    
562
pDiskState :: Field
563
pDiskState =
564
  withDoc "Set disk states" .
565
  optionalField $ simpleField "disk_state" [t| JSObject JSValue |]
566

    
567
-- | Cluster-wide default directory for storing file-backed disks.
568
pClusterFileStorageDir :: Field
569
pClusterFileStorageDir =
570
  renameField "ClusterFileStorageDir" $
571
  optionalStringField "file_storage_dir"
572

    
573
-- | Cluster-wide default directory for storing shared-file-backed disks.
574
pClusterSharedFileStorageDir :: Field
575
pClusterSharedFileStorageDir =
576
  renameField "ClusterSharedFileStorageDir" $
577
  optionalStringField "shared_file_storage_dir"
578

    
579
-- | Cluster-wide default directory for storing Gluster-backed disks.
580
pClusterGlusterStorageDir :: Field
581
pClusterGlusterStorageDir =
582
  renameField "ClusterGlusterStorageDir" $
583
  optionalStringField "gluster_storage_dir"
584

    
585
-- | Volume group name.
586
pVgName :: Field
587
pVgName =
588
  withDoc "Volume group name" $
589
  optionalStringField "vg_name"
590

    
591
pEnabledHypervisors :: Field
592
pEnabledHypervisors =
593
  withDoc "List of enabled hypervisors" .
594
  optionalField $
595
  simpleField "enabled_hypervisors" [t| [Hypervisor] |]
596

    
597
pClusterHvParams :: Field
598
pClusterHvParams =
599
  withDoc "Cluster-wide hypervisor parameters, hypervisor-dependent" .
600
  renameField "ClusterHvParams" .
601
  optionalField $
602
  simpleField "hvparams" [t| GenericContainer String (JSObject JSValue) |]
603

    
604
pClusterBeParams :: Field
605
pClusterBeParams =
606
  withDoc "Cluster-wide backend parameter defaults" .
607
  renameField "ClusterBeParams" .
608
  optionalField $ simpleField "beparams" [t| JSObject JSValue |]
609

    
610
pOsHvp :: Field
611
pOsHvp =
612
  withDoc "Cluster-wide per-OS hypervisor parameter defaults" .
613
  optionalField $
614
  simpleField "os_hvp" [t| GenericContainer String (JSObject JSValue) |]
615

    
616
pClusterOsParams :: Field
617
pClusterOsParams =
618
  withDoc "Cluster-wide OS parameter defaults" .
619
  renameField "ClusterOsParams" .
620
  optionalField $
621
  simpleField "osparams" [t| GenericContainer String (JSObject JSValue) |]
622

    
623
pDiskParams :: Field
624
pDiskParams =
625
  withDoc "Disk templates' parameter defaults" .
626
  optionalField $
627
  simpleField "diskparams"
628
              [t| GenericContainer DiskTemplate (JSObject JSValue) |]
629

    
630
pCandidatePoolSize :: Field
631
pCandidatePoolSize =
632
  withDoc "Master candidate pool size" .
633
  optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]
634

    
635
pMaxRunningJobs :: Field
636
pMaxRunningJobs =
637
  withDoc "Maximal number of jobs to run simultaneously" .
638
  optionalField $ simpleField "max_running_jobs" [t| Positive Int |]
639

    
640
pUidPool :: Field
641
pUidPool =
642
  withDoc "Set UID pool, must be list of lists describing UID ranges\
643
          \ (two items, start and end inclusive)" .
644
  optionalField $ simpleField "uid_pool" [t| [(Int, Int)] |]
645

    
646
pAddUids :: Field
647
pAddUids =
648
  withDoc "Extend UID pool, must be list of lists describing UID\
649
          \ ranges (two items, start and end inclusive)" .
650
  optionalField $ simpleField "add_uids" [t| [(Int, Int)] |]
651

    
652
pRemoveUids :: Field
653
pRemoveUids =
654
  withDoc "Shrink UID pool, must be list of lists describing UID\
655
          \ ranges (two items, start and end inclusive) to be removed" .
656
  optionalField $ simpleField "remove_uids" [t| [(Int, Int)] |]
657

    
658
pMaintainNodeHealth :: Field
659
pMaintainNodeHealth =
660
  withDoc "Whether to automatically maintain node health" .
661
  optionalField $ booleanField "maintain_node_health"
662

    
663
-- | Whether to modify and keep in sync the @/etc/hosts@ files of nodes.
664
pModifyEtcHosts :: Field
665
pModifyEtcHosts = optionalField $ booleanField "modify_etc_hosts"
666

    
667
-- | Whether to wipe disks before allocating them to instances.
668
pPreallocWipeDisks :: Field
669
pPreallocWipeDisks =
670
  withDoc "Whether to wipe disks before allocating them to instances" .
671
  optionalField $ booleanField "prealloc_wipe_disks"
672

    
673
pNicParams :: Field
674
pNicParams =
675
  withDoc "Cluster-wide NIC parameter defaults" .
676
  optionalField $ simpleField "nicparams" [t| INicParams |]
677

    
678
pIpolicy :: Field
679
pIpolicy =
680
  withDoc "Ipolicy specs" .
681
  optionalField $ simpleField "ipolicy" [t| JSObject JSValue |]
682

    
683
pDrbdHelper :: Field
684
pDrbdHelper =
685
  withDoc "DRBD helper program" $
686
  optionalStringField "drbd_helper"
687

    
688
pDefaultIAllocator :: Field
689
pDefaultIAllocator =
690
  withDoc "Default iallocator for cluster" $
691
  optionalStringField "default_iallocator"
692

    
693
pDefaultIAllocatorParams :: Field
694
pDefaultIAllocatorParams =
695
  withDoc "Default iallocator parameters for cluster" . optionalField
696
    $ simpleField "default_iallocator_params" [t| JSObject JSValue |]
697

    
698
pMasterNetdev :: Field
699
pMasterNetdev =
700
  withDoc "Master network device" $
701
  optionalStringField "master_netdev"
702

    
703
pMasterNetmask :: Field
704
pMasterNetmask =
705
  withDoc "Netmask of the master IP" .
706
  optionalField $ simpleField "master_netmask" [t| NonNegative Int |]
707

    
708
pReservedLvs :: Field
709
pReservedLvs =
710
  withDoc "List of reserved LVs" .
711
  optionalField $ simpleField "reserved_lvs" [t| [NonEmptyString] |]
712

    
713
pHiddenOs :: Field
714
pHiddenOs =
715
  withDoc "Modify list of hidden operating systems: each modification\
716
          \ must have two items, the operation and the OS name; the operation\
717
          \ can be add or remove" .
718
  optionalField $ simpleField "hidden_os" [t| [(DdmSimple, NonEmptyString)] |]
719

    
720
pBlacklistedOs :: Field
721
pBlacklistedOs =
722
  withDoc "Modify list of blacklisted operating systems: each\
723
          \ modification must have two items, the operation and the OS name;\
724
          \ the operation can be add or remove" .
725
  optionalField $
726
  simpleField "blacklisted_os" [t| [(DdmSimple, NonEmptyString)] |]
727

    
728
pUseExternalMipScript :: Field
729
pUseExternalMipScript =
730
  withDoc "Whether to use an external master IP address setup script" .
731
  optionalField $ booleanField "use_external_mip_script"
732

    
733
pEnabledDiskTemplates :: Field
734
pEnabledDiskTemplates =
735
  withDoc "List of enabled disk templates" .
736
  optionalField $
737
  simpleField "enabled_disk_templates" [t| [DiskTemplate] |]
738

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

    
744
pUseLocking :: Field
745
pUseLocking =
746
  withDoc "Whether to use synchronization" $
747
  defaultFalse "use_locking"
748

    
749
pQueryFields :: Field
750
pQueryFields =
751
  withDoc "Requested fields" $
752
  simpleField "fields" [t| [NonEmptyString] |]
753

    
754
pQueryFilter :: Field
755
pQueryFilter =
756
  withDoc "Query filter" .
757
  optionalField $ simpleField "qfilter" [t| [JSValue] |]
758

    
759
pQueryFieldsFields :: Field
760
pQueryFieldsFields =
761
  withDoc "Requested fields; if not given, all are returned" .
762
  renameField "QueryFieldsFields" $
763
  optionalField pQueryFields
764

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

    
770
pNodeUuids :: Field
771
pNodeUuids =
772
  withDoc "List of node UUIDs" .
773
  optionalField $ simpleField "node_uuids" [t| [NonEmptyString] |]
774

    
775
pOobCommand :: Field
776
pOobCommand =
777
  withDoc "OOB command to run" $
778
  simpleField "command" [t| OobCommand |]
779

    
780
pOobTimeout :: Field
781
pOobTimeout =
782
  withDoc "Timeout before the OOB helper will be terminated" .
783
  defaultField [| C.oobTimeout |] $
784
  simpleField "timeout" [t| Int |]
785

    
786
pIgnoreStatus :: Field
787
pIgnoreStatus =
788
  withDoc "Ignores the node offline status for power off" $
789
  defaultFalse "ignore_status"
790

    
791
pPowerDelay :: Field
792
pPowerDelay =
793
  -- FIXME: we can't use the proper type "NonNegative Double", since
794
  -- the default constant is a plain Double, not a non-negative one.
795
  -- And trying to fix the constant introduces a cyclic import.
796
  withDoc "Time in seconds to wait between powering on nodes" .
797
  defaultField [| C.oobPowerDelay |] $
798
  simpleField "power_delay" [t| Double |]
799

    
800
pRequiredNodes :: Field
801
pRequiredNodes =
802
  withDoc "Required list of node names" .
803
  renameField "ReqNodes " $ simpleField "nodes" [t| [NonEmptyString] |]
804

    
805
pRequiredNodeUuids :: Field
806
pRequiredNodeUuids =
807
  withDoc "Required list of node UUIDs" .
808
  renameField "ReqNodeUuids " . optionalField $
809
  simpleField "node_uuids" [t| [NonEmptyString] |]
810

    
811
pRestrictedCommand :: Field
812
pRestrictedCommand =
813
  withDoc "Restricted command name" .
814
  renameField "RestrictedCommand" $
815
  simpleField "command" [t| NonEmptyString |]
816

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

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

    
827
pPrimaryIp :: Field
828
pPrimaryIp =
829
  withDoc "Primary IP address" .
830
  optionalField $
831
  simpleField "primary_ip" [t| NonEmptyString |]
832

    
833
pSecondaryIp :: Field
834
pSecondaryIp =
835
  withDoc "Secondary IP address" $
836
  optionalNEStringField "secondary_ip"
837

    
838
pReadd :: Field
839
pReadd =
840
  withDoc "Whether node is re-added to cluster" $
841
  defaultFalse "readd"
842

    
843
pNodeGroup :: Field
844
pNodeGroup =
845
  withDoc "Initial node group" $
846
  optionalNEStringField "group"
847

    
848
pMasterCapable :: Field
849
pMasterCapable =
850
  withDoc "Whether node can become master or master candidate" .
851
  optionalField $ booleanField "master_capable"
852

    
853
pVmCapable :: Field
854
pVmCapable =
855
  withDoc "Whether node can host instances" .
856
  optionalField $ booleanField "vm_capable"
857

    
858
pNdParams :: Field
859
pNdParams =
860
  withDoc "Node parameters" .
861
  renameField "genericNdParams" .
862
  optionalField $ simpleField "ndparams" [t| JSObject JSValue |]
863

    
864
pNames :: Field
865
pNames =
866
  withDoc "List of names" .
867
  defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
868

    
869
pNodes :: Field
870
pNodes =
871
  withDoc "List of nodes" .
872
  defaultField [| [] |] $ simpleField "nodes" [t| [NonEmptyString] |]
873

    
874
pStorageType :: Field
875
pStorageType =
876
  withDoc "Storage type" $ simpleField "storage_type" [t| StorageType |]
877

    
878
pStorageTypeOptional :: Field
879
pStorageTypeOptional =
880
  withDoc "Storage type" .
881
  renameField "StorageTypeOptional" .
882
  optionalField $ simpleField "storage_type" [t| StorageType |]
883

    
884
pStorageName :: Field
885
pStorageName =
886
  withDoc "Storage name" .
887
  renameField "StorageName" .
888
  optionalField $ simpleField "name" [t| NonEmptyString |]
889

    
890
pStorageChanges :: Field
891
pStorageChanges =
892
  withDoc "Requested storage changes" $
893
  simpleField "changes" [t| JSObject JSValue |]
894

    
895
pIgnoreConsistency :: Field
896
pIgnoreConsistency =
897
  withDoc "Whether to ignore disk consistency" $
898
  defaultFalse "ignore_consistency"
899

    
900
pMasterCandidate :: Field
901
pMasterCandidate =
902
  withDoc "Whether the node should become a master candidate" .
903
  optionalField $ booleanField "master_candidate"
904

    
905
pOffline :: Field
906
pOffline =
907
  withDoc "Whether to mark the node or instance offline" .
908
  optionalField $ booleanField "offline"
909

    
910
pDrained ::Field
911
pDrained =
912
  withDoc "Whether to mark the node as drained" .
913
  optionalField $ booleanField "drained"
914

    
915
pAutoPromote :: Field
916
pAutoPromote =
917
  withDoc "Whether node(s) should be promoted to master candidate if\
918
          \ necessary" $
919
  defaultFalse "auto_promote"
920

    
921
pPowered :: Field
922
pPowered =
923
  withDoc "Whether the node should be marked as powered" .
924
  optionalField $ booleanField "powered"
925

    
926
pMigrationMode :: Field
927
pMigrationMode =
928
  withDoc "Migration type (live/non-live)" .
929
  renameField "MigrationMode" .
930
  optionalField $
931
  simpleField "mode" [t| MigrationMode |]
932

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

    
938
pMigrationTargetNode :: Field
939
pMigrationTargetNode =
940
  withDoc "Target node for instance migration/failover" $
941
  optionalNEStringField "target_node"
942

    
943
pMigrationTargetNodeUuid :: Field
944
pMigrationTargetNodeUuid =
945
  withDoc "Target node UUID for instance migration/failover" $
946
  optionalNEStringField "target_node_uuid"
947

    
948
pAllowRuntimeChgs :: Field
949
pAllowRuntimeChgs =
950
  withDoc "Whether to allow runtime changes while migrating" $
951
  defaultTrue "allow_runtime_changes"
952

    
953
pIgnoreIpolicy :: Field
954
pIgnoreIpolicy =
955
  withDoc "Whether to ignore ipolicy violations" $
956
  defaultFalse "ignore_ipolicy"
957

    
958
pIallocator :: Field
959
pIallocator =
960
  withDoc "Iallocator for deciding the target node for shared-storage\
961
          \ instances" $
962
  optionalNEStringField "iallocator"
963

    
964
pEarlyRelease :: Field
965
pEarlyRelease =
966
  withDoc "Whether to release locks as soon as possible" $
967
  defaultFalse "early_release"
968

    
969
pRemoteNode :: Field
970
pRemoteNode =
971
  withDoc "New secondary node" $
972
  optionalNEStringField "remote_node"
973

    
974
pRemoteNodeUuid :: Field
975
pRemoteNodeUuid =
976
  withDoc "New secondary node UUID" $
977
  optionalNEStringField "remote_node_uuid"
978

    
979
pEvacMode :: Field
980
pEvacMode =
981
  withDoc "Node evacuation mode" .
982
  renameField "EvacMode" $ simpleField "mode" [t| EvacMode |]
983

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

    
989
pInstanceCommunication :: Field
990
pInstanceCommunication =
991
  withDoc C.instanceCommunicationDoc $
992
  defaultFalse "instance_communication"
993

    
994
pForceVariant :: Field
995
pForceVariant =
996
  withDoc "Whether to force an unknown OS variant" $
997
  defaultFalse "force_variant"
998

    
999
pWaitForSync :: Field
1000
pWaitForSync =
1001
  withDoc "Whether to wait for the disk to synchronize" $
1002
  defaultTrue "wait_for_sync"
1003

    
1004
pNameCheck :: Field
1005
pNameCheck =
1006
  withDoc "Whether to check name" $
1007
  defaultTrue "name_check"
1008

    
1009
pInstBeParams :: Field
1010
pInstBeParams =
1011
  withDoc "Backend parameters for instance" .
1012
  renameField "InstBeParams" .
1013
  defaultField [| toJSObject [] |] $
1014
  simpleField "beparams" [t| JSObject JSValue |]
1015

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

    
1021
pDiskTemplate :: Field
1022
pDiskTemplate =
1023
  withDoc "Disk template" $
1024
  simpleField "disk_template" [t| DiskTemplate |]
1025

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

    
1031
pFileStorageDir :: Field
1032
pFileStorageDir =
1033
  withDoc "Directory for storing file-backed disks" $
1034
  optionalNEStringField "file_storage_dir"
1035

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

    
1043
pHypervisor :: Field
1044
pHypervisor =
1045
  withDoc "Selected hypervisor for an instance" .
1046
  optionalField $
1047
  simpleField "hypervisor" [t| Hypervisor |]
1048

    
1049
pResetDefaults :: Field
1050
pResetDefaults =
1051
  withDoc "Reset instance parameters to default if equal" $
1052
  defaultFalse "identify_defaults"
1053

    
1054
pIpCheck :: Field
1055
pIpCheck =
1056
  withDoc "Whether to ensure instance's IP address is inactive" $
1057
  defaultTrue "ip_check"
1058

    
1059
pIpConflictsCheck :: Field
1060
pIpConflictsCheck =
1061
  withDoc "Whether to check for conflicting IP addresses" $
1062
  defaultTrue "conflicts_check"
1063

    
1064
pInstCreateMode :: Field
1065
pInstCreateMode =
1066
  withDoc "Instance creation mode" .
1067
  renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]
1068

    
1069
pInstNics :: Field
1070
pInstNics =
1071
  withDoc "List of NIC (network interface) definitions" $
1072
  simpleField "nics" [t| [INicParams] |]
1073

    
1074
pNoInstall :: Field
1075
pNoInstall =
1076
  withDoc "Do not install the OS (will disable automatic start)" .
1077
  optionalField $ booleanField "no_install"
1078

    
1079
pInstOs :: Field
1080
pInstOs =
1081
  withDoc "OS type for instance installation" $
1082
  optionalNEStringField "os_type"
1083

    
1084
pInstOsParams :: Field
1085
pInstOsParams =
1086
  withDoc "OS parameters for instance" .
1087
  renameField "InstOsParams" .
1088
  defaultField [| toJSObject [] |] $
1089
  simpleField "osparams" [t| JSObject JSValue |]
1090

    
1091
pPrimaryNode :: Field
1092
pPrimaryNode =
1093
  withDoc "Primary node for an instance" $
1094
  optionalNEStringField "pnode"
1095

    
1096
pPrimaryNodeUuid :: Field
1097
pPrimaryNodeUuid =
1098
  withDoc "Primary node UUID for an instance" $
1099
  optionalNEStringField "pnode_uuid"
1100

    
1101
pSecondaryNode :: Field
1102
pSecondaryNode =
1103
  withDoc "Secondary node for an instance" $
1104
  optionalNEStringField "snode"
1105

    
1106
pSecondaryNodeUuid :: Field
1107
pSecondaryNodeUuid =
1108
  withDoc "Secondary node UUID for an instance" $
1109
  optionalNEStringField "snode_uuid"
1110

    
1111
pSourceHandshake :: Field
1112
pSourceHandshake =
1113
  withDoc "Signed handshake from source (remote import only)" .
1114
  optionalField $ simpleField "source_handshake" [t| [JSValue] |]
1115

    
1116
pSourceInstance :: Field
1117
pSourceInstance =
1118
  withDoc "Source instance name (remote import only)" $
1119
  optionalNEStringField "source_instance_name"
1120

    
1121
-- FIXME: non-negative int, whereas the constant is a plain int.
1122
pSourceShutdownTimeout :: Field
1123
pSourceShutdownTimeout =
1124
  withDoc "How long source instance was given to shut down (remote import\
1125
          \ only)" .
1126
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
1127
  simpleField "source_shutdown_timeout" [t| NonNegative Int |]
1128

    
1129
pSourceX509Ca :: Field
1130
pSourceX509Ca =
1131
  withDoc "Source X509 CA in PEM format (remote import only)" $
1132
  optionalNEStringField "source_x509_ca"
1133

    
1134
pSrcNode :: Field
1135
pSrcNode =
1136
  withDoc "Source node for import" $
1137
  optionalNEStringField "src_node"
1138

    
1139
pSrcNodeUuid :: Field
1140
pSrcNodeUuid =
1141
  withDoc "Source node UUID for import" $
1142
  optionalNEStringField "src_node_uuid"
1143

    
1144
pSrcPath :: Field
1145
pSrcPath =
1146
  withDoc "Source directory for import" $
1147
  optionalNEStringField "src_path"
1148

    
1149
pStartInstance :: Field
1150
pStartInstance =
1151
  withDoc "Whether to start instance after creation" $
1152
  defaultTrue "start"
1153

    
1154
-- FIXME: unify/simplify with pTags, once that migrates to NonEmpty String"
1155
pInstTags :: Field
1156
pInstTags =
1157
  withDoc "Instance tags" .
1158
  renameField "InstTags" .
1159
  defaultField [| [] |] $
1160
  simpleField "tags" [t| [NonEmptyString] |]
1161

    
1162
pMultiAllocInstances :: Field
1163
pMultiAllocInstances =
1164
  withDoc "List of instance create opcodes describing the instances to\
1165
          \ allocate" .
1166
  renameField "InstMultiAlloc" .
1167
  defaultField [| [] |] $
1168
  simpleField "instances"[t| [JSValue] |]
1169

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

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

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

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

    
1195
-- | Another name for the shutdown timeout, because we like to be
1196
-- inconsistent.
1197
pShutdownTimeout' :: Field
1198
pShutdownTimeout' =
1199
  withDoc "How long to wait for instance to shut down" .
1200
  renameField "InstShutdownTimeout" .
1201
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
1202
  simpleField "timeout" [t| NonNegative Int |]
1203

    
1204
pIgnoreFailures :: Field
1205
pIgnoreFailures =
1206
  withDoc "Whether to ignore failures during removal" $
1207
  defaultFalse "ignore_failures"
1208

    
1209
pNewName :: Field
1210
pNewName =
1211
  withDoc "New group or instance name" $
1212
  simpleField "new_name" [t| NonEmptyString |]
1213

    
1214
pIgnoreOfflineNodes :: Field
1215
pIgnoreOfflineNodes =
1216
  withDoc "Whether to ignore offline nodes" $
1217
  defaultFalse "ignore_offline_nodes"
1218

    
1219
pTempHvParams :: Field
1220
pTempHvParams =
1221
  withDoc "Temporary hypervisor parameters, hypervisor-dependent" .
1222
  renameField "TempHvParams" .
1223
  defaultField [| toJSObject [] |] $
1224
  simpleField "hvparams" [t| JSObject JSValue |]
1225

    
1226
pTempBeParams :: Field
1227
pTempBeParams =
1228
  withDoc "Temporary backend parameters" .
1229
  renameField "TempBeParams" .
1230
  defaultField [| toJSObject [] |] $
1231
  simpleField "beparams" [t| JSObject JSValue |]
1232

    
1233
pNoRemember :: Field
1234
pNoRemember =
1235
  withDoc "Do not remember instance state changes" $
1236
  defaultFalse "no_remember"
1237

    
1238
pStartupPaused :: Field
1239
pStartupPaused =
1240
  withDoc "Pause instance at startup" $
1241
  defaultFalse "startup_paused"
1242

    
1243
pIgnoreSecondaries :: Field
1244
pIgnoreSecondaries =
1245
  withDoc "Whether to start the instance even if secondary disks are failing" $
1246
  defaultFalse "ignore_secondaries"
1247

    
1248
pRebootType :: Field
1249
pRebootType =
1250
  withDoc "How to reboot the instance" $
1251
  simpleField "reboot_type" [t| RebootType |]
1252

    
1253
pReplaceDisksMode :: Field
1254
pReplaceDisksMode =
1255
  withDoc "Replacement mode" .
1256
  renameField "ReplaceDisksMode" $ simpleField "mode" [t| ReplaceDisksMode |]
1257

    
1258
pReplaceDisksList :: Field
1259
pReplaceDisksList =
1260
  withDoc "List of disk indices" .
1261
  renameField "ReplaceDisksList" .
1262
  defaultField [| [] |] $
1263
  simpleField "disks" [t| [DiskIndex] |]
1264

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

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

    
1275
pMoveTargetNode :: Field
1276
pMoveTargetNode =
1277
  withDoc "Target node for instance move" .
1278
  renameField "MoveTargetNode" $
1279
  simpleField "target_node" [t| NonEmptyString |]
1280

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

    
1287
pMoveCompress :: Field
1288
pMoveCompress =
1289
  withDoc "Compression mode to use during instance moves" .
1290
  defaultField [| None |] $
1291
  simpleField "compress" [t| ImportExportCompression |]
1292

    
1293
pBackupCompress :: Field
1294
pBackupCompress =
1295
  withDoc "Compression mode to use for moves during backups/imports" .
1296
  defaultField [| None |] $
1297
  simpleField "compress" [t| ImportExportCompression |]
1298

    
1299
pIgnoreDiskSize :: Field
1300
pIgnoreDiskSize =
1301
  withDoc "Whether to ignore recorded disk size" $
1302
  defaultFalse "ignore_size"
1303

    
1304
pWaitForSyncFalse :: Field
1305
pWaitForSyncFalse =
1306
  withDoc "Whether to wait for the disk to synchronize (defaults to false)" $
1307
  defaultField [| False |] pWaitForSync
1308

    
1309
pRecreateDisksInfo :: Field
1310
pRecreateDisksInfo =
1311
  withDoc "Disk list for recreate disks" .
1312
  renameField "RecreateDisksInfo" .
1313
  defaultField [| RecreateDisksAll |] $
1314
  simpleField "disks" [t| RecreateDisksInfo |]
1315

    
1316
pStatic :: Field
1317
pStatic =
1318
  withDoc "Whether to only return configuration data without querying nodes" $
1319
  defaultFalse "static"
1320

    
1321
pInstParamsNicChanges :: Field
1322
pInstParamsNicChanges =
1323
  withDoc "List of NIC changes" .
1324
  renameField "InstNicChanges" .
1325
  defaultField [| SetParamsEmpty |] $
1326
  simpleField "nics" [t| SetParamsMods INicParams |]
1327

    
1328
pInstParamsDiskChanges :: Field
1329
pInstParamsDiskChanges =
1330
  withDoc "List of disk changes" .
1331
  renameField "InstDiskChanges" .
1332
  defaultField [| SetParamsEmpty |] $
1333
  simpleField "disks" [t| SetParamsMods IDiskParams |]
1334

    
1335
pRuntimeMem :: Field
1336
pRuntimeMem =
1337
  withDoc "New runtime memory" .
1338
  optionalField $ simpleField "runtime_mem" [t| Positive Int |]
1339

    
1340
pOptDiskTemplate :: Field
1341
pOptDiskTemplate =
1342
  withDoc "Instance disk template" .
1343
  optionalField .
1344
  renameField "OptDiskTemplate" $
1345
  simpleField "disk_template" [t| DiskTemplate |]
1346

    
1347
pOsNameChange :: Field
1348
pOsNameChange =
1349
  withDoc "Change the instance's OS without reinstalling the instance" $
1350
  optionalNEStringField "os_name"
1351

    
1352
pDiskIndex :: Field
1353
pDiskIndex =
1354
  withDoc "Disk index for e.g. grow disk" .
1355
  renameField "DiskIndex " $ simpleField "disk" [t| DiskIndex |]
1356

    
1357
pDiskChgAmount :: Field
1358
pDiskChgAmount =
1359
  withDoc "Disk amount to add or grow to" .
1360
  renameField "DiskChgAmount" $ simpleField "amount" [t| NonNegative Int |]
1361

    
1362
pDiskChgAbsolute :: Field
1363
pDiskChgAbsolute =
1364
  withDoc
1365
    "Whether the amount parameter is an absolute target or a relative one" .
1366
  renameField "DiskChkAbsolute" $ defaultFalse "absolute"
1367

    
1368
pTargetGroups :: Field
1369
pTargetGroups =
1370
  withDoc
1371
    "Destination group names or UUIDs (defaults to \"all but current group\")" .
1372
  optionalField $ simpleField "target_groups" [t| [NonEmptyString] |]
1373

    
1374
pNodeGroupAllocPolicy :: Field
1375
pNodeGroupAllocPolicy =
1376
  withDoc "Instance allocation policy" .
1377
  optionalField $
1378
  simpleField "alloc_policy" [t| AllocPolicy |]
1379

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

    
1385
pExportMode :: Field
1386
pExportMode =
1387
  withDoc "Export mode" .
1388
  renameField "ExportMode" $ simpleField "mode" [t| ExportMode |]
1389

    
1390
-- FIXME: Rename target_node as it changes meaning for different
1391
-- export modes (e.g. "destination")
1392
pExportTargetNode :: Field
1393
pExportTargetNode =
1394
  withDoc "Target node (depends on export mode)" .
1395
  renameField "ExportTarget" $
1396
  simpleField "target_node" [t| ExportTarget |]
1397

    
1398
pExportTargetNodeUuid :: Field
1399
pExportTargetNodeUuid =
1400
  withDoc "Target node UUID (if local export)" .
1401
  renameField "ExportTargetNodeUuid" . optionalField $
1402
  simpleField "target_node_uuid" [t| NonEmptyString |]
1403

    
1404
pShutdownInstance :: Field
1405
pShutdownInstance =
1406
  withDoc "Whether to shutdown the instance before export" $
1407
  defaultTrue "shutdown"
1408

    
1409
pRemoveInstance :: Field
1410
pRemoveInstance =
1411
  withDoc "Whether to remove instance after export" $
1412
  defaultFalse "remove_instance"
1413

    
1414
pIgnoreRemoveFailures :: Field
1415
pIgnoreRemoveFailures =
1416
  withDoc "Whether to ignore failures while removing instances" $
1417
  defaultFalse "ignore_remove_failures"
1418

    
1419
pX509KeyName :: Field
1420
pX509KeyName =
1421
  withDoc "Name of X509 key (remote export only)" .
1422
  optionalField $ simpleField "x509_key_name" [t| [JSValue] |]
1423

    
1424
pX509DestCA :: Field
1425
pX509DestCA =
1426
  withDoc "Destination X509 CA (remote export only)" $
1427
  optionalNEStringField "destination_x509_ca"
1428

    
1429
pTagsObject :: Field
1430
pTagsObject =
1431
  withDoc "Tag kind" $
1432
  simpleField "kind" [t| TagKind |]
1433

    
1434
pTagsName :: Field
1435
pTagsName =
1436
  withDoc "Name of object" .
1437
  renameField "TagsGetName" .
1438
  optionalField $ simpleField "name" [t| String |]
1439

    
1440
pTagsList :: Field
1441
pTagsList =
1442
  withDoc "List of tag names" $
1443
  simpleField "tags" [t| [String] |]
1444

    
1445
-- FIXME: this should be compiled at load time?
1446
pTagSearchPattern :: Field
1447
pTagSearchPattern =
1448
  withDoc "Search pattern (regular expression)" .
1449
  renameField "TagSearchPattern" $
1450
  simpleField "pattern" [t| NonEmptyString |]
1451

    
1452
pDelayDuration :: Field
1453
pDelayDuration =
1454
  withDoc "Duration parameter for 'OpTestDelay'" .
1455
  renameField "DelayDuration" $
1456
  simpleField "duration" [t| Double |]
1457

    
1458
pDelayOnMaster :: Field
1459
pDelayOnMaster =
1460
  withDoc "on_master field for 'OpTestDelay'" .
1461
  renameField "DelayOnMaster" $
1462
  defaultTrue "on_master"
1463

    
1464
pDelayOnNodes :: Field
1465
pDelayOnNodes =
1466
  withDoc "on_nodes field for 'OpTestDelay'" .
1467
  renameField "DelayOnNodes" .
1468
  defaultField [| [] |] $
1469
  simpleField "on_nodes" [t| [NonEmptyString] |]
1470

    
1471
pDelayOnNodeUuids :: Field
1472
pDelayOnNodeUuids =
1473
  withDoc "on_node_uuids field for 'OpTestDelay'" .
1474
  renameField "DelayOnNodeUuids" . optionalField $
1475
  simpleField "on_node_uuids" [t| [NonEmptyString] |]
1476

    
1477
pDelayRepeat :: Field
1478
pDelayRepeat =
1479
  withDoc "Repeat parameter for OpTestDelay" .
1480
  renameField "DelayRepeat" .
1481
  defaultField [| forceNonNeg (0::Int) |] $
1482
  simpleField "repeat" [t| NonNegative Int |]
1483

    
1484
pIAllocatorDirection :: Field
1485
pIAllocatorDirection =
1486
  withDoc "IAllocator test direction" .
1487
  renameField "IAllocatorDirection" $
1488
  simpleField "direction" [t| IAllocatorTestDir |]
1489

    
1490
pIAllocatorMode :: Field
1491
pIAllocatorMode =
1492
  withDoc "IAllocator test mode" .
1493
  renameField "IAllocatorMode" $
1494
  simpleField "mode" [t| IAllocatorMode |]
1495

    
1496
pIAllocatorReqName :: Field
1497
pIAllocatorReqName =
1498
  withDoc "IAllocator target name (new instance, node to evac, etc.)" .
1499
  renameField "IAllocatorReqName" $ simpleField "name" [t| NonEmptyString |]
1500

    
1501
pIAllocatorNics :: Field
1502
pIAllocatorNics =
1503
  withDoc "Custom OpTestIAllocator nics" .
1504
  renameField "IAllocatorNics" .
1505
  optionalField $ simpleField "nics" [t| [INicParams] |]
1506

    
1507
pIAllocatorDisks :: Field
1508
pIAllocatorDisks =
1509
  withDoc "Custom OpTestAllocator disks" .
1510
  renameField "IAllocatorDisks" .
1511
  optionalField $ simpleField "disks" [t| [JSValue] |]
1512

    
1513
pIAllocatorMemory :: Field
1514
pIAllocatorMemory =
1515
  withDoc "IAllocator memory field" .
1516
  renameField "IAllocatorMem" .
1517
  optionalField $
1518
  simpleField "memory" [t| NonNegative Int |]
1519

    
1520
pIAllocatorVCpus :: Field
1521
pIAllocatorVCpus =
1522
  withDoc "IAllocator vcpus field" .
1523
  renameField "IAllocatorVCpus" .
1524
  optionalField $
1525
  simpleField "vcpus" [t| NonNegative Int |]
1526

    
1527
pIAllocatorOs :: Field
1528
pIAllocatorOs =
1529
  withDoc "IAllocator os field" .
1530
  renameField "IAllocatorOs" $ optionalNEStringField "os"
1531

    
1532
pIAllocatorInstances :: Field
1533
pIAllocatorInstances =
1534
  withDoc "IAllocator instances field" .
1535
  renameField "IAllocatorInstances " .
1536
  optionalField $
1537
  simpleField "instances" [t| [NonEmptyString] |]
1538

    
1539
pIAllocatorEvacMode :: Field
1540
pIAllocatorEvacMode =
1541
  withDoc "IAllocator evac mode" .
1542
  renameField "IAllocatorEvacMode" .
1543
  optionalField $
1544
  simpleField "evac_mode" [t| EvacMode |]
1545

    
1546
pIAllocatorSpindleUse :: Field
1547
pIAllocatorSpindleUse =
1548
  withDoc "IAllocator spindle use" .
1549
  renameField "IAllocatorSpindleUse" .
1550
  defaultField [| forceNonNeg (1::Int) |] $
1551
  simpleField "spindle_use" [t| NonNegative Int |]
1552

    
1553
pIAllocatorCount :: Field
1554
pIAllocatorCount =
1555
  withDoc "IAllocator count field" .
1556
  renameField "IAllocatorCount" .
1557
  defaultField [| forceNonNeg (1::Int) |] $
1558
  simpleField "count" [t| NonNegative Int |]
1559

    
1560
pJQueueNotifyWaitLock :: Field
1561
pJQueueNotifyWaitLock =
1562
  withDoc "'OpTestJqueue' notify_waitlock" $
1563
  defaultFalse "notify_waitlock"
1564

    
1565
pJQueueNotifyExec :: Field
1566
pJQueueNotifyExec =
1567
  withDoc "'OpTestJQueue' notify_exec" $
1568
  defaultFalse "notify_exec"
1569

    
1570
pJQueueLogMessages :: Field
1571
pJQueueLogMessages =
1572
  withDoc "'OpTestJQueue' log_messages" .
1573
  defaultField [| [] |] $ simpleField "log_messages" [t| [String] |]
1574

    
1575
pJQueueFail :: Field
1576
pJQueueFail =
1577
  withDoc "'OpTestJQueue' fail attribute" .
1578
  renameField "JQueueFail" $ defaultFalse "fail"
1579

    
1580
pTestDummyResult :: Field
1581
pTestDummyResult =
1582
  withDoc "'OpTestDummy' result field" .
1583
  renameField "TestDummyResult" $ simpleField "result" [t| JSValue |]
1584

    
1585
pTestDummyMessages :: Field
1586
pTestDummyMessages =
1587
  withDoc "'OpTestDummy' messages field" .
1588
  renameField "TestDummyMessages" $
1589
  simpleField "messages" [t| JSValue |]
1590

    
1591
pTestDummyFail :: Field
1592
pTestDummyFail =
1593
  withDoc "'OpTestDummy' fail field" .
1594
  renameField "TestDummyFail" $ simpleField "fail" [t| JSValue |]
1595

    
1596
pTestDummySubmitJobs :: Field
1597
pTestDummySubmitJobs =
1598
  withDoc "'OpTestDummy' submit_jobs field" .
1599
  renameField "TestDummySubmitJobs" $
1600
  simpleField "submit_jobs" [t| JSValue |]
1601

    
1602
pNetworkName :: Field
1603
pNetworkName =
1604
  withDoc "Network name" $
1605
  simpleField "network_name" [t| NonEmptyString |]
1606

    
1607
pNetworkAddress4 :: Field
1608
pNetworkAddress4 =
1609
  withDoc "Network address (IPv4 subnet)" .
1610
  renameField "NetworkAddress4" $
1611
  simpleField "network" [t| IPv4Network |]
1612

    
1613
pNetworkGateway4 :: Field
1614
pNetworkGateway4 =
1615
  withDoc "Network gateway (IPv4 address)" .
1616
  renameField "NetworkGateway4" .
1617
  optionalField $ simpleField "gateway" [t| IPv4Address |]
1618

    
1619
pNetworkAddress6 :: Field
1620
pNetworkAddress6 =
1621
  withDoc "Network address (IPv6 subnet)" .
1622
  renameField "NetworkAddress6" .
1623
  optionalField $ simpleField "network6" [t| IPv6Network |]
1624

    
1625
pNetworkGateway6 :: Field
1626
pNetworkGateway6 =
1627
  withDoc "Network gateway (IPv6 address)" .
1628
  renameField "NetworkGateway6" .
1629
  optionalField $ simpleField "gateway6" [t| IPv6Address |]
1630

    
1631
pNetworkMacPrefix :: Field
1632
pNetworkMacPrefix =
1633
  withDoc "Network specific mac prefix (that overrides the cluster one)" .
1634
  renameField "NetMacPrefix" $
1635
  optionalNEStringField "mac_prefix"
1636

    
1637
pNetworkAddRsvdIps :: Field
1638
pNetworkAddRsvdIps =
1639
  withDoc "Which IP addresses to reserve" .
1640
  renameField "NetworkAddRsvdIps" .
1641
  optionalField $
1642
  simpleField "add_reserved_ips" [t| [IPv4Address] |]
1643

    
1644
pNetworkRemoveRsvdIps :: Field
1645
pNetworkRemoveRsvdIps =
1646
  withDoc "Which external IP addresses to release" .
1647
  renameField "NetworkRemoveRsvdIps" .
1648
  optionalField $
1649
  simpleField "remove_reserved_ips" [t| [IPv4Address] |]
1650

    
1651
pNetworkMode :: Field
1652
pNetworkMode =
1653
  withDoc "Network mode when connecting to a group" $
1654
  simpleField "network_mode" [t| NICMode |]
1655

    
1656
pNetworkLink :: Field
1657
pNetworkLink =
1658
  withDoc "Network link when connecting to a group" $
1659
  simpleField "network_link" [t| NonEmptyString |]