Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / OpParams.hs @ de36f091

History | View | Annotate | Download (44.7 kB)

1
{-# LANGUAGE TemplateHaskell #-}
2

    
3
{-| Implementation of opcodes parameters.
4

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

    
11
-}
12

    
13
{-
14

    
15
Copyright (C) 2012 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
  ( TagType(..)
36
  , ReplaceDisksMode(..)
37
  , DiskIndex
38
  , mkDiskIndex
39
  , unDiskIndex
40
  , DiskAccess(..)
41
  , INicParams(..)
42
  , IDiskParams(..)
43
  , RecreateDisksInfo(..)
44
  , DdmOldChanges(..)
45
  , SetParamsMods(..)
46
  , ExportTarget(..)
47
  , pInstanceName
48
  , pInstanceUuid
49
  , pInstances
50
  , pName
51
  , pTagsList
52
  , pTagsObject
53
  , pTagsName
54
  , pOutputFields
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
  , pStartupPaused
87
  , pVerbose
88
  , pDebugSimulateErrors
89
  , pErrorCodes
90
  , pSkipChecks
91
  , pIgnoreErrors
92
  , pOptGroupName
93
  , pDiskParams
94
  , pHvState
95
  , pDiskState
96
  , pIgnoreIpolicy
97
  , pAllowRuntimeChgs
98
  , pInstDisks
99
  , pDiskTemplate
100
  , pOptDiskTemplate
101
  , pFileDriver
102
  , pFileStorageDir
103
  , pGlobalFileStorageDir
104
  , pVgName
105
  , pEnabledHypervisors
106
  , pHypervisor
107
  , pClusterHvParams
108
  , pInstHvParams
109
  , pClusterBeParams
110
  , pInstBeParams
111
  , pResetDefaults
112
  , pOsHvp
113
  , pClusterOsParams
114
  , pInstOsParams
115
  , pCandidatePoolSize
116
  , pUidPool
117
  , pAddUids
118
  , pRemoveUids
119
  , pMaintainNodeHealth
120
  , pModifyEtcHosts
121
  , pPreallocWipeDisks
122
  , pNicParams
123
  , pInstNics
124
  , pNdParams
125
  , pIpolicy
126
  , pDrbdHelper
127
  , pDefaultIAllocator
128
  , pMasterNetdev
129
  , pMasterNetmask
130
  , pReservedLvs
131
  , pHiddenOs
132
  , pBlacklistedOs
133
  , pUseExternalMipScript
134
  , pQueryFields
135
  , pQueryFilter
136
  , pQueryFieldsFields
137
  , pOobCommand
138
  , pOobTimeout
139
  , pIgnoreStatus
140
  , pPowerDelay
141
  , pPrimaryIp
142
  , pSecondaryIp
143
  , pReadd
144
  , pNodeGroup
145
  , pMasterCapable
146
  , pVmCapable
147
  , pNames
148
  , pNodes
149
  , pRequiredNodes
150
  , pRequiredNodeUuids
151
  , pStorageType
152
  , pStorageChanges
153
  , pMasterCandidate
154
  , pOffline
155
  , pDrained
156
  , pAutoPromote
157
  , pPowered
158
  , pIallocator
159
  , pRemoteNode
160
  , pRemoteNodeUuid
161
  , pEvacMode
162
  , pInstCreateMode
163
  , pNoInstall
164
  , pInstOs
165
  , pPrimaryNode
166
  , pPrimaryNodeUuid
167
  , pSecondaryNode
168
  , pSecondaryNodeUuid
169
  , pSourceHandshake
170
  , pSourceInstance
171
  , pSourceShutdownTimeout
172
  , pSourceX509Ca
173
  , pSrcNode
174
  , pSrcNodeUuid
175
  , pSrcPath
176
  , pStartInstance
177
  , pInstTags
178
  , pMultiAllocInstances
179
  , pTempOsParams
180
  , pTempHvParams
181
  , pTempBeParams
182
  , pIgnoreFailures
183
  , pNewName
184
  , pIgnoreSecondaries
185
  , pRebootType
186
  , pIgnoreDiskSize
187
  , pRecreateDisksInfo
188
  , pStatic
189
  , pInstParamsNicChanges
190
  , pInstParamsDiskChanges
191
  , pRuntimeMem
192
  , pOsNameChange
193
  , pDiskIndex
194
  , pDiskChgAmount
195
  , pDiskChgAbsolute
196
  , pTargetGroups
197
  , pExportMode
198
  , pExportTargetNode
199
  , pExportTargetNodeUuid
200
  , pRemoveInstance
201
  , pIgnoreRemoveFailures
202
  , pX509KeyName
203
  , pX509DestCA
204
  , pTagSearchPattern
205
  , pRestrictedCommand
206
  , pReplaceDisksMode
207
  , pReplaceDisksList
208
  , pAllowFailover
209
  , pDelayDuration
210
  , pDelayOnMaster
211
  , pDelayOnNodes
212
  , pDelayOnNodeUuids
213
  , pDelayRepeat
214
  , pIAllocatorDirection
215
  , pIAllocatorMode
216
  , pIAllocatorReqName
217
  , pIAllocatorNics
218
  , pIAllocatorDisks
219
  , pIAllocatorMemory
220
  , pIAllocatorVCpus
221
  , pIAllocatorOs
222
  , pIAllocatorInstances
223
  , pIAllocatorEvacMode
224
  , pIAllocatorSpindleUse
225
  , pIAllocatorCount
226
  , pJQueueNotifyWaitLock
227
  , pJQueueNotifyExec
228
  , pJQueueLogMessages
229
  , pJQueueFail
230
  , pTestDummyResult
231
  , pTestDummyMessages
232
  , pTestDummyFail
233
  , pTestDummySubmitJobs
234
  , pNetworkName
235
  , pNetworkAddress4
236
  , pNetworkGateway4
237
  , pNetworkAddress6
238
  , pNetworkGateway6
239
  , pNetworkMacPrefix
240
  , pNetworkAddRsvdIps
241
  , pNetworkRemoveRsvdIps
242
  , pNetworkMode
243
  , pNetworkLink
244
  , pDryRun
245
  , pDebugLevel
246
  , pOpPriority
247
  , pDependencies
248
  , pComment
249
  , pReason
250
  , pEnabledDiskTemplates
251
  ) where
252

    
253
import Control.Monad (liftM)
254
import Data.Set (Set)
255
import qualified Data.Set as Set
256
import Text.JSON (JSON, JSValue(..), JSObject (..), readJSON, showJSON,
257
                  fromJSString, toJSObject)
258
import qualified Text.JSON
259
import Text.JSON.Pretty (pp_value)
260

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

    
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
-- ** Tags
305

    
306
-- | Data type representing what items do the tag operations apply to.
307
$(declareSADT "TagType"
308
  [ ("TagTypeInstance", 'C.tagInstance)
309
  , ("TagTypeNode",     'C.tagNode)
310
  , ("TagTypeGroup",    'C.tagNodegroup)
311
  , ("TagTypeCluster",  'C.tagCluster)
312
  ])
313
$(makeJSONInstance ''TagType)
314

    
315
-- ** Disks
316

    
317
-- | Replace disks type.
318
$(declareSADT "ReplaceDisksMode"
319
  [ ("ReplaceOnPrimary",    'C.replaceDiskPri)
320
  , ("ReplaceOnSecondary",  'C.replaceDiskSec)
321
  , ("ReplaceNewSecondary", 'C.replaceDiskChg)
322
  , ("ReplaceAuto",         'C.replaceDiskAuto)
323
  ])
324
$(makeJSONInstance ''ReplaceDisksMode)
325

    
326
-- | Disk index type (embedding constraints on the index value via a
327
-- smart constructor).
328
newtype DiskIndex = DiskIndex { unDiskIndex :: Int }
329
  deriving (Show, Eq, Ord)
330

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

    
338
instance JSON DiskIndex where
339
  readJSON v = readJSON v >>= mkDiskIndex
340
  showJSON = showJSON . unDiskIndex
341

    
342
-- ** I* param types
343

    
344
-- | Type holding disk access modes.
345
$(declareSADT "DiskAccess"
346
  [ ("DiskReadOnly",  'C.diskRdonly)
347
  , ("DiskReadWrite", 'C.diskRdwr)
348
  ])
349
$(makeJSONInstance ''DiskAccess)
350

    
351
-- | NIC modification definition.
352
$(buildObject "INicParams" "inic"
353
  [ optionalField $ simpleField C.inicMac    [t| NonEmptyString |]
354
  , optionalField $ simpleField C.inicIp     [t| String         |]
355
  , optionalField $ simpleField C.inicMode   [t| NonEmptyString |]
356
  , optionalField $ simpleField C.inicLink   [t| NonEmptyString |]
357
  , optionalField $ simpleField C.inicName   [t| NonEmptyString |]
358
  , optionalField $ simpleField C.inicVlan   [t| NonEmptyString |]
359
  , optionalField $ simpleField C.inicBridge [t| NonEmptyString |]
360
  ])
361

    
362
-- | Disk modification definition. FIXME: disksize should be VTYPE_UNIT.
363
$(buildObject "IDiskParams" "idisk"
364
  [ optionalField $ simpleField C.idiskSize   [t| Int            |]
365
  , optionalField $ simpleField C.idiskMode   [t| DiskAccess     |]
366
  , optionalField $ simpleField C.idiskAdopt  [t| NonEmptyString |]
367
  , optionalField $ simpleField C.idiskVg     [t| NonEmptyString |]
368
  , optionalField $ simpleField C.idiskMetavg [t| NonEmptyString |]
369
  , optionalField $ simpleField C.idiskName   [t| NonEmptyString |]
370
  ])
371

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

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

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

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

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

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

    
419
-- | Instance disk or nic modifications.
420
data SetParamsMods a
421
  = SetParamsEmpty
422
  | SetParamsDeprecated (NonEmpty (DdmOldChanges, a))
423
  | SetParamsNew (NonEmpty (DdmFull, Int, 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
  case readJSON v::Text.JSON.Result [(DdmOldChanges, JSValue)] of
431
    Text.JSON.Ok _ -> liftM SetParamsDeprecated $ readJSON v
432
    _ -> liftM SetParamsNew $ 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
  readJSON = readSetParams
439

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

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

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

    
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

    
497
-- * Parameters
498

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

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

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

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

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

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

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

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

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

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

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

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

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

    
568
-- | Global directory for storing file-backed disks.
569
pGlobalFileStorageDir :: Field
570
pGlobalFileStorageDir = optionalNEStringField "file_storage_dir"
571

    
572
-- | Volume group name.
573
pVgName :: Field
574
pVgName =
575
  withDoc "Volume group name" $
576
  optionalStringField "vg_name"
577

    
578
pEnabledHypervisors :: Field
579
pEnabledHypervisors =
580
  withDoc "List of enabled hypervisors" .
581
  optionalField $
582
  simpleField "enabled_hypervisors" [t| Hypervisor |]
583

    
584
pClusterHvParams :: Field
585
pClusterHvParams =
586
  withDoc "Cluster-wide hypervisor parameters, hypervisor-dependent" .
587
  renameField "ClusterHvParams" .
588
  optionalField $
589
  simpleField "hvparams" [t| GenericContainer String (JSObject JSValue) |]
590

    
591
pClusterBeParams :: Field
592
pClusterBeParams =
593
  withDoc "Cluster-wide backend parameter defaults" .
594
  renameField "ClusterBeParams" .
595
  optionalField $ simpleField "beparams" [t| JSObject JSValue |]
596

    
597
pOsHvp :: Field
598
pOsHvp =
599
  withDoc "Cluster-wide per-OS hypervisor parameter defaults" .
600
  optionalField $
601
  simpleField "os_hvp" [t| GenericContainer String (JSObject JSValue) |]
602

    
603
pClusterOsParams :: Field
604
pClusterOsParams =
605
  withDoc "Cluster-wide OS parameter defaults" .
606
  renameField "ClusterOsParams" .
607
  optionalField $
608
  simpleField "osparams" [t| GenericContainer String (JSObject JSValue) |]
609

    
610
pDiskParams :: Field
611
pDiskParams =
612
  withDoc "Disk templates' parameter defaults" .
613
  optionalField $
614
  simpleField "diskparams"
615
              [t| GenericContainer DiskTemplate (JSObject JSValue) |]
616

    
617
pCandidatePoolSize :: Field
618
pCandidatePoolSize =
619
  withDoc "Master candidate pool size" .
620
  optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]
621

    
622
pUidPool :: Field
623
pUidPool =
624
  withDoc "Set UID pool, must be list of lists describing UID ranges\
625
          \ (two items, start and end inclusive)" .
626
  optionalField $ simpleField "uid_pool" [t| [[(Int, Int)]] |]
627

    
628
pAddUids :: Field
629
pAddUids =
630
  withDoc "Extend UID pool, must be list of lists describing UID\
631
          \ ranges (two items, start and end inclusive)" .
632
  optionalField $ simpleField "add_uids" [t| [[(Int, Int)]] |]
633

    
634
pRemoveUids :: Field
635
pRemoveUids =
636
  withDoc "Shrink UID pool, must be list of lists describing UID\
637
          \ ranges (two items, start and end inclusive) to be removed" .
638
  optionalField $ simpleField "remove_uids" [t| [[(Int, Int)]] |]
639

    
640
pMaintainNodeHealth :: Field
641
pMaintainNodeHealth =
642
  withDoc "Whether to automatically maintain node health" .
643
  optionalField $ booleanField "maintain_node_health"
644

    
645
-- | Whether to modify and keep in sync the @/etc/hosts@ files of nodes.
646
pModifyEtcHosts :: Field
647
pModifyEtcHosts = optionalField $ booleanField "modify_etc_hosts"
648

    
649
-- | Whether to wipe disks before allocating them to instances.
650
pPreallocWipeDisks :: Field
651
pPreallocWipeDisks =
652
  withDoc "Whether to wipe disks before allocating them to instances" .
653
  optionalField $ booleanField "prealloc_wipe_disks"
654

    
655
pNicParams :: Field
656
pNicParams =
657
  withDoc "Cluster-wide NIC parameter defaults" .
658
  optionalField $ simpleField "nicparams" [t| INicParams |]
659

    
660
pIpolicy :: Field
661
pIpolicy =
662
  withDoc "Ipolicy specs" .
663
  optionalField $ simpleField "ipolicy" [t| JSObject JSValue |]
664

    
665
pDrbdHelper :: Field
666
pDrbdHelper =
667
  withDoc "DRBD helper program" $
668
  optionalStringField "drbd_helper"
669

    
670
pDefaultIAllocator :: Field
671
pDefaultIAllocator =
672
  withDoc "Default iallocator for cluster" $
673
  optionalStringField "default_iallocator"
674

    
675
pMasterNetdev :: Field
676
pMasterNetdev =
677
  withDoc "Master network device" $
678
  optionalStringField "master_netdev"
679

    
680
pMasterNetmask :: Field
681
pMasterNetmask =
682
  withDoc "Netmask of the master IP" .
683
  optionalField $ simpleField "master_netmask" [t| NonNegative Int |]
684

    
685
pReservedLvs :: Field
686
pReservedLvs =
687
  withDoc "List of reserved LVs" .
688
  optionalField $ simpleField "reserved_lvs" [t| [NonEmptyString] |]
689

    
690
pHiddenOs :: Field
691
pHiddenOs =
692
  withDoc "Modify list of hidden operating systems: each modification\
693
          \ must have two items, the operation and the OS name; the operation\
694
          \ can be add or remove" .
695
  optionalField $ simpleField "hidden_os" [t| [(DdmSimple, NonEmptyString)] |]
696

    
697
pBlacklistedOs :: Field
698
pBlacklistedOs =
699
  withDoc "Modify list of blacklisted operating systems: each\
700
          \ modification must have two items, the operation and the OS name;\
701
          \ the operation can be add or remove" .
702
  optionalField $
703
  simpleField "blacklisted_os" [t| [(DdmSimple, NonEmptyString)] |]
704

    
705
pUseExternalMipScript :: Field
706
pUseExternalMipScript =
707
  withDoc "Whether to use an external master IP address setup script" .
708
  optionalField $ booleanField "use_external_mip_script"
709

    
710
pEnabledDiskTemplates :: Field
711
pEnabledDiskTemplates =
712
  withDoc "List of enabled disk templates" .
713
  optionalField $
714
  simpleField "enabled_disk_templates" [t| DiskTemplate |]
715

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

    
721
pUseLocking :: Field
722
pUseLocking =
723
  withDoc "Whether to use synchronization" $
724
  defaultFalse "use_locking"
725

    
726
pQueryFields :: Field
727
pQueryFields =
728
  withDoc "Requested fields" $
729
  simpleField "fields" [t| [NonEmptyString] |]
730

    
731
pQueryFilter :: Field
732
pQueryFilter =
733
  withDoc "Query filter" .
734
  optionalField $ simpleField "qfilter" [t| [JSValue] |]
735

    
736
pQueryFieldsFields :: Field
737
pQueryFieldsFields =
738
  withDoc "Requested fields; if not given, all are returned" .
739
  renameField "QueryFieldsFields" $
740
  optionalField pQueryFields
741

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

    
747
pNodeUuids :: Field
748
pNodeUuids =
749
  withDoc "List of node UUIDs" .
750
  optionalField $ simpleField "node_uuids" [t| [NonEmptyString] |]
751

    
752
pOobCommand :: Field
753
pOobCommand =
754
  withDoc "OOB command to run" $
755
  simpleField "command" [t| OobCommand |]
756

    
757
pOobTimeout :: Field
758
pOobTimeout =
759
  withDoc "Timeout before the OOB helper will be terminated" .
760
  defaultField [| C.oobTimeout |] $
761
  simpleField "timeout" [t| Int |]
762

    
763
pIgnoreStatus :: Field
764
pIgnoreStatus =
765
  withDoc "Ignores the node offline status for power off" $
766
  defaultFalse "ignore_status"
767

    
768
pPowerDelay :: Field
769
pPowerDelay =
770
  -- FIXME: we can't use the proper type "NonNegative Double", since
771
  -- the default constant is a plain Double, not a non-negative one.
772
  -- And trying to fix the constant introduces a cyclic import.
773
  withDoc "Time in seconds to wait between powering on nodes" .
774
  defaultField [| C.oobPowerDelay |] $
775
  simpleField "power_delay" [t| Double |]
776

    
777
pRequiredNodes :: Field
778
pRequiredNodes =
779
  withDoc "Required list of node names" .
780
  renameField "ReqNodes " $ simpleField "nodes" [t| [NonEmptyString] |]
781

    
782
pRequiredNodeUuids :: Field
783
pRequiredNodeUuids =
784
  withDoc "Required list of node UUIDs" .
785
  renameField "ReqNodeUuids " . optionalField $
786
  simpleField "node_uuids" [t| [NonEmptyString] |]
787

    
788
pRestrictedCommand :: Field
789
pRestrictedCommand =
790
  withDoc "Restricted command name" .
791
  renameField "RestrictedCommand" $
792
  simpleField "command" [t| NonEmptyString |]
793

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

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

    
804
pPrimaryIp :: Field
805
pPrimaryIp =
806
  withDoc "Primary IP address" $
807
  simpleField "primary_ip" [t| NonEmptyString |]
808

    
809
pSecondaryIp :: Field
810
pSecondaryIp =
811
  withDoc "Secondary IP address" $
812
  optionalNEStringField "secondary_ip"
813

    
814
pReadd :: Field
815
pReadd =
816
  withDoc "Whether node is re-added to cluster" $
817
  defaultFalse "readd"
818

    
819
pNodeGroup :: Field
820
pNodeGroup =
821
  withDoc "Initial node group" $
822
  optionalNEStringField "group"
823

    
824
pMasterCapable :: Field
825
pMasterCapable =
826
  withDoc "Whether node can become master or master candidate" .
827
  optionalField $ booleanField "master_capable"
828

    
829
pVmCapable :: Field
830
pVmCapable =
831
  withDoc "Whether node can host instances" .
832
  optionalField $ booleanField "vm_capable"
833

    
834
pNdParams :: Field
835
pNdParams =
836
  withDoc "Node parameters" .
837
  renameField "genericNdParams" .
838
  optionalField $ simpleField "ndparams" [t| JSObject JSValue |]
839
  
840
pNames :: Field
841
pNames =
842
  withDoc "List of names" .
843
  defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
844

    
845
pNodes :: Field
846
pNodes =
847
  withDoc "List of nodes" .
848
  defaultField [| [] |] $ simpleField "nodes" [t| [NonEmptyString] |]
849

    
850
pStorageType :: Field
851
pStorageType =
852
  withDoc "Storage type" $
853
  simpleField "storage_type" [t| StorageType |]
854

    
855
pStorageName :: Field
856
pStorageName =
857
  withDoc "Storage name" .
858
  renameField "StorageName" .
859
  optionalField $ simpleField "name" [t| NonEmptyString |]
860

    
861
pStorageChanges :: Field
862
pStorageChanges =
863
  withDoc "Requested storage changes" $
864
  simpleField "changes" [t| JSObject JSValue |]
865

    
866
pIgnoreConsistency :: Field
867
pIgnoreConsistency =
868
  withDoc "Whether to ignore disk consistency" $
869
  defaultFalse "ignore_consistency"
870

    
871
pMasterCandidate :: Field
872
pMasterCandidate =
873
  withDoc "Whether the node should become a master candidate" .
874
  optionalField $ booleanField "master_candidate"
875

    
876
pOffline :: Field
877
pOffline =
878
  withDoc "Whether to mark the node or instance offline" .
879
  optionalField $ booleanField "offline"
880

    
881
pDrained ::Field
882
pDrained =
883
  withDoc "Whether to mark the node as drained" .
884
  optionalField $ booleanField "drained"
885

    
886
pAutoPromote :: Field
887
pAutoPromote =
888
  withDoc "Whether node(s) should be promoted to master candidate if\
889
          \ necessary" $
890
  defaultFalse "auto_promote"
891

    
892
pPowered :: Field
893
pPowered =
894
  withDoc "Whether the node should be marked as powered" .
895
  optionalField $ booleanField "powered"
896

    
897
pMigrationMode :: Field
898
pMigrationMode =
899
  withDoc "Migration type (live/non-live)" .
900
  renameField "MigrationMode" .
901
  optionalField $
902
  simpleField "mode" [t| MigrationMode |]
903

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

    
909
pMigrationTargetNode :: Field
910
pMigrationTargetNode =
911
  withDoc "Target node for instance migration/failover" $
912
  optionalNEStringField "target_node"
913

    
914
pMigrationTargetNodeUuid :: Field
915
pMigrationTargetNodeUuid =
916
  withDoc "Target node UUID for instance migration/failover" $
917
  optionalNEStringField "target_node_uuid"
918

    
919
pAllowRuntimeChgs :: Field
920
pAllowRuntimeChgs =
921
  withDoc "Whether to allow runtime changes while migrating" $
922
  defaultTrue "allow_runtime_changes"
923

    
924
pIgnoreIpolicy :: Field
925
pIgnoreIpolicy =
926
  withDoc "Whether to ignore ipolicy violations" $
927
  defaultFalse "ignore_ipolicy"
928
  
929
pIallocator :: Field
930
pIallocator =
931
  withDoc "Iallocator for deciding the target node for shared-storage\
932
          \ instances" $
933
  optionalNEStringField "iallocator"
934

    
935
pEarlyRelease :: Field
936
pEarlyRelease =
937
  withDoc "Whether to release locks as soon as possible" $
938
  defaultFalse "early_release"
939

    
940
pRemoteNode :: Field
941
pRemoteNode =
942
  withDoc "New secondary node" $
943
  optionalNEStringField "remote_node"
944

    
945
pRemoteNodeUuid :: Field
946
pRemoteNodeUuid =
947
  withDoc "New secondary node UUID" $
948
  optionalNEStringField "remote_node_uuid"
949

    
950
pEvacMode :: Field
951
pEvacMode =
952
  withDoc "Node evacuation mode" .
953
  renameField "EvacMode" $ simpleField "mode" [t| NodeEvacMode |]
954

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

    
960
pForceVariant :: Field
961
pForceVariant =
962
  withDoc "Whether to force an unknown OS variant" $
963
  defaultFalse "force_variant"
964

    
965
pWaitForSync :: Field
966
pWaitForSync =
967
  withDoc "Whether to wait for the disk to synchronize" $
968
  defaultTrue "wait_for_sync"
969

    
970
pNameCheck :: Field
971
pNameCheck =
972
  withDoc "Whether to check name" $
973
  defaultTrue "name_check"
974

    
975
pInstBeParams :: Field
976
pInstBeParams =
977
  withDoc "Backend parameters for instance" .
978
  renameField "InstBeParams" .
979
  defaultField [| toJSObject [] |] $
980
  simpleField "beparams" [t| JSObject JSValue |]
981

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

    
987
pDiskTemplate :: Field
988
pDiskTemplate =
989
  withDoc "List of instance disks" $
990
  simpleField "disk_template" [t| DiskTemplate |]
991

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

    
997
pFileStorageDir :: Field
998
pFileStorageDir =
999
  withDoc "Directory for storing file-backed disks" $
1000
  optionalNEStringField "file_storage_dir"
1001

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

    
1009
pHypervisor :: Field
1010
pHypervisor =
1011
  withDoc "Selected hypervisor for an instance" .
1012
  optionalField $
1013
  simpleField "hypervisor" [t| Hypervisor |]
1014

    
1015
pResetDefaults :: Field
1016
pResetDefaults =
1017
  withDoc "Reset instance parameters to default if equal" $
1018
  defaultFalse "identify_defaults"
1019

    
1020
pIpCheck :: Field
1021
pIpCheck =
1022
  withDoc "Whether to ensure instance's IP address is inactive" $
1023
  defaultTrue "ip_check"
1024

    
1025
pIpConflictsCheck :: Field
1026
pIpConflictsCheck =
1027
  withDoc "Whether to check for conflicting IP addresses" $
1028
  defaultTrue "conflicts_check"
1029

    
1030
pInstCreateMode :: Field
1031
pInstCreateMode =
1032
  withDoc "Instance creation mode" .
1033
  renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]
1034

    
1035
pInstNics :: Field
1036
pInstNics =
1037
  withDoc "List of NIC (network interface) definitions" $
1038
  simpleField "nics" [t| [INicParams] |]
1039

    
1040
pNoInstall :: Field
1041
pNoInstall =
1042
  withDoc "Do not install the OS (will disable automatic start)" .
1043
  optionalField $ booleanField "no_install"
1044

    
1045
pInstOs :: Field
1046
pInstOs =
1047
  withDoc "OS type for instance installation" $
1048
  optionalNEStringField "os_type"
1049

    
1050
pInstOsParams :: Field
1051
pInstOsParams =
1052
  withDoc "OS parameters for instance" .
1053
  renameField "InstOsParams" .
1054
  defaultField [| toJSObject [] |] $
1055
  simpleField "osparams" [t| JSObject JSValue |]
1056

    
1057
pPrimaryNode :: Field
1058
pPrimaryNode =
1059
  withDoc "Primary node for an instance" $
1060
  optionalNEStringField "pnode"
1061

    
1062
pPrimaryNodeUuid :: Field
1063
pPrimaryNodeUuid =
1064
  withDoc "Primary node UUID for an instance" $
1065
  optionalNEStringField "pnode_uuid"
1066

    
1067
pSecondaryNode :: Field
1068
pSecondaryNode =
1069
  withDoc "Secondary node for an instance" $
1070
  optionalNEStringField "snode"
1071

    
1072
pSecondaryNodeUuid :: Field
1073
pSecondaryNodeUuid =
1074
  withDoc "Secondary node UUID for an instance" $
1075
  optionalNEStringField "snode_uuid"
1076

    
1077
pSourceHandshake :: Field
1078
pSourceHandshake =
1079
  withDoc "Signed handshake from source (remote import only)" .
1080
  optionalField $ simpleField "source_handshake" [t| [JSValue] |]
1081

    
1082
pSourceInstance :: Field
1083
pSourceInstance =
1084
  withDoc "Source instance name (remote import only)" $
1085
  optionalNEStringField "source_instance_name"
1086

    
1087
-- FIXME: non-negative int, whereas the constant is a plain int.
1088
pSourceShutdownTimeout :: Field
1089
pSourceShutdownTimeout =
1090
  withDoc "How long source instance was given to shut down (remote import\
1091
          \ only)" .
1092
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
1093
  simpleField "source_shutdown_timeout" [t| NonNegative Int |]
1094

    
1095
pSourceX509Ca :: Field
1096
pSourceX509Ca =
1097
  withDoc "Source X509 CA in PEM format (remote import only)" $
1098
  optionalNEStringField "source_x509_ca"
1099

    
1100
pSrcNode :: Field
1101
pSrcNode =
1102
  withDoc "Source node for import" $
1103
  optionalNEStringField "src_node"
1104

    
1105
pSrcNodeUuid :: Field
1106
pSrcNodeUuid =
1107
  withDoc "Source node UUID for import" $
1108
  optionalNEStringField "src_node_uuid"
1109

    
1110
pSrcPath :: Field
1111
pSrcPath =
1112
  withDoc "Source directory for import" $
1113
  optionalNEStringField "src_path"
1114

    
1115
pStartInstance :: Field
1116
pStartInstance =
1117
  withDoc "Whether to start instance after creation" $
1118
  defaultTrue "start"
1119

    
1120
-- FIXME: unify/simplify with pTags, once that migrates to NonEmpty String"
1121
pInstTags :: Field
1122
pInstTags =
1123
  withDoc "Instance tags" .
1124
  renameField "InstTags" .
1125
  defaultField [| [] |] $
1126
  simpleField "tags" [t| [NonEmptyString] |]
1127

    
1128
pMultiAllocInstances :: Field
1129
pMultiAllocInstances =
1130
  withDoc "List of instance create opcodes describing the instances to\
1131
          \ allocate" .
1132
  renameField "InstMultiAlloc" .
1133
  defaultField [| [] |] $
1134
  simpleField "instances"[t| [JSValue] |]
1135

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

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

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

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

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

    
1166
pNewName :: Field
1167
pNewName =
1168
  withDoc "New group or instance name" $
1169
  simpleField "new_name" [t| NonEmptyString |]
1170
  
1171
pIgnoreOfflineNodes :: Field
1172
pIgnoreOfflineNodes =
1173
  withDoc "Whether to ignore offline nodes" $
1174
  defaultFalse "ignore_offline_nodes"
1175

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

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

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

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

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

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

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

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

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

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

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

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

    
1244
pIgnoreDiskSize :: Field
1245
pIgnoreDiskSize =
1246
  withDoc "Whether to ignore recorded disk size" $
1247
  defaultFalse "ignore_size"
1248
  
1249
pWaitForSyncFalse :: Field
1250
pWaitForSyncFalse =
1251
  withDoc "Whether to wait for the disk to synchronize (defaults to false)" $
1252
  defaultField [| False |] pWaitForSync
1253
  
1254
pRecreateDisksInfo :: Field
1255
pRecreateDisksInfo =
1256
  withDoc "Disk list for recreate disks" .
1257
  renameField "RecreateDisksInfo" .
1258
  defaultField [| RecreateDisksAll |] $
1259
  simpleField "disks" [t| RecreateDisksInfo |]
1260

    
1261
pStatic :: Field
1262
pStatic =
1263
  withDoc "Whether to only return configuration data without querying nodes" $
1264
  defaultFalse "static"
1265

    
1266
pInstParamsNicChanges :: Field
1267
pInstParamsNicChanges =
1268
  withDoc "List of NIC changes" .
1269
  renameField "InstNicChanges" .
1270
  defaultField [| SetParamsEmpty |] $
1271
  simpleField "nics" [t| SetParamsMods INicParams |]
1272

    
1273
pInstParamsDiskChanges :: Field
1274
pInstParamsDiskChanges =
1275
  withDoc "List of disk changes" .
1276
  renameField "InstDiskChanges" .
1277
  defaultField [| SetParamsEmpty |] $
1278
  simpleField "disks" [t| SetParamsMods IDiskParams |]
1279

    
1280
pRuntimeMem :: Field
1281
pRuntimeMem =
1282
  withDoc "New runtime memory" .
1283
  optionalField $ simpleField "runtime_mem" [t| Positive Int |]
1284

    
1285
pOptDiskTemplate :: Field
1286
pOptDiskTemplate =
1287
  withDoc "Instance disk template" .
1288
  optionalField .
1289
  renameField "OptDiskTemplate" $
1290
  simpleField "disk_template" [t| DiskTemplate |]
1291

    
1292
pOsNameChange :: Field
1293
pOsNameChange =
1294
  withDoc "Change the instance's OS without reinstalling the instance" $
1295
  optionalNEStringField "os_name"
1296

    
1297
pDiskIndex :: Field
1298
pDiskIndex =
1299
  withDoc "Disk index for e.g. grow disk" .
1300
  renameField "DiskIndex " $ simpleField "disk" [t| DiskIndex |]
1301

    
1302
pDiskChgAmount :: Field
1303
pDiskChgAmount =
1304
  withDoc "Disk amount to add or grow to" .
1305
  renameField "DiskChgAmount" $ simpleField "amount" [t| NonNegative Int |]
1306

    
1307
pDiskChgAbsolute :: Field
1308
pDiskChgAbsolute =
1309
  withDoc
1310
    "Whether the amount parameter is an absolute target or a relative one" .
1311
  renameField "DiskChkAbsolute" $ defaultFalse "absolute"
1312

    
1313
pTargetGroups :: Field
1314
pTargetGroups =
1315
  withDoc
1316
    "Destination group names or UUIDs (defaults to \"all but current group\")" .
1317
  optionalField $ simpleField "target_groups" [t| [NonEmptyString] |]
1318

    
1319
pNodeGroupAllocPolicy :: Field
1320
pNodeGroupAllocPolicy =
1321
  withDoc "Instance allocation policy" .
1322
  optionalField $
1323
  simpleField "alloc_policy" [t| AllocPolicy |]
1324

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

    
1330
pExportMode :: Field
1331
pExportMode =
1332
  withDoc "Export mode" .
1333
  renameField "ExportMode" $ simpleField "mode" [t| ExportMode |]
1334

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

    
1343
pExportTargetNodeUuid :: Field
1344
pExportTargetNodeUuid =
1345
  withDoc "Target node UUID (if local export)" .
1346
  renameField "ExportTargetNodeUuid" . optionalField $
1347
  simpleField "target_node_uuid" [t| NonEmptyString |]
1348

    
1349
pShutdownInstance :: Field
1350
pShutdownInstance =
1351
  withDoc "Whether to shutdown the instance before export" $
1352
  defaultTrue "shutdown"
1353

    
1354
pRemoveInstance :: Field
1355
pRemoveInstance =
1356
  withDoc "Whether to remove instance after export" $
1357
  defaultFalse "remove_instance"
1358

    
1359
pIgnoreRemoveFailures :: Field
1360
pIgnoreRemoveFailures =
1361
  withDoc "Whether to ignore failures while removing instances" $
1362
  defaultFalse "ignore_remove_failures"
1363

    
1364
pX509KeyName :: Field
1365
pX509KeyName =
1366
  withDoc "Name of X509 key (remote export only)" .
1367
  optionalField $ simpleField "x509_key_name" [t| [JSValue] |]
1368

    
1369
pX509DestCA :: Field
1370
pX509DestCA =
1371
  withDoc "Destination X509 CA (remote export only)" $
1372
  optionalNEStringField "destination_x509_ca"
1373

    
1374
pTagsObject :: Field
1375
pTagsObject =
1376
  withDoc "Tag kind" $
1377
  simpleField "kind" [t| TagKind |]
1378

    
1379
pTagsName :: Field
1380
pTagsName =
1381
  withDoc "Name of object" .
1382
  renameField "TagsGetName" .
1383
  optionalField $ simpleField "name" [t| NonEmptyString |]
1384

    
1385
pTagsList :: Field
1386
pTagsList =
1387
  withDoc "List of tag names" $
1388
  simpleField "tags" [t| [String] |]
1389

    
1390
-- FIXME: this should be compiled at load time?
1391
pTagSearchPattern :: Field
1392
pTagSearchPattern =
1393
  withDoc "Search pattern (regular expression)" .
1394
  renameField "TagSearchPattern" $
1395
  simpleField "pattern" [t| NonEmptyString |]
1396

    
1397
pDelayDuration :: Field
1398
pDelayDuration =
1399
  withDoc "Duration parameter for 'OpTestDelay'" .
1400
  renameField "DelayDuration" $
1401
  simpleField "duration" [t| Double |]
1402

    
1403
pDelayOnMaster :: Field
1404
pDelayOnMaster =
1405
  withDoc "on_master field for 'OpTestDelay'" .
1406
  renameField "DelayOnMaster" $
1407
  defaultTrue "on_master"
1408

    
1409
pDelayOnNodes :: Field
1410
pDelayOnNodes =
1411
  withDoc "on_nodes field for 'OpTestDelay'" .
1412
  renameField "DelayOnNodes" .
1413
  defaultField [| [] |] $
1414
  simpleField "on_nodes" [t| [NonEmptyString] |]
1415

    
1416
pDelayOnNodeUuids :: Field
1417
pDelayOnNodeUuids =
1418
  withDoc "on_node_uuids field for 'OpTestDelay'" .
1419
  renameField "DelayOnNodeUuids" . optionalField $
1420
  simpleField "on_node_uuids" [t| [NonEmptyString] |]
1421

    
1422
pDelayRepeat :: Field
1423
pDelayRepeat =
1424
  withDoc "Repeat parameter for OpTestDelay" .
1425
  renameField "DelayRepeat" .
1426
  defaultField [| forceNonNeg (0::Int) |] $
1427
  simpleField "repeat" [t| NonNegative Int |]
1428

    
1429
pIAllocatorDirection :: Field
1430
pIAllocatorDirection =
1431
  withDoc "IAllocator test direction" .
1432
  renameField "IAllocatorDirection" $
1433
  simpleField "direction" [t| IAllocatorTestDir |]
1434

    
1435
pIAllocatorMode :: Field
1436
pIAllocatorMode =
1437
  withDoc "IAllocator test mode" .
1438
  renameField "IAllocatorMode" $
1439
  simpleField "mode" [t| IAllocatorMode |]
1440

    
1441
pIAllocatorReqName :: Field
1442
pIAllocatorReqName =
1443
  withDoc "IAllocator target name (new instance, node to evac, etc.)" .
1444
  renameField "IAllocatorReqName" $ simpleField "name" [t| NonEmptyString |]
1445

    
1446
pIAllocatorNics :: Field
1447
pIAllocatorNics =
1448
  withDoc "Custom OpTestIAllocator nics" .
1449
  renameField "IAllocatorNics" .
1450
  optionalField $ simpleField "nics" [t| [INicParams] |]
1451

    
1452
pIAllocatorDisks :: Field
1453
pIAllocatorDisks =
1454
  withDoc "Custom OpTestAllocator disks" .
1455
  renameField "IAllocatorDisks" .
1456
  optionalField $ simpleField "disks" [t| [JSValue] |]
1457

    
1458
pIAllocatorMemory :: Field
1459
pIAllocatorMemory =
1460
  withDoc "IAllocator memory field" .
1461
  renameField "IAllocatorMem" .
1462
  optionalField $
1463
  simpleField "memory" [t| NonNegative Int |]
1464

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

    
1472
pIAllocatorOs :: Field
1473
pIAllocatorOs =
1474
  withDoc "IAllocator os field" .
1475
  renameField "IAllocatorOs" $ optionalNEStringField "os"
1476

    
1477
pIAllocatorInstances :: Field
1478
pIAllocatorInstances =
1479
  withDoc "IAllocator instances field" .
1480
  renameField "IAllocatorInstances " .
1481
  optionalField $
1482
  simpleField "instances" [t| [NonEmptyString] |]
1483

    
1484
pIAllocatorEvacMode :: Field
1485
pIAllocatorEvacMode =
1486
  withDoc "IAllocator evac mode" .
1487
  renameField "IAllocatorEvacMode" .
1488
  optionalField $
1489
  simpleField "evac_mode" [t| NodeEvacMode |]
1490

    
1491
pIAllocatorSpindleUse :: Field
1492
pIAllocatorSpindleUse =
1493
  withDoc "IAllocator spindle use" .
1494
  renameField "IAllocatorSpindleUse" .
1495
  defaultField [| forceNonNeg (1::Int) |] $
1496
  simpleField "spindle_use" [t| NonNegative Int |]
1497

    
1498
pIAllocatorCount :: Field
1499
pIAllocatorCount =
1500
  withDoc "IAllocator count field" .
1501
  renameField "IAllocatorCount" .
1502
  defaultField [| forceNonNeg (1::Int) |] $
1503
  simpleField "count" [t| NonNegative Int |]
1504

    
1505
pJQueueNotifyWaitLock :: Field
1506
pJQueueNotifyWaitLock =
1507
  withDoc "'OpTestJqueue' notify_waitlock" $
1508
  defaultFalse "notify_waitlock"
1509

    
1510
pJQueueNotifyExec :: Field
1511
pJQueueNotifyExec =
1512
  withDoc "'OpTestJQueue' notify_exec" $
1513
  defaultFalse "notify_exec"
1514

    
1515
pJQueueLogMessages :: Field
1516
pJQueueLogMessages =
1517
  withDoc "'OpTestJQueue' log_messages" .
1518
  defaultField [| [] |] $ simpleField "log_messages" [t| [String] |]
1519

    
1520
pJQueueFail :: Field
1521
pJQueueFail =
1522
  withDoc "'OpTestJQueue' fail attribute" .
1523
  renameField "JQueueFail" $ defaultFalse "fail"
1524

    
1525
pTestDummyResult :: Field
1526
pTestDummyResult =
1527
  withDoc "'OpTestDummy' result field" .
1528
  renameField "TestDummyResult" $ simpleField "result" [t| JSValue |]
1529

    
1530
pTestDummyMessages :: Field
1531
pTestDummyMessages =
1532
  withDoc "'OpTestDummy' messages field" .
1533
  renameField "TestDummyMessages" $
1534
  simpleField "messages" [t| JSValue |]
1535

    
1536
pTestDummyFail :: Field
1537
pTestDummyFail =
1538
  withDoc "'OpTestDummy' fail field" .
1539
  renameField "TestDummyFail" $ simpleField "fail" [t| JSValue |]
1540

    
1541
pTestDummySubmitJobs :: Field
1542
pTestDummySubmitJobs =
1543
  withDoc "'OpTestDummy' submit_jobs field" .
1544
  renameField "TestDummySubmitJobs" $
1545
  simpleField "submit_jobs" [t| JSValue |]
1546

    
1547
pNetworkName :: Field
1548
pNetworkName =
1549
  withDoc "Network name" $
1550
  simpleField "network_name" [t| NonEmptyString |]
1551

    
1552
pNetworkAddress4 :: Field
1553
pNetworkAddress4 =
1554
  withDoc "Network address (IPv4 subnet)" .
1555
  renameField "NetworkAddress4" $
1556
  simpleField "network" [t| IPv4Network |]
1557

    
1558
pNetworkGateway4 :: Field
1559
pNetworkGateway4 =
1560
  withDoc "Network gateway (IPv4 address)" .
1561
  renameField "NetworkGateway4" .
1562
  optionalField $ simpleField "gateway" [t| IPv4Address |]
1563

    
1564
pNetworkAddress6 :: Field
1565
pNetworkAddress6 =
1566
  withDoc "Network address (IPv6 subnet)" .
1567
  renameField "NetworkAddress6" .
1568
  optionalField $ simpleField "network6" [t| IPv6Network |]
1569

    
1570
pNetworkGateway6 :: Field
1571
pNetworkGateway6 =
1572
  withDoc "Network gateway (IPv6 address)" .
1573
  renameField "NetworkGateway6" .
1574
  optionalField $ simpleField "gateway6" [t| IPv6Address |]
1575

    
1576
pNetworkMacPrefix :: Field
1577
pNetworkMacPrefix =
1578
  withDoc "Network specific mac prefix (that overrides the cluster one)" .
1579
  renameField "NetMacPrefix" $
1580
  optionalNEStringField "mac_prefix"
1581

    
1582
pNetworkAddRsvdIps :: Field
1583
pNetworkAddRsvdIps =
1584
  withDoc "Which IP addresses to reserve" .
1585
  renameField "NetworkAddRsvdIps" .
1586
  optionalField $
1587
  simpleField "add_reserved_ips" [t| [IPv4Address] |]
1588

    
1589
pNetworkRemoveRsvdIps :: Field
1590
pNetworkRemoveRsvdIps =
1591
  withDoc "Which external IP addresses to release" .
1592
  renameField "NetworkRemoveRsvdIps" .
1593
  optionalField $
1594
  simpleField "remove_reserved_ips" [t| [IPv4Address] |]
1595

    
1596
pNetworkMode :: Field
1597
pNetworkMode =
1598
  withDoc "Network mode when connecting to a group" $
1599
  simpleField "network_mode" [t| NICMode |]
1600

    
1601
pNetworkLink :: Field
1602
pNetworkLink =
1603
  withDoc "Network link when connecting to a group" $
1604
  simpleField "network_link" [t| NonEmptyString |]