Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / OpParams.hs @ 13d26b66

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

    
270
import Control.Monad (liftM, mplus)
271
import Text.JSON (JSON, JSValue(..), JSObject (..), readJSON, showJSON,
272
                  fromJSString, toJSObject)
273
import qualified Text.JSON
274
import Text.JSON.Pretty (pp_value)
275

    
276
import Ganeti.BasicTypes
277
import qualified Ganeti.Constants as C
278
import Ganeti.THH
279
import Ganeti.Utils
280
import Ganeti.JSON
281
import Ganeti.Types
282
import qualified Ganeti.Query.Language as Qlang
283

    
284
-- * Helper functions and types
285

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

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

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

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

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

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

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

    
319
-- ** Disks
320

    
321
-- | Disk index type (embedding constraints on the index value via a
322
-- smart constructor).
323
newtype DiskIndex = DiskIndex { unDiskIndex :: Int }
324
  deriving (Show, Eq, Ord)
325

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

    
333
instance JSON DiskIndex where
334
  readJSON v = readJSON v >>= mkDiskIndex
335
  showJSON = showJSON . unDiskIndex
336

    
337
-- ** I* param types
338

    
339
-- | Type holding disk access modes.
340
$(declareSADT "DiskAccess"
341
  [ ("DiskReadOnly",  'C.diskRdonly)
342
  , ("DiskReadWrite", 'C.diskRdwr)
343
  ])
344
$(makeJSONInstance ''DiskAccess)
345

    
346
-- | NIC modification definition.
347
$(buildObject "INicParams" "inic"
348
  [ optionalField $ simpleField C.inicMac    [t| NonEmptyString |]
349
  , optionalField $ simpleField C.inicIp     [t| String         |]
350
  , optionalField $ simpleField C.inicMode   [t| NonEmptyString |]
351
  , optionalField $ simpleField C.inicLink   [t| NonEmptyString |]
352
  , optionalField $ simpleField C.inicName   [t| NonEmptyString |]
353
  , optionalField $ simpleField C.inicVlan   [t| String         |]
354
  , optionalField $ simpleField C.inicBridge [t| NonEmptyString |]
355
  ])
356

    
357
-- | Disk modification definition.
358
$(buildObject "IDiskParams" "idisk"
359
  [ specialNumericalField 'parseUnitAssumeBinary . optionalField
360
      $ simpleField C.idiskSize               [t| Int            |]
361
  , optionalField $ simpleField C.idiskMode   [t| DiskAccess     |]
362
  , optionalField $ simpleField C.idiskAdopt  [t| NonEmptyString |]
363
  , optionalField $ simpleField C.idiskVg     [t| NonEmptyString |]
364
  , optionalField $ simpleField C.idiskMetavg [t| NonEmptyString |]
365
  , optionalField $ simpleField C.idiskName   [t| NonEmptyString |]
366
  , optionalField $ simpleField C.idiskProvider [t| NonEmptyString |]
367
  , optionalField $ simpleField C.idiskSpindles [t| Int          |]
368
  , andRestArguments "opaque"
369
  ])
370

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

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

    
393
instance JSON RecreateDisksInfo where
394
  readJSON = readRecreateDisks
395
  showJSON  RecreateDisksAll            = showJSON ()
396
  showJSON (RecreateDisksIndices idx)   = showJSON idx
397
  showJSON (RecreateDisksParams params) = showJSON params
398

    
399
-- | Simple type for old-style ddm changes.
400
data DdmOldChanges = DdmOldIndex (NonNegative Int)
401
                   | DdmOldMod DdmSimple
402
                     deriving (Eq, Show)
403

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

    
413
instance JSON DdmOldChanges where
414
  showJSON (DdmOldIndex i) = showJSON i
415
  showJSON (DdmOldMod m)   = showJSON m
416
  readJSON = readDdmOldChanges
417

    
418
-- | Instance disk or nic modifications.
419
data SetParamsMods a
420
  = SetParamsEmpty
421
  | SetParamsDeprecated (NonEmpty (DdmOldChanges, a))
422
  | SetParamsNew (NonEmpty (DdmFull, Int, a))
423
  | SetParamsNewName (NonEmpty (DdmFull, String, a))
424
    deriving (Eq, Show)
425

    
426
-- | Custom deserialiser for 'SetParamsMods'.
427
readSetParams :: (JSON a) => JSValue -> Text.JSON.Result (SetParamsMods a)
428
readSetParams (JSArray []) = return SetParamsEmpty
429
readSetParams v =
430
  liftM SetParamsDeprecated (readJSON v)
431
  `mplus` liftM SetParamsNew (readJSON v)
432
  `mplus` liftM SetParamsNewName (readJSON v)
433

    
434
instance (JSON a) => JSON (SetParamsMods a) where
435
  showJSON SetParamsEmpty = showJSON ()
436
  showJSON (SetParamsDeprecated v) = showJSON v
437
  showJSON (SetParamsNew v) = showJSON v
438
  showJSON (SetParamsNewName v) = showJSON v
439
  readJSON = readSetParams
440

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

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

    
457
instance JSON ExportTarget where
458
  showJSON (ExportTargetLocal s)  = showJSON s
459
  showJSON (ExportTargetRemote l) = showJSON l
460
  readJSON = readExportTarget
461

    
462
-- * Common opcode parameters
463

    
464
pDryRun :: Field
465
pDryRun =
466
  withDoc "Run checks only, don't execute" .
467
  optionalField $ booleanField "dry_run"
468

    
469
pDebugLevel :: Field
470
pDebugLevel =
471
  withDoc "Debug level" .
472
  optionalField $ simpleField "debug_level" [t| NonNegative Int |]
473

    
474
pOpPriority :: Field
475
pOpPriority =
476
  withDoc "Opcode priority. Note: python uses a separate constant,\
477
          \ we're using the actual value we know it's the default" .
478
  defaultField [| OpPrioNormal |] $
479
  simpleField "priority" [t| OpSubmitPriority |]
480

    
481
pDependencies :: Field
482
pDependencies =
483
  withDoc "Job dependencies" .
484
  optionalNullSerField $ simpleField "depends" [t| [JobDependency] |]
485

    
486
pComment :: Field
487
pComment =
488
  withDoc "Comment field" .
489
  optionalNullSerField $ stringField "comment"
490

    
491
pReason :: Field
492
pReason =
493
  withDoc "Reason trail field" $
494
  simpleField C.opcodeReason [t| ReasonTrail |]
495

    
496
-- * Parameters
497

    
498
pDebugSimulateErrors :: Field
499
pDebugSimulateErrors =
500
  withDoc "Whether to simulate errors (useful for debugging)" $
501
  defaultFalse "debug_simulate_errors"
502

    
503
pErrorCodes :: Field
504
pErrorCodes =
505
  withDoc "Error codes" $
506
  defaultFalse "error_codes"
507

    
508
pSkipChecks :: Field
509
pSkipChecks =
510
  withDoc "Which checks to skip" .
511
  defaultField [| emptyListSet |] $
512
  simpleField "skip_checks" [t| ListSet VerifyOptionalChecks |]
513

    
514
pIgnoreErrors :: Field
515
pIgnoreErrors =
516
  withDoc "List of error codes that should be treated as warnings" .
517
  defaultField [| emptyListSet |] $
518
  simpleField "ignore_errors" [t| ListSet CVErrorCode |]
519

    
520
pVerbose :: Field
521
pVerbose =
522
  withDoc "Verbose mode" $
523
  defaultFalse "verbose"
524

    
525
pOptGroupName :: Field
526
pOptGroupName =
527
  withDoc "Optional group name" .
528
  renameField "OptGroupName" .
529
  optionalField $ simpleField "group_name" [t| NonEmptyString |]
530

    
531
pGroupName :: Field
532
pGroupName =
533
  withDoc "Group name" $
534
  simpleField "group_name" [t| NonEmptyString |]
535

    
536
-- | Whether to hotplug device.
537
pHotplug :: Field
538
pHotplug = defaultFalse "hotplug"
539

    
540
pHotplugIfPossible :: Field
541
pHotplugIfPossible = defaultFalse "hotplug_if_possible"
542

    
543
pInstances :: Field
544
pInstances =
545
  withDoc "List of instances" .
546
  defaultField [| [] |] $
547
  simpleField "instances" [t| [NonEmptyString] |]
548

    
549
pOutputFields :: Field
550
pOutputFields =
551
  withDoc "Selected output fields" $
552
  simpleField "output_fields" [t| [NonEmptyString] |]
553

    
554
pName :: Field
555
pName =
556
  withDoc "A generic name" $
557
  simpleField "name" [t| NonEmptyString |]
558

    
559
pForce :: Field
560
pForce =
561
  withDoc "Whether to force the operation" $
562
  defaultFalse "force"
563

    
564
pHvState :: Field
565
pHvState =
566
  withDoc "Set hypervisor states" .
567
  optionalField $ simpleField "hv_state" [t| JSObject JSValue |]
568

    
569
pDiskState :: Field
570
pDiskState =
571
  withDoc "Set disk states" .
572
  optionalField $ simpleField "disk_state" [t| JSObject JSValue |]
573

    
574
-- | Cluster-wide default directory for storing file-backed disks.
575
pClusterFileStorageDir :: Field
576
pClusterFileStorageDir =
577
  renameField "ClusterFileStorageDir" $
578
  optionalStringField "file_storage_dir"
579

    
580
-- | Cluster-wide default directory for storing shared-file-backed disks.
581
pClusterSharedFileStorageDir :: Field
582
pClusterSharedFileStorageDir =
583
  renameField "ClusterSharedFileStorageDir" $
584
  optionalStringField "shared_file_storage_dir"
585

    
586
-- | Cluster-wide default directory for storing Gluster-backed disks.
587
pClusterGlusterStorageDir :: Field
588
pClusterGlusterStorageDir =
589
  renameField "ClusterGlusterStorageDir" $
590
  optionalStringField "gluster_storage_dir"
591

    
592
pInstanceCommunicationNetwork :: Field
593
pInstanceCommunicationNetwork =
594
  optionalStringField "instance_communication_network"
595

    
596
-- | Volume group name.
597
pVgName :: Field
598
pVgName =
599
  withDoc "Volume group name" $
600
  optionalStringField "vg_name"
601

    
602
pEnabledHypervisors :: Field
603
pEnabledHypervisors =
604
  withDoc "List of enabled hypervisors" .
605
  optionalField $
606
  simpleField "enabled_hypervisors" [t| [Hypervisor] |]
607

    
608
pClusterHvParams :: Field
609
pClusterHvParams =
610
  withDoc "Cluster-wide hypervisor parameters, hypervisor-dependent" .
611
  renameField "ClusterHvParams" .
612
  optionalField $
613
  simpleField "hvparams" [t| GenericContainer String (JSObject JSValue) |]
614

    
615
pClusterBeParams :: Field
616
pClusterBeParams =
617
  withDoc "Cluster-wide backend parameter defaults" .
618
  renameField "ClusterBeParams" .
619
  optionalField $ simpleField "beparams" [t| JSObject JSValue |]
620

    
621
pOsHvp :: Field
622
pOsHvp =
623
  withDoc "Cluster-wide per-OS hypervisor parameter defaults" .
624
  optionalField $
625
  simpleField "os_hvp" [t| GenericContainer String (JSObject JSValue) |]
626

    
627
pClusterOsParams :: Field
628
pClusterOsParams =
629
  withDoc "Cluster-wide OS parameter defaults" .
630
  renameField "ClusterOsParams" .
631
  optionalField $
632
  simpleField "osparams" [t| GenericContainer String (JSObject JSValue) |]
633

    
634
pClusterOsParamsPrivate :: Field
635
pClusterOsParamsPrivate =
636
  withDoc "Cluster-wide private OS parameter defaults" .
637
  renameField "ClusterOsParamsPrivate" .
638
  optionalField $
639
  -- This field needs an unique name to aid Python deserialization
640
  simpleField "osparams_private_cluster"
641
    [t| GenericContainer String (JSObject (Private JSValue)) |]
642

    
643
pDiskParams :: Field
644
pDiskParams =
645
  withDoc "Disk templates' parameter defaults" .
646
  optionalField $
647
  simpleField "diskparams"
648
              [t| GenericContainer DiskTemplate (JSObject JSValue) |]
649

    
650
pCandidatePoolSize :: Field
651
pCandidatePoolSize =
652
  withDoc "Master candidate pool size" .
653
  optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]
654

    
655
pMaxRunningJobs :: Field
656
pMaxRunningJobs =
657
  withDoc "Maximal number of jobs to run simultaneously" .
658
  optionalField $ simpleField "max_running_jobs" [t| Positive Int |]
659

    
660
pUidPool :: Field
661
pUidPool =
662
  withDoc "Set UID pool, must be list of lists describing UID ranges\
663
          \ (two items, start and end inclusive)" .
664
  optionalField $ simpleField "uid_pool" [t| [(Int, Int)] |]
665

    
666
pAddUids :: Field
667
pAddUids =
668
  withDoc "Extend UID pool, must be list of lists describing UID\
669
          \ ranges (two items, start and end inclusive)" .
670
  optionalField $ simpleField "add_uids" [t| [(Int, Int)] |]
671

    
672
pRemoveUids :: Field
673
pRemoveUids =
674
  withDoc "Shrink UID pool, must be list of lists describing UID\
675
          \ ranges (two items, start and end inclusive) to be removed" .
676
  optionalField $ simpleField "remove_uids" [t| [(Int, Int)] |]
677

    
678
pMaintainNodeHealth :: Field
679
pMaintainNodeHealth =
680
  withDoc "Whether to automatically maintain node health" .
681
  optionalField $ booleanField "maintain_node_health"
682

    
683
-- | Whether to modify and keep in sync the @/etc/hosts@ files of nodes.
684
pModifyEtcHosts :: Field
685
pModifyEtcHosts = optionalField $ booleanField "modify_etc_hosts"
686

    
687
-- | Whether to wipe disks before allocating them to instances.
688
pPreallocWipeDisks :: Field
689
pPreallocWipeDisks =
690
  withDoc "Whether to wipe disks before allocating them to instances" .
691
  optionalField $ booleanField "prealloc_wipe_disks"
692

    
693
pNicParams :: Field
694
pNicParams =
695
  withDoc "Cluster-wide NIC parameter defaults" .
696
  optionalField $ simpleField "nicparams" [t| INicParams |]
697

    
698
pIpolicy :: Field
699
pIpolicy =
700
  withDoc "Ipolicy specs" .
701
  optionalField $ simpleField "ipolicy" [t| JSObject JSValue |]
702

    
703
pDrbdHelper :: Field
704
pDrbdHelper =
705
  withDoc "DRBD helper program" $
706
  optionalStringField "drbd_helper"
707

    
708
pDefaultIAllocator :: Field
709
pDefaultIAllocator =
710
  withDoc "Default iallocator for cluster" $
711
  optionalStringField "default_iallocator"
712

    
713
pDefaultIAllocatorParams :: Field
714
pDefaultIAllocatorParams =
715
  withDoc "Default iallocator parameters for cluster" . optionalField
716
    $ simpleField "default_iallocator_params" [t| JSObject JSValue |]
717

    
718
pMasterNetdev :: Field
719
pMasterNetdev =
720
  withDoc "Master network device" $
721
  optionalStringField "master_netdev"
722

    
723
pMasterNetmask :: Field
724
pMasterNetmask =
725
  withDoc "Netmask of the master IP" .
726
  optionalField $ simpleField "master_netmask" [t| NonNegative Int |]
727

    
728
pReservedLvs :: Field
729
pReservedLvs =
730
  withDoc "List of reserved LVs" .
731
  optionalField $ simpleField "reserved_lvs" [t| [NonEmptyString] |]
732

    
733
pHiddenOs :: Field
734
pHiddenOs =
735
  withDoc "Modify list of hidden operating systems: each modification\
736
          \ must have two items, the operation and the OS name; the operation\
737
          \ can be add or remove" .
738
  optionalField $ simpleField "hidden_os" [t| [(DdmSimple, NonEmptyString)] |]
739

    
740
pBlacklistedOs :: Field
741
pBlacklistedOs =
742
  withDoc "Modify list of blacklisted operating systems: each\
743
          \ modification must have two items, the operation and the OS name;\
744
          \ the operation can be add or remove" .
745
  optionalField $
746
  simpleField "blacklisted_os" [t| [(DdmSimple, NonEmptyString)] |]
747

    
748
pUseExternalMipScript :: Field
749
pUseExternalMipScript =
750
  withDoc "Whether to use an external master IP address setup script" .
751
  optionalField $ booleanField "use_external_mip_script"
752

    
753
pEnabledDiskTemplates :: Field
754
pEnabledDiskTemplates =
755
  withDoc "List of enabled disk templates" .
756
  optionalField $
757
  simpleField "enabled_disk_templates" [t| [DiskTemplate] |]
758

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

    
764
pUseLocking :: Field
765
pUseLocking =
766
  withDoc "Whether to use synchronization" $
767
  defaultFalse "use_locking"
768

    
769
pQueryFields :: Field
770
pQueryFields =
771
  withDoc "Requested fields" $
772
  simpleField "fields" [t| [NonEmptyString] |]
773

    
774
pQueryFilter :: Field
775
pQueryFilter =
776
  withDoc "Query filter" .
777
  optionalField $ simpleField "qfilter" [t| [JSValue] |]
778

    
779
pQueryFieldsFields :: Field
780
pQueryFieldsFields =
781
  withDoc "Requested fields; if not given, all are returned" .
782
  renameField "QueryFieldsFields" $
783
  optionalField pQueryFields
784

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

    
790
pNodeUuids :: Field
791
pNodeUuids =
792
  withDoc "List of node UUIDs" .
793
  optionalField $ simpleField "node_uuids" [t| [NonEmptyString] |]
794

    
795
pOobCommand :: Field
796
pOobCommand =
797
  withDoc "OOB command to run" $
798
  simpleField "command" [t| OobCommand |]
799

    
800
pOobTimeout :: Field
801
pOobTimeout =
802
  withDoc "Timeout before the OOB helper will be terminated" .
803
  defaultField [| C.oobTimeout |] $
804
  simpleField "timeout" [t| Int |]
805

    
806
pIgnoreStatus :: Field
807
pIgnoreStatus =
808
  withDoc "Ignores the node offline status for power off" $
809
  defaultFalse "ignore_status"
810

    
811
pPowerDelay :: Field
812
pPowerDelay =
813
  -- FIXME: we can't use the proper type "NonNegative Double", since
814
  -- the default constant is a plain Double, not a non-negative one.
815
  -- And trying to fix the constant introduces a cyclic import.
816
  withDoc "Time in seconds to wait between powering on nodes" .
817
  defaultField [| C.oobPowerDelay |] $
818
  simpleField "power_delay" [t| Double |]
819

    
820
pRequiredNodes :: Field
821
pRequiredNodes =
822
  withDoc "Required list of node names" .
823
  renameField "ReqNodes " $ simpleField "nodes" [t| [NonEmptyString] |]
824

    
825
pRequiredNodeUuids :: Field
826
pRequiredNodeUuids =
827
  withDoc "Required list of node UUIDs" .
828
  renameField "ReqNodeUuids " . optionalField $
829
  simpleField "node_uuids" [t| [NonEmptyString] |]
830

    
831
pRestrictedCommand :: Field
832
pRestrictedCommand =
833
  withDoc "Restricted command name" .
834
  renameField "RestrictedCommand" $
835
  simpleField "command" [t| NonEmptyString |]
836

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

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

    
847
pPrimaryIp :: Field
848
pPrimaryIp =
849
  withDoc "Primary IP address" .
850
  optionalField $
851
  simpleField "primary_ip" [t| NonEmptyString |]
852

    
853
pSecondaryIp :: Field
854
pSecondaryIp =
855
  withDoc "Secondary IP address" $
856
  optionalNEStringField "secondary_ip"
857

    
858
pReadd :: Field
859
pReadd =
860
  withDoc "Whether node is re-added to cluster" $
861
  defaultFalse "readd"
862

    
863
pNodeGroup :: Field
864
pNodeGroup =
865
  withDoc "Initial node group" $
866
  optionalNEStringField "group"
867

    
868
pMasterCapable :: Field
869
pMasterCapable =
870
  withDoc "Whether node can become master or master candidate" .
871
  optionalField $ booleanField "master_capable"
872

    
873
pVmCapable :: Field
874
pVmCapable =
875
  withDoc "Whether node can host instances" .
876
  optionalField $ booleanField "vm_capable"
877

    
878
pNdParams :: Field
879
pNdParams =
880
  withDoc "Node parameters" .
881
  renameField "genericNdParams" .
882
  optionalField $ simpleField "ndparams" [t| JSObject JSValue |]
883

    
884
pNames :: Field
885
pNames =
886
  withDoc "List of names" .
887
  defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
888

    
889
pNodes :: Field
890
pNodes =
891
  withDoc "List of nodes" .
892
  defaultField [| [] |] $ simpleField "nodes" [t| [NonEmptyString] |]
893

    
894
pStorageType :: Field
895
pStorageType =
896
  withDoc "Storage type" $ simpleField "storage_type" [t| StorageType |]
897

    
898
pOptStorageType :: Field
899
pOptStorageType =
900
  withDoc "Storage type" .
901
  renameField "OptStorageType" .
902
  optionalField $ simpleField "storage_type" [t| StorageType |]
903

    
904
pStorageName :: Field
905
pStorageName =
906
  withDoc "Storage name" .
907
  renameField "StorageName" .
908
  optionalField $ simpleField "name" [t| NonEmptyString |]
909

    
910
pStorageChanges :: Field
911
pStorageChanges =
912
  withDoc "Requested storage changes" $
913
  simpleField "changes" [t| JSObject JSValue |]
914

    
915
pIgnoreConsistency :: Field
916
pIgnoreConsistency =
917
  withDoc "Whether to ignore disk consistency" $
918
  defaultFalse "ignore_consistency"
919

    
920
pMasterCandidate :: Field
921
pMasterCandidate =
922
  withDoc "Whether the node should become a master candidate" .
923
  optionalField $ booleanField "master_candidate"
924

    
925
pOffline :: Field
926
pOffline =
927
  withDoc "Whether to mark the node or instance offline" .
928
  optionalField $ booleanField "offline"
929

    
930
pDrained ::Field
931
pDrained =
932
  withDoc "Whether to mark the node as drained" .
933
  optionalField $ booleanField "drained"
934

    
935
pAutoPromote :: Field
936
pAutoPromote =
937
  withDoc "Whether node(s) should be promoted to master candidate if\
938
          \ necessary" $
939
  defaultFalse "auto_promote"
940

    
941
pPowered :: Field
942
pPowered =
943
  withDoc "Whether the node should be marked as powered" .
944
  optionalField $ booleanField "powered"
945

    
946
pMigrationMode :: Field
947
pMigrationMode =
948
  withDoc "Migration type (live/non-live)" .
949
  renameField "MigrationMode" .
950
  optionalField $
951
  simpleField "mode" [t| MigrationMode |]
952

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

    
958
pMigrationTargetNode :: Field
959
pMigrationTargetNode =
960
  withDoc "Target node for instance migration/failover" $
961
  optionalNEStringField "target_node"
962

    
963
pMigrationTargetNodeUuid :: Field
964
pMigrationTargetNodeUuid =
965
  withDoc "Target node UUID for instance migration/failover" $
966
  optionalNEStringField "target_node_uuid"
967

    
968
pAllowRuntimeChgs :: Field
969
pAllowRuntimeChgs =
970
  withDoc "Whether to allow runtime changes while migrating" $
971
  defaultTrue "allow_runtime_changes"
972

    
973
pIgnoreIpolicy :: Field
974
pIgnoreIpolicy =
975
  withDoc "Whether to ignore ipolicy violations" $
976
  defaultFalse "ignore_ipolicy"
977

    
978
pIallocator :: Field
979
pIallocator =
980
  withDoc "Iallocator for deciding the target node for shared-storage\
981
          \ instances" $
982
  optionalNEStringField "iallocator"
983

    
984
pEarlyRelease :: Field
985
pEarlyRelease =
986
  withDoc "Whether to release locks as soon as possible" $
987
  defaultFalse "early_release"
988

    
989
pRemoteNode :: Field
990
pRemoteNode =
991
  withDoc "New secondary node" $
992
  optionalNEStringField "remote_node"
993

    
994
pRemoteNodeUuid :: Field
995
pRemoteNodeUuid =
996
  withDoc "New secondary node UUID" $
997
  optionalNEStringField "remote_node_uuid"
998

    
999
pEvacMode :: Field
1000
pEvacMode =
1001
  withDoc "Node evacuation mode" .
1002
  renameField "EvacMode" $ simpleField "mode" [t| EvacMode |]
1003

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

    
1009
pInstanceCommunication :: Field
1010
pInstanceCommunication =
1011
  withDoc C.instanceCommunicationDoc $
1012
  defaultFalse "instance_communication"
1013

    
1014
pOptInstanceCommunication :: Field
1015
pOptInstanceCommunication =
1016
  withDoc C.instanceCommunicationDoc .
1017
  renameField "OptInstanceCommunication" .
1018
  optionalField $
1019
  booleanField "instance_communication"
1020

    
1021
pForceVariant :: Field
1022
pForceVariant =
1023
  withDoc "Whether to force an unknown OS variant" $
1024
  defaultFalse "force_variant"
1025

    
1026
pWaitForSync :: Field
1027
pWaitForSync =
1028
  withDoc "Whether to wait for the disk to synchronize" $
1029
  defaultTrue "wait_for_sync"
1030

    
1031
pNameCheck :: Field
1032
pNameCheck =
1033
  withDoc "Whether to check name" $
1034
  defaultTrue "name_check"
1035

    
1036
pInstBeParams :: Field
1037
pInstBeParams =
1038
  withDoc "Backend parameters for instance" .
1039
  renameField "InstBeParams" .
1040
  defaultField [| toJSObject [] |] $
1041
  simpleField "beparams" [t| JSObject JSValue |]
1042

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

    
1048
pDiskTemplate :: Field
1049
pDiskTemplate =
1050
  withDoc "Disk template" $
1051
  simpleField "disk_template" [t| DiskTemplate |]
1052

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

    
1058
pFileStorageDir :: Field
1059
pFileStorageDir =
1060
  withDoc "Directory for storing file-backed disks" $
1061
  optionalNEStringField "file_storage_dir"
1062

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

    
1070
pHypervisor :: Field
1071
pHypervisor =
1072
  withDoc "Selected hypervisor for an instance" .
1073
  optionalField $
1074
  simpleField "hypervisor" [t| Hypervisor |]
1075

    
1076
pResetDefaults :: Field
1077
pResetDefaults =
1078
  withDoc "Reset instance parameters to default if equal" $
1079
  defaultFalse "identify_defaults"
1080

    
1081
pIpCheck :: Field
1082
pIpCheck =
1083
  withDoc "Whether to ensure instance's IP address is inactive" $
1084
  defaultTrue "ip_check"
1085

    
1086
pIpConflictsCheck :: Field
1087
pIpConflictsCheck =
1088
  withDoc "Whether to check for conflicting IP addresses" $
1089
  defaultTrue "conflicts_check"
1090

    
1091
pInstCreateMode :: Field
1092
pInstCreateMode =
1093
  withDoc "Instance creation mode" .
1094
  renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]
1095

    
1096
pInstNics :: Field
1097
pInstNics =
1098
  withDoc "List of NIC (network interface) definitions" $
1099
  simpleField "nics" [t| [INicParams] |]
1100

    
1101
pNoInstall :: Field
1102
pNoInstall =
1103
  withDoc "Do not install the OS (will disable automatic start)" .
1104
  optionalField $ booleanField "no_install"
1105

    
1106
pInstOs :: Field
1107
pInstOs =
1108
  withDoc "OS type for instance installation" $
1109
  optionalNEStringField "os_type"
1110

    
1111
pInstOsParams :: Field
1112
pInstOsParams =
1113
  withDoc "OS parameters for instance" .
1114
  renameField "InstOsParams" .
1115
  defaultField [| toJSObject [] |] $
1116
  simpleField "osparams" [t| JSObject JSValue |]
1117

    
1118
pInstOsParamsPrivate :: Field
1119
pInstOsParamsPrivate =
1120
  withDoc "Private OS parameters for instance" .
1121
  optionalField $
1122
  simpleField "osparams_private" [t| JSObject (Private JSValue) |]
1123

    
1124
pInstOsParamsSecret :: Field
1125
pInstOsParamsSecret =
1126
  withDoc "Secret OS parameters for instance" .
1127
  optionalField $
1128
  simpleField "osparams_secret" [t| JSObject (Private JSValue) |]
1129

    
1130
pPrimaryNode :: Field
1131
pPrimaryNode =
1132
  withDoc "Primary node for an instance" $
1133
  optionalNEStringField "pnode"
1134

    
1135
pPrimaryNodeUuid :: Field
1136
pPrimaryNodeUuid =
1137
  withDoc "Primary node UUID for an instance" $
1138
  optionalNEStringField "pnode_uuid"
1139

    
1140
pSecondaryNode :: Field
1141
pSecondaryNode =
1142
  withDoc "Secondary node for an instance" $
1143
  optionalNEStringField "snode"
1144

    
1145
pSecondaryNodeUuid :: Field
1146
pSecondaryNodeUuid =
1147
  withDoc "Secondary node UUID for an instance" $
1148
  optionalNEStringField "snode_uuid"
1149

    
1150
pSourceHandshake :: Field
1151
pSourceHandshake =
1152
  withDoc "Signed handshake from source (remote import only)" .
1153
  optionalField $ simpleField "source_handshake" [t| [JSValue] |]
1154

    
1155
pSourceInstance :: Field
1156
pSourceInstance =
1157
  withDoc "Source instance name (remote import only)" $
1158
  optionalNEStringField "source_instance_name"
1159

    
1160
-- FIXME: non-negative int, whereas the constant is a plain int.
1161
pSourceShutdownTimeout :: Field
1162
pSourceShutdownTimeout =
1163
  withDoc "How long source instance was given to shut down (remote import\
1164
          \ only)" .
1165
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
1166
  simpleField "source_shutdown_timeout" [t| NonNegative Int |]
1167

    
1168
pSourceX509Ca :: Field
1169
pSourceX509Ca =
1170
  withDoc "Source X509 CA in PEM format (remote import only)" $
1171
  optionalNEStringField "source_x509_ca"
1172

    
1173
pSrcNode :: Field
1174
pSrcNode =
1175
  withDoc "Source node for import" $
1176
  optionalNEStringField "src_node"
1177

    
1178
pSrcNodeUuid :: Field
1179
pSrcNodeUuid =
1180
  withDoc "Source node UUID for import" $
1181
  optionalNEStringField "src_node_uuid"
1182

    
1183
pSrcPath :: Field
1184
pSrcPath =
1185
  withDoc "Source directory for import" $
1186
  optionalNEStringField "src_path"
1187

    
1188
pStartInstance :: Field
1189
pStartInstance =
1190
  withDoc "Whether to start instance after creation" $
1191
  defaultTrue "start"
1192

    
1193
-- FIXME: unify/simplify with pTags, once that migrates to NonEmpty String"
1194
pInstTags :: Field
1195
pInstTags =
1196
  withDoc "Instance tags" .
1197
  renameField "InstTags" .
1198
  defaultField [| [] |] $
1199
  simpleField "tags" [t| [NonEmptyString] |]
1200

    
1201
pMultiAllocInstances :: Field
1202
pMultiAllocInstances =
1203
  withDoc "List of instance create opcodes describing the instances to\
1204
          \ allocate" .
1205
  renameField "InstMultiAlloc" .
1206
  defaultField [| [] |] $
1207
  simpleField "instances"[t| [JSValue] |]
1208

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

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

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

    
1228
pTempOsParamsPrivate :: Field
1229
pTempOsParamsPrivate =
1230
  withDoc "Private OS parameters for instance reinstalls" .
1231
  optionalField $
1232
  simpleField "osparams_private" [t| JSObject (Private JSValue) |]
1233

    
1234
pTempOsParamsSecret :: Field
1235
pTempOsParamsSecret =
1236
  withDoc "Secret OS parameters for instance reinstalls" .
1237
  optionalField $
1238
  simpleField "osparams_secret" [t| JSObject (Private JSValue) |]
1239

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

    
1246
-- | Another name for the shutdown timeout, because we like to be
1247
-- inconsistent.
1248
pShutdownTimeout' :: Field
1249
pShutdownTimeout' =
1250
  withDoc "How long to wait for instance to shut down" .
1251
  renameField "InstShutdownTimeout" .
1252
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
1253
  simpleField "timeout" [t| NonNegative Int |]
1254

    
1255
pIgnoreFailures :: Field
1256
pIgnoreFailures =
1257
  withDoc "Whether to ignore failures during removal" $
1258
  defaultFalse "ignore_failures"
1259

    
1260
pNewName :: Field
1261
pNewName =
1262
  withDoc "New group or instance name" $
1263
  simpleField "new_name" [t| NonEmptyString |]
1264

    
1265
pIgnoreOfflineNodes :: Field
1266
pIgnoreOfflineNodes =
1267
  withDoc "Whether to ignore offline nodes" $
1268
  defaultFalse "ignore_offline_nodes"
1269

    
1270
pTempHvParams :: Field
1271
pTempHvParams =
1272
  withDoc "Temporary hypervisor parameters, hypervisor-dependent" .
1273
  renameField "TempHvParams" .
1274
  defaultField [| toJSObject [] |] $
1275
  simpleField "hvparams" [t| JSObject JSValue |]
1276

    
1277
pTempBeParams :: Field
1278
pTempBeParams =
1279
  withDoc "Temporary backend parameters" .
1280
  renameField "TempBeParams" .
1281
  defaultField [| toJSObject [] |] $
1282
  simpleField "beparams" [t| JSObject JSValue |]
1283

    
1284
pNoRemember :: Field
1285
pNoRemember =
1286
  withDoc "Do not remember instance state changes" $
1287
  defaultFalse "no_remember"
1288

    
1289
pStartupPaused :: Field
1290
pStartupPaused =
1291
  withDoc "Pause instance at startup" $
1292
  defaultFalse "startup_paused"
1293

    
1294
pIgnoreSecondaries :: Field
1295
pIgnoreSecondaries =
1296
  withDoc "Whether to start the instance even if secondary disks are failing" $
1297
  defaultFalse "ignore_secondaries"
1298

    
1299
pRebootType :: Field
1300
pRebootType =
1301
  withDoc "How to reboot the instance" $
1302
  simpleField "reboot_type" [t| RebootType |]
1303

    
1304
pReplaceDisksMode :: Field
1305
pReplaceDisksMode =
1306
  withDoc "Replacement mode" .
1307
  renameField "ReplaceDisksMode" $ simpleField "mode" [t| ReplaceDisksMode |]
1308

    
1309
pReplaceDisksList :: Field
1310
pReplaceDisksList =
1311
  withDoc "List of disk indices" .
1312
  renameField "ReplaceDisksList" .
1313
  defaultField [| [] |] $
1314
  simpleField "disks" [t| [DiskIndex] |]
1315

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

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

    
1326
pMoveTargetNode :: Field
1327
pMoveTargetNode =
1328
  withDoc "Target node for instance move" .
1329
  renameField "MoveTargetNode" $
1330
  simpleField "target_node" [t| NonEmptyString |]
1331

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

    
1338
pMoveCompress :: Field
1339
pMoveCompress =
1340
  withDoc "Compression mode to use during instance moves" .
1341
  defaultField [| None |] $
1342
  simpleField "compress" [t| ImportExportCompression |]
1343

    
1344
pBackupCompress :: Field
1345
pBackupCompress =
1346
  withDoc "Compression mode to use for moves during backups/imports" .
1347
  defaultField [| None |] $
1348
  simpleField "compress" [t| ImportExportCompression |]
1349

    
1350
pIgnoreDiskSize :: Field
1351
pIgnoreDiskSize =
1352
  withDoc "Whether to ignore recorded disk size" $
1353
  defaultFalse "ignore_size"
1354

    
1355
pWaitForSyncFalse :: Field
1356
pWaitForSyncFalse =
1357
  withDoc "Whether to wait for the disk to synchronize (defaults to false)" $
1358
  defaultField [| False |] pWaitForSync
1359

    
1360
pRecreateDisksInfo :: Field
1361
pRecreateDisksInfo =
1362
  withDoc "Disk list for recreate disks" .
1363
  renameField "RecreateDisksInfo" .
1364
  defaultField [| RecreateDisksAll |] $
1365
  simpleField "disks" [t| RecreateDisksInfo |]
1366

    
1367
pStatic :: Field
1368
pStatic =
1369
  withDoc "Whether to only return configuration data without querying nodes" $
1370
  defaultFalse "static"
1371

    
1372
pInstParamsNicChanges :: Field
1373
pInstParamsNicChanges =
1374
  withDoc "List of NIC changes" .
1375
  renameField "InstNicChanges" .
1376
  defaultField [| SetParamsEmpty |] $
1377
  simpleField "nics" [t| SetParamsMods INicParams |]
1378

    
1379
pInstParamsDiskChanges :: Field
1380
pInstParamsDiskChanges =
1381
  withDoc "List of disk changes" .
1382
  renameField "InstDiskChanges" .
1383
  defaultField [| SetParamsEmpty |] $
1384
  simpleField "disks" [t| SetParamsMods IDiskParams |]
1385

    
1386
pRuntimeMem :: Field
1387
pRuntimeMem =
1388
  withDoc "New runtime memory" .
1389
  optionalField $ simpleField "runtime_mem" [t| Positive Int |]
1390

    
1391
pOptDiskTemplate :: Field
1392
pOptDiskTemplate =
1393
  withDoc "Instance disk template" .
1394
  optionalField .
1395
  renameField "OptDiskTemplate" $
1396
  simpleField "disk_template" [t| DiskTemplate |]
1397

    
1398
pOsNameChange :: Field
1399
pOsNameChange =
1400
  withDoc "Change the instance's OS without reinstalling the instance" $
1401
  optionalNEStringField "os_name"
1402

    
1403
pDiskIndex :: Field
1404
pDiskIndex =
1405
  withDoc "Disk index for e.g. grow disk" .
1406
  renameField "DiskIndex " $ simpleField "disk" [t| DiskIndex |]
1407

    
1408
pDiskChgAmount :: Field
1409
pDiskChgAmount =
1410
  withDoc "Disk amount to add or grow to" .
1411
  renameField "DiskChgAmount" $ simpleField "amount" [t| NonNegative Int |]
1412

    
1413
pDiskChgAbsolute :: Field
1414
pDiskChgAbsolute =
1415
  withDoc
1416
    "Whether the amount parameter is an absolute target or a relative one" .
1417
  renameField "DiskChkAbsolute" $ defaultFalse "absolute"
1418

    
1419
pTargetGroups :: Field
1420
pTargetGroups =
1421
  withDoc
1422
    "Destination group names or UUIDs (defaults to \"all but current group\")" .
1423
  optionalField $ simpleField "target_groups" [t| [NonEmptyString] |]
1424

    
1425
pNodeGroupAllocPolicy :: Field
1426
pNodeGroupAllocPolicy =
1427
  withDoc "Instance allocation policy" .
1428
  optionalField $
1429
  simpleField "alloc_policy" [t| AllocPolicy |]
1430

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

    
1436
pExportMode :: Field
1437
pExportMode =
1438
  withDoc "Export mode" .
1439
  renameField "ExportMode" $ simpleField "mode" [t| ExportMode |]
1440

    
1441
-- FIXME: Rename target_node as it changes meaning for different
1442
-- export modes (e.g. "destination")
1443
pExportTargetNode :: Field
1444
pExportTargetNode =
1445
  withDoc "Target node (depends on export mode)" .
1446
  renameField "ExportTarget" $
1447
  simpleField "target_node" [t| ExportTarget |]
1448

    
1449
pExportTargetNodeUuid :: Field
1450
pExportTargetNodeUuid =
1451
  withDoc "Target node UUID (if local export)" .
1452
  renameField "ExportTargetNodeUuid" . optionalField $
1453
  simpleField "target_node_uuid" [t| NonEmptyString |]
1454

    
1455
pShutdownInstance :: Field
1456
pShutdownInstance =
1457
  withDoc "Whether to shutdown the instance before export" $
1458
  defaultTrue "shutdown"
1459

    
1460
pRemoveInstance :: Field
1461
pRemoveInstance =
1462
  withDoc "Whether to remove instance after export" $
1463
  defaultFalse "remove_instance"
1464

    
1465
pIgnoreRemoveFailures :: Field
1466
pIgnoreRemoveFailures =
1467
  withDoc "Whether to ignore failures while removing instances" $
1468
  defaultFalse "ignore_remove_failures"
1469

    
1470
pX509KeyName :: Field
1471
pX509KeyName =
1472
  withDoc "Name of X509 key (remote export only)" .
1473
  optionalField $ simpleField "x509_key_name" [t| [JSValue] |]
1474

    
1475
pX509DestCA :: Field
1476
pX509DestCA =
1477
  withDoc "Destination X509 CA (remote export only)" $
1478
  optionalNEStringField "destination_x509_ca"
1479

    
1480
pTagsObject :: Field
1481
pTagsObject =
1482
  withDoc "Tag kind" $
1483
  simpleField "kind" [t| TagKind |]
1484

    
1485
pTagsName :: Field
1486
pTagsName =
1487
  withDoc "Name of object" .
1488
  renameField "TagsGetName" .
1489
  optionalField $ simpleField "name" [t| String |]
1490

    
1491
pTagsList :: Field
1492
pTagsList =
1493
  withDoc "List of tag names" $
1494
  simpleField "tags" [t| [String] |]
1495

    
1496
-- FIXME: this should be compiled at load time?
1497
pTagSearchPattern :: Field
1498
pTagSearchPattern =
1499
  withDoc "Search pattern (regular expression)" .
1500
  renameField "TagSearchPattern" $
1501
  simpleField "pattern" [t| NonEmptyString |]
1502

    
1503
pDelayDuration :: Field
1504
pDelayDuration =
1505
  withDoc "Duration parameter for 'OpTestDelay'" .
1506
  renameField "DelayDuration" $
1507
  simpleField "duration" [t| Double |]
1508

    
1509
pDelayOnMaster :: Field
1510
pDelayOnMaster =
1511
  withDoc "on_master field for 'OpTestDelay'" .
1512
  renameField "DelayOnMaster" $
1513
  defaultTrue "on_master"
1514

    
1515
pDelayOnNodes :: Field
1516
pDelayOnNodes =
1517
  withDoc "on_nodes field for 'OpTestDelay'" .
1518
  renameField "DelayOnNodes" .
1519
  defaultField [| [] |] $
1520
  simpleField "on_nodes" [t| [NonEmptyString] |]
1521

    
1522
pDelayOnNodeUuids :: Field
1523
pDelayOnNodeUuids =
1524
  withDoc "on_node_uuids field for 'OpTestDelay'" .
1525
  renameField "DelayOnNodeUuids" . optionalField $
1526
  simpleField "on_node_uuids" [t| [NonEmptyString] |]
1527

    
1528
pDelayRepeat :: Field
1529
pDelayRepeat =
1530
  withDoc "Repeat parameter for OpTestDelay" .
1531
  renameField "DelayRepeat" .
1532
  defaultField [| forceNonNeg (0::Int) |] $
1533
  simpleField "repeat" [t| NonNegative Int |]
1534

    
1535
pIAllocatorDirection :: Field
1536
pIAllocatorDirection =
1537
  withDoc "IAllocator test direction" .
1538
  renameField "IAllocatorDirection" $
1539
  simpleField "direction" [t| IAllocatorTestDir |]
1540

    
1541
pIAllocatorMode :: Field
1542
pIAllocatorMode =
1543
  withDoc "IAllocator test mode" .
1544
  renameField "IAllocatorMode" $
1545
  simpleField "mode" [t| IAllocatorMode |]
1546

    
1547
pIAllocatorReqName :: Field
1548
pIAllocatorReqName =
1549
  withDoc "IAllocator target name (new instance, node to evac, etc.)" .
1550
  renameField "IAllocatorReqName" $ simpleField "name" [t| NonEmptyString |]
1551

    
1552
pIAllocatorNics :: Field
1553
pIAllocatorNics =
1554
  withDoc "Custom OpTestIAllocator nics" .
1555
  renameField "IAllocatorNics" .
1556
  optionalField $ simpleField "nics" [t| [INicParams] |]
1557

    
1558
pIAllocatorDisks :: Field
1559
pIAllocatorDisks =
1560
  withDoc "Custom OpTestAllocator disks" .
1561
  renameField "IAllocatorDisks" .
1562
  optionalField $ simpleField "disks" [t| [JSValue] |]
1563

    
1564
pIAllocatorMemory :: Field
1565
pIAllocatorMemory =
1566
  withDoc "IAllocator memory field" .
1567
  renameField "IAllocatorMem" .
1568
  optionalField $
1569
  simpleField "memory" [t| NonNegative Int |]
1570

    
1571
pIAllocatorVCpus :: Field
1572
pIAllocatorVCpus =
1573
  withDoc "IAllocator vcpus field" .
1574
  renameField "IAllocatorVCpus" .
1575
  optionalField $
1576
  simpleField "vcpus" [t| NonNegative Int |]
1577

    
1578
pIAllocatorOs :: Field
1579
pIAllocatorOs =
1580
  withDoc "IAllocator os field" .
1581
  renameField "IAllocatorOs" $ optionalNEStringField "os"
1582

    
1583
pIAllocatorInstances :: Field
1584
pIAllocatorInstances =
1585
  withDoc "IAllocator instances field" .
1586
  renameField "IAllocatorInstances " .
1587
  optionalField $
1588
  simpleField "instances" [t| [NonEmptyString] |]
1589

    
1590
pIAllocatorEvacMode :: Field
1591
pIAllocatorEvacMode =
1592
  withDoc "IAllocator evac mode" .
1593
  renameField "IAllocatorEvacMode" .
1594
  optionalField $
1595
  simpleField "evac_mode" [t| EvacMode |]
1596

    
1597
pIAllocatorSpindleUse :: Field
1598
pIAllocatorSpindleUse =
1599
  withDoc "IAllocator spindle use" .
1600
  renameField "IAllocatorSpindleUse" .
1601
  defaultField [| forceNonNeg (1::Int) |] $
1602
  simpleField "spindle_use" [t| NonNegative Int |]
1603

    
1604
pIAllocatorCount :: Field
1605
pIAllocatorCount =
1606
  withDoc "IAllocator count field" .
1607
  renameField "IAllocatorCount" .
1608
  defaultField [| forceNonNeg (1::Int) |] $
1609
  simpleField "count" [t| NonNegative Int |]
1610

    
1611
pJQueueNotifyWaitLock :: Field
1612
pJQueueNotifyWaitLock =
1613
  withDoc "'OpTestJqueue' notify_waitlock" $
1614
  defaultFalse "notify_waitlock"
1615

    
1616
pJQueueNotifyExec :: Field
1617
pJQueueNotifyExec =
1618
  withDoc "'OpTestJQueue' notify_exec" $
1619
  defaultFalse "notify_exec"
1620

    
1621
pJQueueLogMessages :: Field
1622
pJQueueLogMessages =
1623
  withDoc "'OpTestJQueue' log_messages" .
1624
  defaultField [| [] |] $ simpleField "log_messages" [t| [String] |]
1625

    
1626
pJQueueFail :: Field
1627
pJQueueFail =
1628
  withDoc "'OpTestJQueue' fail attribute" .
1629
  renameField "JQueueFail" $ defaultFalse "fail"
1630

    
1631
pTestDummyResult :: Field
1632
pTestDummyResult =
1633
  withDoc "'OpTestDummy' result field" .
1634
  renameField "TestDummyResult" $ simpleField "result" [t| JSValue |]
1635

    
1636
pTestDummyMessages :: Field
1637
pTestDummyMessages =
1638
  withDoc "'OpTestDummy' messages field" .
1639
  renameField "TestDummyMessages" $
1640
  simpleField "messages" [t| JSValue |]
1641

    
1642
pTestDummyFail :: Field
1643
pTestDummyFail =
1644
  withDoc "'OpTestDummy' fail field" .
1645
  renameField "TestDummyFail" $ simpleField "fail" [t| JSValue |]
1646

    
1647
pTestDummySubmitJobs :: Field
1648
pTestDummySubmitJobs =
1649
  withDoc "'OpTestDummy' submit_jobs field" .
1650
  renameField "TestDummySubmitJobs" $
1651
  simpleField "submit_jobs" [t| JSValue |]
1652

    
1653
pNetworkName :: Field
1654
pNetworkName =
1655
  withDoc "Network name" $
1656
  simpleField "network_name" [t| NonEmptyString |]
1657

    
1658
pNetworkAddress4 :: Field
1659
pNetworkAddress4 =
1660
  withDoc "Network address (IPv4 subnet)" .
1661
  renameField "NetworkAddress4" $
1662
  simpleField "network" [t| IPv4Network |]
1663

    
1664
pNetworkGateway4 :: Field
1665
pNetworkGateway4 =
1666
  withDoc "Network gateway (IPv4 address)" .
1667
  renameField "NetworkGateway4" .
1668
  optionalField $ simpleField "gateway" [t| IPv4Address |]
1669

    
1670
pNetworkAddress6 :: Field
1671
pNetworkAddress6 =
1672
  withDoc "Network address (IPv6 subnet)" .
1673
  renameField "NetworkAddress6" .
1674
  optionalField $ simpleField "network6" [t| IPv6Network |]
1675

    
1676
pNetworkGateway6 :: Field
1677
pNetworkGateway6 =
1678
  withDoc "Network gateway (IPv6 address)" .
1679
  renameField "NetworkGateway6" .
1680
  optionalField $ simpleField "gateway6" [t| IPv6Address |]
1681

    
1682
pNetworkMacPrefix :: Field
1683
pNetworkMacPrefix =
1684
  withDoc "Network specific mac prefix (that overrides the cluster one)" .
1685
  renameField "NetMacPrefix" $
1686
  optionalNEStringField "mac_prefix"
1687

    
1688
pNetworkAddRsvdIps :: Field
1689
pNetworkAddRsvdIps =
1690
  withDoc "Which IP addresses to reserve" .
1691
  renameField "NetworkAddRsvdIps" .
1692
  optionalField $
1693
  simpleField "add_reserved_ips" [t| [IPv4Address] |]
1694

    
1695
pNetworkRemoveRsvdIps :: Field
1696
pNetworkRemoveRsvdIps =
1697
  withDoc "Which external IP addresses to release" .
1698
  renameField "NetworkRemoveRsvdIps" .
1699
  optionalField $
1700
  simpleField "remove_reserved_ips" [t| [IPv4Address] |]
1701

    
1702
pNetworkMode :: Field
1703
pNetworkMode =
1704
  withDoc "Network mode when connecting to a group" $
1705
  simpleField "network_mode" [t| NICMode |]
1706

    
1707
pNetworkLink :: Field
1708
pNetworkLink =
1709
  withDoc "Network link when connecting to a group" $
1710
  simpleField "network_link" [t| NonEmptyString |]