Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / OpParams.hs @ f198cf91

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

    
256
import Control.Monad (liftM)
257
import Text.JSON (JSON, JSValue(..), JSObject (..), readJSON, showJSON,
258
                  fromJSString, toJSObject)
259
import qualified Text.JSON
260
import Text.JSON.Pretty (pp_value)
261

    
262
import Ganeti.BasicTypes
263
import qualified Ganeti.Constants as C
264
import Ganeti.THH
265
import Ganeti.JSON
266
import Ganeti.Types
267
import qualified Ganeti.Query.Language as Qlang
268

    
269
-- * Helper functions and types
270

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

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

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

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

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

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

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

    
304
-- ** Disks
305

    
306
-- | Disk index type (embedding constraints on the index value via a
307
-- smart constructor).
308
newtype DiskIndex = DiskIndex { unDiskIndex :: Int }
309
  deriving (Show, Eq, Ord)
310

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

    
318
instance JSON DiskIndex where
319
  readJSON v = readJSON v >>= mkDiskIndex
320
  showJSON = showJSON . unDiskIndex
321

    
322
-- ** I* param types
323

    
324
-- | Type holding disk access modes.
325
$(declareSADT "DiskAccess"
326
  [ ("DiskReadOnly",  'C.diskRdonly)
327
  , ("DiskReadWrite", 'C.diskRdwr)
328
  ])
329
$(makeJSONInstance ''DiskAccess)
330

    
331
-- | NIC modification definition.
332
$(buildObject "INicParams" "inic"
333
  [ optionalField $ simpleField C.inicMac    [t| NonEmptyString |]
334
  , optionalField $ simpleField C.inicIp     [t| String         |]
335
  , optionalField $ simpleField C.inicMode   [t| NonEmptyString |]
336
  , optionalField $ simpleField C.inicLink   [t| NonEmptyString |]
337
  , optionalField $ simpleField C.inicName   [t| NonEmptyString |]
338
  , optionalField $ simpleField C.inicVlan   [t| NonEmptyString |]
339
  , optionalField $ simpleField C.inicBridge [t| NonEmptyString |]
340
  ])
341

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

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

    
363
readRecreateDisks :: JSValue -> Text.JSON.Result RecreateDisksInfo
364
readRecreateDisks (JSArray []) = return RecreateDisksAll
365
readRecreateDisks v =
366
  case readJSON v::Text.JSON.Result [DiskIndex] of
367
    Text.JSON.Ok indices -> liftM RecreateDisksIndices (mkNonEmpty indices)
368
    _ -> case readJSON v::Text.JSON.Result [(DiskIndex, IDiskParams)] of
369
           Text.JSON.Ok params -> liftM RecreateDisksParams (mkNonEmpty params)
370
           _ -> fail $ "Can't parse disk information as either list of disk"
371
                ++ " indices or list of disk parameters; value received:"
372
                ++ show (pp_value v)
373

    
374
instance JSON RecreateDisksInfo where
375
  readJSON = readRecreateDisks
376
  showJSON  RecreateDisksAll            = showJSON ()
377
  showJSON (RecreateDisksIndices idx)   = showJSON idx
378
  showJSON (RecreateDisksParams params) = showJSON params
379

    
380
-- | Simple type for old-style ddm changes.
381
data DdmOldChanges = DdmOldIndex (NonNegative Int)
382
                   | DdmOldMod DdmSimple
383
                     deriving (Eq, Show)
384

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

    
394
instance JSON DdmOldChanges where
395
  showJSON (DdmOldIndex i) = showJSON i
396
  showJSON (DdmOldMod m)   = showJSON m
397
  readJSON = readDdmOldChanges
398

    
399
-- | Instance disk or nic modifications.
400
data SetParamsMods a
401
  = SetParamsEmpty
402
  | SetParamsDeprecated (NonEmpty (DdmOldChanges, a))
403
  | SetParamsNew (NonEmpty (DdmFull, Int, a))
404
    deriving (Eq, Show)
405

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

    
414
instance (JSON a) => JSON (SetParamsMods a) where
415
  showJSON SetParamsEmpty = showJSON ()
416
  showJSON (SetParamsDeprecated v) = showJSON v
417
  showJSON (SetParamsNew v) = showJSON v
418
  readJSON = readSetParams
419

    
420
-- | Custom type for target_node parameter of OpBackupExport, which
421
-- varies depending on mode. FIXME: this uses an [JSValue] since
422
-- we don't care about individual rows (just like the Python code
423
-- tests). But the proper type could be parsed if we wanted.
424
data ExportTarget = ExportTargetLocal NonEmptyString
425
                  | ExportTargetRemote [JSValue]
426
                    deriving (Eq, Show)
427

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

    
436
instance JSON ExportTarget where
437
  showJSON (ExportTargetLocal s)  = showJSON s
438
  showJSON (ExportTargetRemote l) = showJSON l
439
  readJSON = readExportTarget
440

    
441
-- * Common opcode parameters
442

    
443
pDryRun :: Field
444
pDryRun =
445
  withDoc "Run checks only, don't execute" .
446
  optionalField $ booleanField "dry_run"
447

    
448
pDebugLevel :: Field
449
pDebugLevel =
450
  withDoc "Debug level" .
451
  optionalField $ simpleField "debug_level" [t| NonNegative Int |]
452

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

    
460
pDependencies :: Field
461
pDependencies =
462
  withDoc "Job dependencies" .
463
  optionalNullSerField $ simpleField "depends" [t| [JobDependency] |]
464

    
465
pComment :: Field
466
pComment =
467
  withDoc "Comment field" .
468
  optionalNullSerField $ stringField "comment"
469

    
470
pReason :: Field
471
pReason =
472
  withDoc "Reason trail field" $
473
  simpleField C.opcodeReason [t| ReasonTrail |]
474

    
475
-- * Parameters
476

    
477
pDebugSimulateErrors :: Field
478
pDebugSimulateErrors =
479
  withDoc "Whether to simulate errors (useful for debugging)" $
480
  defaultFalse "debug_simulate_errors"
481

    
482
pErrorCodes :: Field
483
pErrorCodes =
484
  withDoc "Error codes" $
485
  defaultFalse "error_codes"
486

    
487
pSkipChecks :: Field
488
pSkipChecks =
489
  withDoc "Which checks to skip" .
490
  defaultField [| emptyListSet |] $
491
  simpleField "skip_checks" [t| ListSet VerifyOptionalChecks |]
492

    
493
pIgnoreErrors :: Field
494
pIgnoreErrors =
495
  withDoc "List of error codes that should be treated as warnings" .
496
  defaultField [| emptyListSet |] $
497
  simpleField "ignore_errors" [t| ListSet CVErrorCode |]
498

    
499
pVerbose :: Field
500
pVerbose =
501
  withDoc "Verbose mode" $
502
  defaultFalse "verbose"
503

    
504
pOptGroupName :: Field
505
pOptGroupName =
506
  withDoc "Optional group name" .
507
  renameField "OptGroupName" .
508
  optionalField $ simpleField "group_name" [t| NonEmptyString |]
509

    
510
pGroupName :: Field
511
pGroupName =
512
  withDoc "Group name" $
513
  simpleField "group_name" [t| NonEmptyString |]
514

    
515
pInstances :: Field
516
pInstances =
517
  withDoc "List of instances" .
518
  defaultField [| [] |] $
519
  simpleField "instances" [t| [NonEmptyString] |]
520

    
521
pOutputFields :: Field
522
pOutputFields =
523
  withDoc "Selected output fields" $
524
  simpleField "output_fields" [t| [NonEmptyString] |]
525

    
526
pName :: Field
527
pName =
528
  withDoc "A generic name" $
529
  simpleField "name" [t| NonEmptyString |]
530

    
531
pForce :: Field
532
pForce =
533
  withDoc "Whether to force the operation" $
534
  defaultFalse "force"
535

    
536
pHvState :: Field
537
pHvState =
538
  withDoc "Set hypervisor states" .
539
  optionalField $ simpleField "hv_state" [t| JSObject JSValue |]
540

    
541
pDiskState :: Field
542
pDiskState =
543
  withDoc "Set disk states" .
544
  optionalField $ simpleField "disk_state" [t| JSObject JSValue |]
545

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

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

    
558
-- | Volume group name.
559
pVgName :: Field
560
pVgName =
561
  withDoc "Volume group name" $
562
  optionalStringField "vg_name"
563

    
564
pEnabledHypervisors :: Field
565
pEnabledHypervisors =
566
  withDoc "List of enabled hypervisors" .
567
  optionalField $
568
  simpleField "enabled_hypervisors" [t| [Hypervisor] |]
569

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

    
577
pClusterBeParams :: Field
578
pClusterBeParams =
579
  withDoc "Cluster-wide backend parameter defaults" .
580
  renameField "ClusterBeParams" .
581
  optionalField $ simpleField "beparams" [t| JSObject JSValue |]
582

    
583
pOsHvp :: Field
584
pOsHvp =
585
  withDoc "Cluster-wide per-OS hypervisor parameter defaults" .
586
  optionalField $
587
  simpleField "os_hvp" [t| GenericContainer String (JSObject JSValue) |]
588

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

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

    
603
pCandidatePoolSize :: Field
604
pCandidatePoolSize =
605
  withDoc "Master candidate pool size" .
606
  optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]
607

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

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

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

    
626
pMaintainNodeHealth :: Field
627
pMaintainNodeHealth =
628
  withDoc "Whether to automatically maintain node health" .
629
  optionalField $ booleanField "maintain_node_health"
630

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

    
635
-- | Whether to wipe disks before allocating them to instances.
636
pPreallocWipeDisks :: Field
637
pPreallocWipeDisks =
638
  withDoc "Whether to wipe disks before allocating them to instances" .
639
  optionalField $ booleanField "prealloc_wipe_disks"
640

    
641
pNicParams :: Field
642
pNicParams =
643
  withDoc "Cluster-wide NIC parameter defaults" .
644
  optionalField $ simpleField "nicparams" [t| INicParams |]
645

    
646
pIpolicy :: Field
647
pIpolicy =
648
  withDoc "Ipolicy specs" .
649
  optionalField $ simpleField "ipolicy" [t| JSObject JSValue |]
650

    
651
pDrbdHelper :: Field
652
pDrbdHelper =
653
  withDoc "DRBD helper program" $
654
  optionalStringField "drbd_helper"
655

    
656
pDefaultIAllocator :: Field
657
pDefaultIAllocator =
658
  withDoc "Default iallocator for cluster" $
659
  optionalStringField "default_iallocator"
660

    
661
pMasterNetdev :: Field
662
pMasterNetdev =
663
  withDoc "Master network device" $
664
  optionalStringField "master_netdev"
665

    
666
pMasterNetmask :: Field
667
pMasterNetmask =
668
  withDoc "Netmask of the master IP" .
669
  optionalField $ simpleField "master_netmask" [t| NonNegative Int |]
670

    
671
pReservedLvs :: Field
672
pReservedLvs =
673
  withDoc "List of reserved LVs" .
674
  optionalField $ simpleField "reserved_lvs" [t| [NonEmptyString] |]
675

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

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

    
691
pUseExternalMipScript :: Field
692
pUseExternalMipScript =
693
  withDoc "Whether to use an external master IP address setup script" .
694
  optionalField $ booleanField "use_external_mip_script"
695

    
696
pEnabledDiskTemplates :: Field
697
pEnabledDiskTemplates =
698
  withDoc "List of enabled disk templates" .
699
  optionalField $
700
  simpleField "enabled_disk_templates" [t| [DiskTemplate] |]
701

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

    
707
pUseLocking :: Field
708
pUseLocking =
709
  withDoc "Whether to use synchronization" $
710
  defaultFalse "use_locking"
711

    
712
pQueryFields :: Field
713
pQueryFields =
714
  withDoc "Requested fields" $
715
  simpleField "fields" [t| [NonEmptyString] |]
716

    
717
pQueryFilter :: Field
718
pQueryFilter =
719
  withDoc "Query filter" .
720
  optionalField $ simpleField "qfilter" [t| [JSValue] |]
721

    
722
pQueryFieldsFields :: Field
723
pQueryFieldsFields =
724
  withDoc "Requested fields; if not given, all are returned" .
725
  renameField "QueryFieldsFields" $
726
  optionalField pQueryFields
727

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

    
733
pNodeUuids :: Field
734
pNodeUuids =
735
  withDoc "List of node UUIDs" .
736
  optionalField $ simpleField "node_uuids" [t| [NonEmptyString] |]
737

    
738
pOobCommand :: Field
739
pOobCommand =
740
  withDoc "OOB command to run" $
741
  simpleField "command" [t| OobCommand |]
742

    
743
pOobTimeout :: Field
744
pOobTimeout =
745
  withDoc "Timeout before the OOB helper will be terminated" .
746
  defaultField [| C.oobTimeout |] $
747
  simpleField "timeout" [t| Int |]
748

    
749
pIgnoreStatus :: Field
750
pIgnoreStatus =
751
  withDoc "Ignores the node offline status for power off" $
752
  defaultFalse "ignore_status"
753

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

    
763
pRequiredNodes :: Field
764
pRequiredNodes =
765
  withDoc "Required list of node names" .
766
  renameField "ReqNodes " $ simpleField "nodes" [t| [NonEmptyString] |]
767

    
768
pRequiredNodeUuids :: Field
769
pRequiredNodeUuids =
770
  withDoc "Required list of node UUIDs" .
771
  renameField "ReqNodeUuids " . optionalField $
772
  simpleField "node_uuids" [t| [NonEmptyString] |]
773

    
774
pRestrictedCommand :: Field
775
pRestrictedCommand =
776
  withDoc "Restricted command name" .
777
  renameField "RestrictedCommand" $
778
  simpleField "command" [t| NonEmptyString |]
779

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

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

    
790
pPrimaryIp :: Field
791
pPrimaryIp =
792
  withDoc "Primary IP address" .
793
  optionalField $
794
  simpleField "primary_ip" [t| NonEmptyString |]
795

    
796
pSecondaryIp :: Field
797
pSecondaryIp =
798
  withDoc "Secondary IP address" $
799
  optionalNEStringField "secondary_ip"
800

    
801
pReadd :: Field
802
pReadd =
803
  withDoc "Whether node is re-added to cluster" $
804
  defaultFalse "readd"
805

    
806
pNodeGroup :: Field
807
pNodeGroup =
808
  withDoc "Initial node group" $
809
  optionalNEStringField "group"
810

    
811
pMasterCapable :: Field
812
pMasterCapable =
813
  withDoc "Whether node can become master or master candidate" .
814
  optionalField $ booleanField "master_capable"
815

    
816
pVmCapable :: Field
817
pVmCapable =
818
  withDoc "Whether node can host instances" .
819
  optionalField $ booleanField "vm_capable"
820

    
821
pNdParams :: Field
822
pNdParams =
823
  withDoc "Node parameters" .
824
  renameField "genericNdParams" .
825
  optionalField $ simpleField "ndparams" [t| JSObject JSValue |]
826

    
827
pNames :: Field
828
pNames =
829
  withDoc "List of names" .
830
  defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
831

    
832
pNodes :: Field
833
pNodes =
834
  withDoc "List of nodes" .
835
  defaultField [| [] |] $ simpleField "nodes" [t| [NonEmptyString] |]
836

    
837
pStorageType :: Field
838
pStorageType =
839
  withDoc "Storage type" $ simpleField "storage_type" [t| StorageType |]
840

    
841
pStorageTypeOptional :: Field
842
pStorageTypeOptional =
843
  withDoc "Storage type" .
844
  renameField "StorageTypeOptional" .
845
  optionalField $ simpleField "storage_type" [t| StorageType |]
846

    
847
pStorageName :: Field
848
pStorageName =
849
  withDoc "Storage name" .
850
  renameField "StorageName" .
851
  optionalField $ simpleField "name" [t| NonEmptyString |]
852

    
853
pStorageChanges :: Field
854
pStorageChanges =
855
  withDoc "Requested storage changes" $
856
  simpleField "changes" [t| JSObject JSValue |]
857

    
858
pIgnoreConsistency :: Field
859
pIgnoreConsistency =
860
  withDoc "Whether to ignore disk consistency" $
861
  defaultFalse "ignore_consistency"
862

    
863
pMasterCandidate :: Field
864
pMasterCandidate =
865
  withDoc "Whether the node should become a master candidate" .
866
  optionalField $ booleanField "master_candidate"
867

    
868
pOffline :: Field
869
pOffline =
870
  withDoc "Whether to mark the node or instance offline" .
871
  optionalField $ booleanField "offline"
872

    
873
pDrained ::Field
874
pDrained =
875
  withDoc "Whether to mark the node as drained" .
876
  optionalField $ booleanField "drained"
877

    
878
pAutoPromote :: Field
879
pAutoPromote =
880
  withDoc "Whether node(s) should be promoted to master candidate if\
881
          \ necessary" $
882
  defaultFalse "auto_promote"
883

    
884
pPowered :: Field
885
pPowered =
886
  withDoc "Whether the node should be marked as powered" .
887
  optionalField $ booleanField "powered"
888

    
889
pMigrationMode :: Field
890
pMigrationMode =
891
  withDoc "Migration type (live/non-live)" .
892
  renameField "MigrationMode" .
893
  optionalField $
894
  simpleField "mode" [t| MigrationMode |]
895

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

    
901
pMigrationTargetNode :: Field
902
pMigrationTargetNode =
903
  withDoc "Target node for instance migration/failover" $
904
  optionalNEStringField "target_node"
905

    
906
pMigrationTargetNodeUuid :: Field
907
pMigrationTargetNodeUuid =
908
  withDoc "Target node UUID for instance migration/failover" $
909
  optionalNEStringField "target_node_uuid"
910

    
911
pAllowRuntimeChgs :: Field
912
pAllowRuntimeChgs =
913
  withDoc "Whether to allow runtime changes while migrating" $
914
  defaultTrue "allow_runtime_changes"
915

    
916
pIgnoreIpolicy :: Field
917
pIgnoreIpolicy =
918
  withDoc "Whether to ignore ipolicy violations" $
919
  defaultFalse "ignore_ipolicy"
920

    
921
pIallocator :: Field
922
pIallocator =
923
  withDoc "Iallocator for deciding the target node for shared-storage\
924
          \ instances" $
925
  optionalNEStringField "iallocator"
926

    
927
pEarlyRelease :: Field
928
pEarlyRelease =
929
  withDoc "Whether to release locks as soon as possible" $
930
  defaultFalse "early_release"
931

    
932
pRemoteNode :: Field
933
pRemoteNode =
934
  withDoc "New secondary node" $
935
  optionalNEStringField "remote_node"
936

    
937
pRemoteNodeUuid :: Field
938
pRemoteNodeUuid =
939
  withDoc "New secondary node UUID" $
940
  optionalNEStringField "remote_node_uuid"
941

    
942
pEvacMode :: Field
943
pEvacMode =
944
  withDoc "Node evacuation mode" .
945
  renameField "EvacMode" $ simpleField "mode" [t| EvacMode |]
946

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

    
952
pForceVariant :: Field
953
pForceVariant =
954
  withDoc "Whether to force an unknown OS variant" $
955
  defaultFalse "force_variant"
956

    
957
pWaitForSync :: Field
958
pWaitForSync =
959
  withDoc "Whether to wait for the disk to synchronize" $
960
  defaultTrue "wait_for_sync"
961

    
962
pNameCheck :: Field
963
pNameCheck =
964
  withDoc "Whether to check name" $
965
  defaultTrue "name_check"
966

    
967
pInstBeParams :: Field
968
pInstBeParams =
969
  withDoc "Backend parameters for instance" .
970
  renameField "InstBeParams" .
971
  defaultField [| toJSObject [] |] $
972
  simpleField "beparams" [t| JSObject JSValue |]
973

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

    
979
pDiskTemplate :: Field
980
pDiskTemplate =
981
  withDoc "Disk template" $
982
  simpleField "disk_template" [t| DiskTemplate |]
983

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

    
989
pFileStorageDir :: Field
990
pFileStorageDir =
991
  withDoc "Directory for storing file-backed disks" $
992
  optionalNEStringField "file_storage_dir"
993

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

    
1001
pHypervisor :: Field
1002
pHypervisor =
1003
  withDoc "Selected hypervisor for an instance" .
1004
  optionalField $
1005
  simpleField "hypervisor" [t| Hypervisor |]
1006

    
1007
pResetDefaults :: Field
1008
pResetDefaults =
1009
  withDoc "Reset instance parameters to default if equal" $
1010
  defaultFalse "identify_defaults"
1011

    
1012
pIpCheck :: Field
1013
pIpCheck =
1014
  withDoc "Whether to ensure instance's IP address is inactive" $
1015
  defaultTrue "ip_check"
1016

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

    
1022
pInstCreateMode :: Field
1023
pInstCreateMode =
1024
  withDoc "Instance creation mode" .
1025
  renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]
1026

    
1027
pInstNics :: Field
1028
pInstNics =
1029
  withDoc "List of NIC (network interface) definitions" $
1030
  simpleField "nics" [t| [INicParams] |]
1031

    
1032
pNoInstall :: Field
1033
pNoInstall =
1034
  withDoc "Do not install the OS (will disable automatic start)" .
1035
  optionalField $ booleanField "no_install"
1036

    
1037
pInstOs :: Field
1038
pInstOs =
1039
  withDoc "OS type for instance installation" $
1040
  optionalNEStringField "os_type"
1041

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

    
1049
pPrimaryNode :: Field
1050
pPrimaryNode =
1051
  withDoc "Primary node for an instance" $
1052
  optionalNEStringField "pnode"
1053

    
1054
pPrimaryNodeUuid :: Field
1055
pPrimaryNodeUuid =
1056
  withDoc "Primary node UUID for an instance" $
1057
  optionalNEStringField "pnode_uuid"
1058

    
1059
pSecondaryNode :: Field
1060
pSecondaryNode =
1061
  withDoc "Secondary node for an instance" $
1062
  optionalNEStringField "snode"
1063

    
1064
pSecondaryNodeUuid :: Field
1065
pSecondaryNodeUuid =
1066
  withDoc "Secondary node UUID for an instance" $
1067
  optionalNEStringField "snode_uuid"
1068

    
1069
pSourceHandshake :: Field
1070
pSourceHandshake =
1071
  withDoc "Signed handshake from source (remote import only)" .
1072
  optionalField $ simpleField "source_handshake" [t| [JSValue] |]
1073

    
1074
pSourceInstance :: Field
1075
pSourceInstance =
1076
  withDoc "Source instance name (remote import only)" $
1077
  optionalNEStringField "source_instance_name"
1078

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

    
1087
pSourceX509Ca :: Field
1088
pSourceX509Ca =
1089
  withDoc "Source X509 CA in PEM format (remote import only)" $
1090
  optionalNEStringField "source_x509_ca"
1091

    
1092
pSrcNode :: Field
1093
pSrcNode =
1094
  withDoc "Source node for import" $
1095
  optionalNEStringField "src_node"
1096

    
1097
pSrcNodeUuid :: Field
1098
pSrcNodeUuid =
1099
  withDoc "Source node UUID for import" $
1100
  optionalNEStringField "src_node_uuid"
1101

    
1102
pSrcPath :: Field
1103
pSrcPath =
1104
  withDoc "Source directory for import" $
1105
  optionalNEStringField "src_path"
1106

    
1107
pStartInstance :: Field
1108
pStartInstance =
1109
  withDoc "Whether to start instance after creation" $
1110
  defaultTrue "start"
1111

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

    
1120
pMultiAllocInstances :: Field
1121
pMultiAllocInstances =
1122
  withDoc "List of instance create opcodes describing the instances to\
1123
          \ allocate" .
1124
  renameField "InstMultiAlloc" .
1125
  defaultField [| [] |] $
1126
  simpleField "instances"[t| [JSValue] |]
1127

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

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

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

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

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

    
1162
pIgnoreFailures :: Field
1163
pIgnoreFailures =
1164
  withDoc "Whether to ignore failures during removal" $
1165
  defaultFalse "ignore_failures"
1166

    
1167
pNewName :: Field
1168
pNewName =
1169
  withDoc "New group or instance name" $
1170
  simpleField "new_name" [t| NonEmptyString |]
1171

    
1172
pIgnoreOfflineNodes :: Field
1173
pIgnoreOfflineNodes =
1174
  withDoc "Whether to ignore offline nodes" $
1175
  defaultFalse "ignore_offline_nodes"
1176

    
1177
pTempHvParams :: Field
1178
pTempHvParams =
1179
  withDoc "Temporary hypervisor parameters, hypervisor-dependent" .
1180
  renameField "TempHvParams" .
1181
  defaultField [| toJSObject [] |] $
1182
  simpleField "hvparams" [t| JSObject JSValue |]
1183

    
1184
pTempBeParams :: Field
1185
pTempBeParams =
1186
  withDoc "Temporary backend parameters" .
1187
  renameField "TempBeParams" .
1188
  defaultField [| toJSObject [] |] $
1189
  simpleField "beparams" [t| JSObject JSValue |]
1190

    
1191
pNoRemember :: Field
1192
pNoRemember =
1193
  withDoc "Do not remember instance state changes" $
1194
  defaultFalse "no_remember"
1195

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

    
1201
pIgnoreSecondaries :: Field
1202
pIgnoreSecondaries =
1203
  withDoc "Whether to start the instance even if secondary disks are failing" $
1204
  defaultFalse "ignore_secondaries"
1205

    
1206
pRebootType :: Field
1207
pRebootType =
1208
  withDoc "How to reboot the instance" $
1209
  simpleField "reboot_type" [t| RebootType |]
1210

    
1211
pReplaceDisksMode :: Field
1212
pReplaceDisksMode =
1213
  withDoc "Replacement mode" .
1214
  renameField "ReplaceDisksMode" $ simpleField "mode" [t| ReplaceDisksMode |]
1215

    
1216
pReplaceDisksList :: Field
1217
pReplaceDisksList =
1218
  withDoc "List of disk indices" .
1219
  renameField "ReplaceDisksList" .
1220
  defaultField [| [] |] $
1221
  simpleField "disks" [t| [DiskIndex] |]
1222

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

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

    
1233
pMoveTargetNode :: Field
1234
pMoveTargetNode =
1235
  withDoc "Target node for instance move" .
1236
  renameField "MoveTargetNode" $
1237
  simpleField "target_node" [t| NonEmptyString |]
1238

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

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

    
1251
pIgnoreDiskSize :: Field
1252
pIgnoreDiskSize =
1253
  withDoc "Whether to ignore recorded disk size" $
1254
  defaultFalse "ignore_size"
1255

    
1256
pWaitForSyncFalse :: Field
1257
pWaitForSyncFalse =
1258
  withDoc "Whether to wait for the disk to synchronize (defaults to false)" $
1259
  defaultField [| False |] pWaitForSync
1260

    
1261
pRecreateDisksInfo :: Field
1262
pRecreateDisksInfo =
1263
  withDoc "Disk list for recreate disks" .
1264
  renameField "RecreateDisksInfo" .
1265
  defaultField [| RecreateDisksAll |] $
1266
  simpleField "disks" [t| RecreateDisksInfo |]
1267

    
1268
pStatic :: Field
1269
pStatic =
1270
  withDoc "Whether to only return configuration data without querying nodes" $
1271
  defaultFalse "static"
1272

    
1273
pInstParamsNicChanges :: Field
1274
pInstParamsNicChanges =
1275
  withDoc "List of NIC changes" .
1276
  renameField "InstNicChanges" .
1277
  defaultField [| SetParamsEmpty |] $
1278
  simpleField "nics" [t| SetParamsMods INicParams |]
1279

    
1280
pInstParamsDiskChanges :: Field
1281
pInstParamsDiskChanges =
1282
  withDoc "List of disk changes" .
1283
  renameField "InstDiskChanges" .
1284
  defaultField [| SetParamsEmpty |] $
1285
  simpleField "disks" [t| SetParamsMods IDiskParams |]
1286

    
1287
pRuntimeMem :: Field
1288
pRuntimeMem =
1289
  withDoc "New runtime memory" .
1290
  optionalField $ simpleField "runtime_mem" [t| Positive Int |]
1291

    
1292
pOptDiskTemplate :: Field
1293
pOptDiskTemplate =
1294
  withDoc "Instance disk template" .
1295
  optionalField .
1296
  renameField "OptDiskTemplate" $
1297
  simpleField "disk_template" [t| DiskTemplate |]
1298

    
1299
pOsNameChange :: Field
1300
pOsNameChange =
1301
  withDoc "Change the instance's OS without reinstalling the instance" $
1302
  optionalNEStringField "os_name"
1303

    
1304
pDiskIndex :: Field
1305
pDiskIndex =
1306
  withDoc "Disk index for e.g. grow disk" .
1307
  renameField "DiskIndex " $ simpleField "disk" [t| DiskIndex |]
1308

    
1309
pDiskChgAmount :: Field
1310
pDiskChgAmount =
1311
  withDoc "Disk amount to add or grow to" .
1312
  renameField "DiskChgAmount" $ simpleField "amount" [t| NonNegative Int |]
1313

    
1314
pDiskChgAbsolute :: Field
1315
pDiskChgAbsolute =
1316
  withDoc
1317
    "Whether the amount parameter is an absolute target or a relative one" .
1318
  renameField "DiskChkAbsolute" $ defaultFalse "absolute"
1319

    
1320
pTargetGroups :: Field
1321
pTargetGroups =
1322
  withDoc
1323
    "Destination group names or UUIDs (defaults to \"all but current group\")" .
1324
  optionalField $ simpleField "target_groups" [t| [NonEmptyString] |]
1325

    
1326
pNodeGroupAllocPolicy :: Field
1327
pNodeGroupAllocPolicy =
1328
  withDoc "Instance allocation policy" .
1329
  optionalField $
1330
  simpleField "alloc_policy" [t| AllocPolicy |]
1331

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

    
1337
pExportMode :: Field
1338
pExportMode =
1339
  withDoc "Export mode" .
1340
  renameField "ExportMode" $ simpleField "mode" [t| ExportMode |]
1341

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

    
1350
pExportTargetNodeUuid :: Field
1351
pExportTargetNodeUuid =
1352
  withDoc "Target node UUID (if local export)" .
1353
  renameField "ExportTargetNodeUuid" . optionalField $
1354
  simpleField "target_node_uuid" [t| NonEmptyString |]
1355

    
1356
pShutdownInstance :: Field
1357
pShutdownInstance =
1358
  withDoc "Whether to shutdown the instance before export" $
1359
  defaultTrue "shutdown"
1360

    
1361
pRemoveInstance :: Field
1362
pRemoveInstance =
1363
  withDoc "Whether to remove instance after export" $
1364
  defaultFalse "remove_instance"
1365

    
1366
pIgnoreRemoveFailures :: Field
1367
pIgnoreRemoveFailures =
1368
  withDoc "Whether to ignore failures while removing instances" $
1369
  defaultFalse "ignore_remove_failures"
1370

    
1371
pX509KeyName :: Field
1372
pX509KeyName =
1373
  withDoc "Name of X509 key (remote export only)" .
1374
  optionalField $ simpleField "x509_key_name" [t| [JSValue] |]
1375

    
1376
pX509DestCA :: Field
1377
pX509DestCA =
1378
  withDoc "Destination X509 CA (remote export only)" $
1379
  optionalNEStringField "destination_x509_ca"
1380

    
1381
pTagsObject :: Field
1382
pTagsObject =
1383
  withDoc "Tag kind" $
1384
  simpleField "kind" [t| TagKind |]
1385

    
1386
pTagsName :: Field
1387
pTagsName =
1388
  withDoc "Name of object" .
1389
  renameField "TagsGetName" .
1390
  optionalField $ simpleField "name" [t| String |]
1391

    
1392
pTagsList :: Field
1393
pTagsList =
1394
  withDoc "List of tag names" $
1395
  simpleField "tags" [t| [String] |]
1396

    
1397
-- FIXME: this should be compiled at load time?
1398
pTagSearchPattern :: Field
1399
pTagSearchPattern =
1400
  withDoc "Search pattern (regular expression)" .
1401
  renameField "TagSearchPattern" $
1402
  simpleField "pattern" [t| NonEmptyString |]
1403

    
1404
pDelayDuration :: Field
1405
pDelayDuration =
1406
  withDoc "Duration parameter for 'OpTestDelay'" .
1407
  renameField "DelayDuration" $
1408
  simpleField "duration" [t| Double |]
1409

    
1410
pDelayOnMaster :: Field
1411
pDelayOnMaster =
1412
  withDoc "on_master field for 'OpTestDelay'" .
1413
  renameField "DelayOnMaster" $
1414
  defaultTrue "on_master"
1415

    
1416
pDelayOnNodes :: Field
1417
pDelayOnNodes =
1418
  withDoc "on_nodes field for 'OpTestDelay'" .
1419
  renameField "DelayOnNodes" .
1420
  defaultField [| [] |] $
1421
  simpleField "on_nodes" [t| [NonEmptyString] |]
1422

    
1423
pDelayOnNodeUuids :: Field
1424
pDelayOnNodeUuids =
1425
  withDoc "on_node_uuids field for 'OpTestDelay'" .
1426
  renameField "DelayOnNodeUuids" . optionalField $
1427
  simpleField "on_node_uuids" [t| [NonEmptyString] |]
1428

    
1429
pDelayRepeat :: Field
1430
pDelayRepeat =
1431
  withDoc "Repeat parameter for OpTestDelay" .
1432
  renameField "DelayRepeat" .
1433
  defaultField [| forceNonNeg (0::Int) |] $
1434
  simpleField "repeat" [t| NonNegative Int |]
1435

    
1436
pIAllocatorDirection :: Field
1437
pIAllocatorDirection =
1438
  withDoc "IAllocator test direction" .
1439
  renameField "IAllocatorDirection" $
1440
  simpleField "direction" [t| IAllocatorTestDir |]
1441

    
1442
pIAllocatorMode :: Field
1443
pIAllocatorMode =
1444
  withDoc "IAllocator test mode" .
1445
  renameField "IAllocatorMode" $
1446
  simpleField "mode" [t| IAllocatorMode |]
1447

    
1448
pIAllocatorReqName :: Field
1449
pIAllocatorReqName =
1450
  withDoc "IAllocator target name (new instance, node to evac, etc.)" .
1451
  renameField "IAllocatorReqName" $ simpleField "name" [t| NonEmptyString |]
1452

    
1453
pIAllocatorNics :: Field
1454
pIAllocatorNics =
1455
  withDoc "Custom OpTestIAllocator nics" .
1456
  renameField "IAllocatorNics" .
1457
  optionalField $ simpleField "nics" [t| [INicParams] |]
1458

    
1459
pIAllocatorDisks :: Field
1460
pIAllocatorDisks =
1461
  withDoc "Custom OpTestAllocator disks" .
1462
  renameField "IAllocatorDisks" .
1463
  optionalField $ simpleField "disks" [t| [JSValue] |]
1464

    
1465
pIAllocatorMemory :: Field
1466
pIAllocatorMemory =
1467
  withDoc "IAllocator memory field" .
1468
  renameField "IAllocatorMem" .
1469
  optionalField $
1470
  simpleField "memory" [t| NonNegative Int |]
1471

    
1472
pIAllocatorVCpus :: Field
1473
pIAllocatorVCpus =
1474
  withDoc "IAllocator vcpus field" .
1475
  renameField "IAllocatorVCpus" .
1476
  optionalField $
1477
  simpleField "vcpus" [t| NonNegative Int |]
1478

    
1479
pIAllocatorOs :: Field
1480
pIAllocatorOs =
1481
  withDoc "IAllocator os field" .
1482
  renameField "IAllocatorOs" $ optionalNEStringField "os"
1483

    
1484
pIAllocatorInstances :: Field
1485
pIAllocatorInstances =
1486
  withDoc "IAllocator instances field" .
1487
  renameField "IAllocatorInstances " .
1488
  optionalField $
1489
  simpleField "instances" [t| [NonEmptyString] |]
1490

    
1491
pIAllocatorEvacMode :: Field
1492
pIAllocatorEvacMode =
1493
  withDoc "IAllocator evac mode" .
1494
  renameField "IAllocatorEvacMode" .
1495
  optionalField $
1496
  simpleField "evac_mode" [t| EvacMode |]
1497

    
1498
pIAllocatorSpindleUse :: Field
1499
pIAllocatorSpindleUse =
1500
  withDoc "IAllocator spindle use" .
1501
  renameField "IAllocatorSpindleUse" .
1502
  defaultField [| forceNonNeg (1::Int) |] $
1503
  simpleField "spindle_use" [t| NonNegative Int |]
1504

    
1505
pIAllocatorCount :: Field
1506
pIAllocatorCount =
1507
  withDoc "IAllocator count field" .
1508
  renameField "IAllocatorCount" .
1509
  defaultField [| forceNonNeg (1::Int) |] $
1510
  simpleField "count" [t| NonNegative Int |]
1511

    
1512
pJQueueNotifyWaitLock :: Field
1513
pJQueueNotifyWaitLock =
1514
  withDoc "'OpTestJqueue' notify_waitlock" $
1515
  defaultFalse "notify_waitlock"
1516

    
1517
pJQueueNotifyExec :: Field
1518
pJQueueNotifyExec =
1519
  withDoc "'OpTestJQueue' notify_exec" $
1520
  defaultFalse "notify_exec"
1521

    
1522
pJQueueLogMessages :: Field
1523
pJQueueLogMessages =
1524
  withDoc "'OpTestJQueue' log_messages" .
1525
  defaultField [| [] |] $ simpleField "log_messages" [t| [String] |]
1526

    
1527
pJQueueFail :: Field
1528
pJQueueFail =
1529
  withDoc "'OpTestJQueue' fail attribute" .
1530
  renameField "JQueueFail" $ defaultFalse "fail"
1531

    
1532
pTestDummyResult :: Field
1533
pTestDummyResult =
1534
  withDoc "'OpTestDummy' result field" .
1535
  renameField "TestDummyResult" $ simpleField "result" [t| JSValue |]
1536

    
1537
pTestDummyMessages :: Field
1538
pTestDummyMessages =
1539
  withDoc "'OpTestDummy' messages field" .
1540
  renameField "TestDummyMessages" $
1541
  simpleField "messages" [t| JSValue |]
1542

    
1543
pTestDummyFail :: Field
1544
pTestDummyFail =
1545
  withDoc "'OpTestDummy' fail field" .
1546
  renameField "TestDummyFail" $ simpleField "fail" [t| JSValue |]
1547

    
1548
pTestDummySubmitJobs :: Field
1549
pTestDummySubmitJobs =
1550
  withDoc "'OpTestDummy' submit_jobs field" .
1551
  renameField "TestDummySubmitJobs" $
1552
  simpleField "submit_jobs" [t| JSValue |]
1553

    
1554
pNetworkName :: Field
1555
pNetworkName =
1556
  withDoc "Network name" $
1557
  simpleField "network_name" [t| NonEmptyString |]
1558

    
1559
pNetworkAddress4 :: Field
1560
pNetworkAddress4 =
1561
  withDoc "Network address (IPv4 subnet)" .
1562
  renameField "NetworkAddress4" $
1563
  simpleField "network" [t| IPv4Network |]
1564

    
1565
pNetworkGateway4 :: Field
1566
pNetworkGateway4 =
1567
  withDoc "Network gateway (IPv4 address)" .
1568
  renameField "NetworkGateway4" .
1569
  optionalField $ simpleField "gateway" [t| IPv4Address |]
1570

    
1571
pNetworkAddress6 :: Field
1572
pNetworkAddress6 =
1573
  withDoc "Network address (IPv6 subnet)" .
1574
  renameField "NetworkAddress6" .
1575
  optionalField $ simpleField "network6" [t| IPv6Network |]
1576

    
1577
pNetworkGateway6 :: Field
1578
pNetworkGateway6 =
1579
  withDoc "Network gateway (IPv6 address)" .
1580
  renameField "NetworkGateway6" .
1581
  optionalField $ simpleField "gateway6" [t| IPv6Address |]
1582

    
1583
pNetworkMacPrefix :: Field
1584
pNetworkMacPrefix =
1585
  withDoc "Network specific mac prefix (that overrides the cluster one)" .
1586
  renameField "NetMacPrefix" $
1587
  optionalNEStringField "mac_prefix"
1588

    
1589
pNetworkAddRsvdIps :: Field
1590
pNetworkAddRsvdIps =
1591
  withDoc "Which IP addresses to reserve" .
1592
  renameField "NetworkAddRsvdIps" .
1593
  optionalField $
1594
  simpleField "add_reserved_ips" [t| [IPv4Address] |]
1595

    
1596
pNetworkRemoveRsvdIps :: Field
1597
pNetworkRemoveRsvdIps =
1598
  withDoc "Which external IP addresses to release" .
1599
  renameField "NetworkRemoveRsvdIps" .
1600
  optionalField $
1601
  simpleField "remove_reserved_ips" [t| [IPv4Address] |]
1602

    
1603
pNetworkMode :: Field
1604
pNetworkMode =
1605
  withDoc "Network mode when connecting to a group" $
1606
  simpleField "network_mode" [t| NICMode |]
1607

    
1608
pNetworkLink :: Field
1609
pNetworkLink =
1610
  withDoc "Network link when connecting to a group" $
1611
  simpleField "network_link" [t| NonEmptyString |]