Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / OpParams.hs @ 66af5ec5

History | View | Annotate | Download (43 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
  , TagObject(..)
37
  , tagObjectFrom
38
  , tagNameOf
39
  , decodeTagObject
40
  , encodeTagObject
41
  , ReplaceDisksMode(..)
42
  , DiskIndex
43
  , mkDiskIndex
44
  , unDiskIndex
45
  , DiskAccess(..)
46
  , INicParams(..)
47
  , IDiskParams(..)
48
  , RecreateDisksInfo(..)
49
  , DdmOldChanges(..)
50
  , SetParamsMods(..)
51
  , ExportTarget(..)
52
  , pInstanceName
53
  , pInstances
54
  , pName
55
  , pTagsList
56
  , pTagsObject
57
  , pOutputFields
58
  , pShutdownTimeout
59
  , pShutdownTimeout'
60
  , pShutdownInstance
61
  , pForce
62
  , pIgnoreOfflineNodes
63
  , pNodeName
64
  , pNodeNames
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
  , pMoveTargetNode
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
  , pVgName
104
  , pEnabledHypervisors
105
  , pHypervisor
106
  , pClusterHvParams
107
  , pInstHvParams
108
  , pClusterBeParams
109
  , pInstBeParams
110
  , pResetDefaults
111
  , pOsHvp
112
  , pClusterOsParams
113
  , pInstOsParams
114
  , pCandidatePoolSize
115
  , pUidPool
116
  , pAddUids
117
  , pRemoveUids
118
  , pMaintainNodeHealth
119
  , pPreallocWipeDisks
120
  , pNicParams
121
  , pInstNics
122
  , pNdParams
123
  , pIpolicy
124
  , pDrbdHelper
125
  , pDefaultIAllocator
126
  , pMasterNetdev
127
  , pMasterNetmask
128
  , pReservedLvs
129
  , pHiddenOs
130
  , pBlacklistedOs
131
  , pUseExternalMipScript
132
  , pQueryFields
133
  , pQueryFilter
134
  , pOobCommand
135
  , pOobTimeout
136
  , pIgnoreStatus
137
  , pPowerDelay
138
  , pPrimaryIp
139
  , pSecondaryIp
140
  , pReadd
141
  , pNodeGroup
142
  , pMasterCapable
143
  , pVmCapable
144
  , pNames
145
  , pNodes
146
  , pRequiredNodes
147
  , pStorageType
148
  , pStorageChanges
149
  , pMasterCandidate
150
  , pOffline
151
  , pDrained
152
  , pAutoPromote
153
  , pPowered
154
  , pIallocator
155
  , pRemoteNode
156
  , pEvacMode
157
  , pInstCreateMode
158
  , pNoInstall
159
  , pInstOs
160
  , pPrimaryNode
161
  , pSecondaryNode
162
  , pSourceHandshake
163
  , pSourceInstance
164
  , pSourceShutdownTimeout
165
  , pSourceX509Ca
166
  , pSrcNode
167
  , pSrcPath
168
  , pStartInstance
169
  , pInstTags
170
  , pMultiAllocInstances
171
  , pTempOsParams
172
  , pTempHvParams
173
  , pTempBeParams
174
  , pIgnoreFailures
175
  , pNewName
176
  , pIgnoreSecondaries
177
  , pRebootType
178
  , pIgnoreDiskSize
179
  , pRecreateDisksInfo
180
  , pStatic
181
  , pInstParamsNicChanges
182
  , pInstParamsDiskChanges
183
  , pRuntimeMem
184
  , pOsNameChange
185
  , pDiskIndex
186
  , pDiskChgAmount
187
  , pDiskChgAbsolute
188
  , pTargetGroups
189
  , pExportMode
190
  , pExportTargetNode
191
  , pRemoveInstance
192
  , pIgnoreRemoveFailures
193
  , pX509KeyName
194
  , pX509DestCA
195
  , pTagSearchPattern
196
  , pRestrictedCommand
197
  , pReplaceDisksMode
198
  , pReplaceDisksList
199
  , pAllowFailover
200
  , pDelayDuration
201
  , pDelayOnMaster
202
  , pDelayOnNodes
203
  , pDelayRepeat
204
  , pIAllocatorDirection
205
  , pIAllocatorMode
206
  , pIAllocatorReqName
207
  , pIAllocatorNics
208
  , pIAllocatorDisks
209
  , pIAllocatorMemory
210
  , pIAllocatorVCpus
211
  , pIAllocatorOs
212
  , pIAllocatorInstances
213
  , pIAllocatorEvacMode
214
  , pIAllocatorSpindleUse
215
  , pIAllocatorCount
216
  , pJQueueNotifyWaitLock
217
  , pJQueueNotifyExec
218
  , pJQueueLogMessages
219
  , pJQueueFail
220
  , pTestDummyResult
221
  , pTestDummyMessages
222
  , pTestDummyFail
223
  , pTestDummySubmitJobs
224
  , pNetworkName
225
  , pNetworkAddress4
226
  , pNetworkGateway4
227
  , pNetworkAddress6
228
  , pNetworkGateway6
229
  , pNetworkMacPrefix
230
  , pNetworkAddRsvdIps
231
  , pNetworkRemoveRsvdIps
232
  , pNetworkMode
233
  , pNetworkLink
234
  , pDryRun
235
  , pDebugLevel
236
  , pOpPriority
237
  , pDependencies
238
  , pComment
239
  , pReason
240
  -- FIXME: Remove once enabled disk templates are fully implemented
241
  , pEnabledStorageTypes
242
  , pEnabledDiskTemplates
243
  , dOldQuery
244
  , dOldQueryNoLocking
245
  ) where
246

    
247
import Control.Monad (liftM)
248
import qualified Data.Set as Set
249
import Text.JSON (readJSON, showJSON, JSON, JSValue(..), fromJSString,
250
                  JSObject, toJSObject)
251
import qualified Text.JSON
252
import Text.JSON.Pretty (pp_value)
253

    
254
import Ganeti.BasicTypes
255
import qualified Ganeti.Constants as C
256
import Ganeti.THH
257
import Ganeti.JSON
258
import Ganeti.Types
259
import qualified Ganeti.Query.Language as Qlang
260

    
261
-- * Helper functions and types
262

    
263
-- * Type aliases
264

    
265
-- | Build a boolean field.
266
booleanField :: String -> Field
267
booleanField = flip simpleField [t| Bool |]
268

    
269
-- | Default a field to 'False'.
270
defaultFalse :: String -> Field
271
defaultFalse = defaultField [| False |] . booleanField
272

    
273
-- | Default a field to 'True'.
274
defaultTrue :: String -> Field
275
defaultTrue = defaultField [| True |] . booleanField
276

    
277
-- | An alias for a 'String' field.
278
stringField :: String -> Field
279
stringField = flip simpleField [t| String |]
280

    
281
-- | An alias for an optional string field.
282
optionalStringField :: String -> Field
283
optionalStringField = optionalField . stringField
284

    
285
-- | An alias for an optional non-empty string field.
286
optionalNEStringField :: String -> Field
287
optionalNEStringField = optionalField . flip simpleField [t| NonEmptyString |]
288

    
289
-- | Unchecked value, should be replaced by a better definition.
290
type UncheckedValue = JSValue
291

    
292
-- | Unchecked dict, should be replaced by a better definition.
293
type UncheckedDict = JSObject JSValue
294

    
295
-- | Unchecked list, shoild be replaced by a better definition.
296
type UncheckedList = [JSValue]
297

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

    
307
-- ** Tags
308

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

    
318
-- | Data type holding a tag object (type and object name).
319
data TagObject = TagInstance String
320
               | TagNode     String
321
               | TagGroup    String
322
               | TagCluster
323
               deriving (Show, Eq)
324

    
325
-- | Tag type for a given tag object.
326
tagTypeOf :: TagObject -> TagType
327
tagTypeOf (TagInstance {}) = TagTypeInstance
328
tagTypeOf (TagNode     {}) = TagTypeNode
329
tagTypeOf (TagGroup    {}) = TagTypeGroup
330
tagTypeOf (TagCluster  {}) = TagTypeCluster
331

    
332
-- | Gets the potential tag object name.
333
tagNameOf :: TagObject -> Maybe String
334
tagNameOf (TagInstance s) = Just s
335
tagNameOf (TagNode     s) = Just s
336
tagNameOf (TagGroup    s) = Just s
337
tagNameOf  TagCluster     = Nothing
338

    
339
-- | Builds a 'TagObject' from a tag type and name.
340
tagObjectFrom :: (Monad m) => TagType -> JSValue -> m TagObject
341
tagObjectFrom TagTypeInstance (JSString s) =
342
  return . TagInstance $ fromJSString s
343
tagObjectFrom TagTypeNode     (JSString s) = return . TagNode $ fromJSString s
344
tagObjectFrom TagTypeGroup    (JSString s) = return . TagGroup $ fromJSString s
345
tagObjectFrom TagTypeCluster   JSNull      = return TagCluster
346
tagObjectFrom t v =
347
  fail $ "Invalid tag type/name combination: " ++ show t ++ "/" ++
348
         show (pp_value v)
349

    
350
-- | Name of the tag \"name\" field.
351
tagNameField :: String
352
tagNameField = "name"
353

    
354
-- | Custom encoder for 'TagObject' as represented in an opcode.
355
encodeTagObject :: TagObject -> (JSValue, [(String, JSValue)])
356
encodeTagObject t = ( showJSON (tagTypeOf t)
357
                    , [(tagNameField, maybe JSNull showJSON (tagNameOf t))] )
358

    
359
-- | Custom decoder for 'TagObject' as represented in an opcode.
360
decodeTagObject :: (Monad m) => [(String, JSValue)] -> JSValue -> m TagObject
361
decodeTagObject obj kind = do
362
  ttype <- fromJVal kind
363
  tname <- fromObj obj tagNameField
364
  tagObjectFrom ttype tname
365

    
366
-- ** Disks
367

    
368
-- | Replace disks type.
369
$(declareSADT "ReplaceDisksMode"
370
  [ ("ReplaceOnPrimary",    'C.replaceDiskPri)
371
  , ("ReplaceOnSecondary",  'C.replaceDiskSec)
372
  , ("ReplaceNewSecondary", 'C.replaceDiskChg)
373
  , ("ReplaceAuto",         'C.replaceDiskAuto)
374
  ])
375
$(makeJSONInstance ''ReplaceDisksMode)
376

    
377
-- | Disk index type (embedding constraints on the index value via a
378
-- smart constructor).
379
newtype DiskIndex = DiskIndex { unDiskIndex :: Int }
380
  deriving (Show, Eq, Ord)
381

    
382
-- | Smart constructor for 'DiskIndex'.
383
mkDiskIndex :: (Monad m) => Int -> m DiskIndex
384
mkDiskIndex i | i >= 0 && i < C.maxDisks = return (DiskIndex i)
385
              | otherwise = fail $ "Invalid value for disk index '" ++
386
                            show i ++ "', required between 0 and " ++
387
                            show C.maxDisks
388

    
389
instance JSON DiskIndex where
390
  readJSON v = readJSON v >>= mkDiskIndex
391
  showJSON = showJSON . unDiskIndex
392

    
393
-- ** I* param types
394

    
395
-- | Type holding disk access modes.
396
$(declareSADT "DiskAccess"
397
  [ ("DiskReadOnly",  'C.diskRdonly)
398
  , ("DiskReadWrite", 'C.diskRdwr)
399
  ])
400
$(makeJSONInstance ''DiskAccess)
401

    
402
-- | NIC modification definition.
403
$(buildObject "INicParams" "inic"
404
  [ optionalField $ simpleField C.inicMac  [t| NonEmptyString |]
405
  , optionalField $ simpleField C.inicIp   [t| String         |]
406
  , optionalField $ simpleField C.inicMode [t| NonEmptyString |]
407
  , optionalField $ simpleField C.inicLink [t| NonEmptyString |]
408
  ])
409

    
410
-- | Disk modification definition. FIXME: disksize should be VTYPE_UNIT.
411
$(buildObject "IDiskParams" "idisk"
412
  [ optionalField $ simpleField C.idiskSize   [t| Int            |]
413
  , optionalField $ simpleField C.idiskMode   [t| DiskAccess     |]
414
  , optionalField $ simpleField C.idiskAdopt  [t| NonEmptyString |]
415
  , optionalField $ simpleField C.idiskVg     [t| NonEmptyString |]
416
  , optionalField $ simpleField C.idiskMetavg [t| NonEmptyString |]
417
  ])
418

    
419
-- | Disk changes type for OpInstanceRecreateDisks. This is a bit
420
-- strange, because the type in Python is something like Either
421
-- [DiskIndex] [DiskChanges], but we can't represent the type of an
422
-- empty list in JSON, so we have to add a custom case for the empty
423
-- list.
424
data RecreateDisksInfo
425
  = RecreateDisksAll
426
  | RecreateDisksIndices (NonEmpty DiskIndex)
427
  | RecreateDisksParams (NonEmpty (DiskIndex, IDiskParams))
428
    deriving (Eq, Show)
429

    
430
readRecreateDisks :: JSValue -> Text.JSON.Result RecreateDisksInfo
431
readRecreateDisks (JSArray []) = return RecreateDisksAll
432
readRecreateDisks v =
433
  case readJSON v::Text.JSON.Result [DiskIndex] of
434
    Text.JSON.Ok indices -> liftM RecreateDisksIndices (mkNonEmpty indices)
435
    _ -> case readJSON v::Text.JSON.Result [(DiskIndex, IDiskParams)] of
436
           Text.JSON.Ok params -> liftM RecreateDisksParams (mkNonEmpty params)
437
           _ -> fail $ "Can't parse disk information as either list of disk"
438
                ++ " indices or list of disk parameters; value received:"
439
                ++ show (pp_value v)
440

    
441
instance JSON RecreateDisksInfo where
442
  readJSON = readRecreateDisks
443
  showJSON  RecreateDisksAll            = showJSON ()
444
  showJSON (RecreateDisksIndices idx)   = showJSON idx
445
  showJSON (RecreateDisksParams params) = showJSON params
446

    
447
-- | Simple type for old-style ddm changes.
448
data DdmOldChanges = DdmOldIndex (NonNegative Int)
449
                   | DdmOldMod DdmSimple
450
                     deriving (Eq, Show)
451

    
452
readDdmOldChanges :: JSValue -> Text.JSON.Result DdmOldChanges
453
readDdmOldChanges v =
454
  case readJSON v::Text.JSON.Result (NonNegative Int) of
455
    Text.JSON.Ok nn -> return $ DdmOldIndex nn
456
    _ -> case readJSON v::Text.JSON.Result DdmSimple of
457
           Text.JSON.Ok ddms -> return $ DdmOldMod ddms
458
           _ -> fail $ "Can't parse value '" ++ show (pp_value v) ++ "' as"
459
                ++ " either index or modification"
460

    
461
instance JSON DdmOldChanges where
462
  showJSON (DdmOldIndex i) = showJSON i
463
  showJSON (DdmOldMod m)   = showJSON m
464
  readJSON = readDdmOldChanges
465

    
466
-- | Instance disk or nic modifications.
467
data SetParamsMods a
468
  = SetParamsEmpty
469
  | SetParamsDeprecated (NonEmpty (DdmOldChanges, a))
470
  | SetParamsNew (NonEmpty (DdmFull, Int, a))
471
    deriving (Eq, Show)
472

    
473
-- | Custom deserialiser for 'SetParamsMods'.
474
readSetParams :: (JSON a) => JSValue -> Text.JSON.Result (SetParamsMods a)
475
readSetParams (JSArray []) = return SetParamsEmpty
476
readSetParams v =
477
  case readJSON v::Text.JSON.Result [(DdmOldChanges, JSValue)] of
478
    Text.JSON.Ok _ -> liftM SetParamsDeprecated $ readJSON v
479
    _ -> liftM SetParamsNew $ readJSON v
480

    
481
instance (JSON a) => JSON (SetParamsMods a) where
482
  showJSON SetParamsEmpty = showJSON ()
483
  showJSON (SetParamsDeprecated v) = showJSON v
484
  showJSON (SetParamsNew v) = showJSON v
485
  readJSON = readSetParams
486

    
487
-- | Custom type for target_node parameter of OpBackupExport, which
488
-- varies depending on mode. FIXME: this uses an UncheckedList since
489
-- we don't care about individual rows (just like the Python code
490
-- tests). But the proper type could be parsed if we wanted.
491
data ExportTarget = ExportTargetLocal NonEmptyString
492
                  | ExportTargetRemote UncheckedList
493
                    deriving (Eq, Show)
494

    
495
-- | Custom reader for 'ExportTarget'.
496
readExportTarget :: JSValue -> Text.JSON.Result ExportTarget
497
readExportTarget (JSString s) = liftM ExportTargetLocal $
498
                                mkNonEmpty (fromJSString s)
499
readExportTarget (JSArray arr) = return $ ExportTargetRemote arr
500
readExportTarget v = fail $ "Invalid value received for 'target_node': " ++
501
                     show (pp_value v)
502

    
503
instance JSON ExportTarget where
504
  showJSON (ExportTargetLocal s)  = showJSON s
505
  showJSON (ExportTargetRemote l) = showJSON l
506
  readJSON = readExportTarget
507

    
508
-- * Parameters
509

    
510
-- | A required instance name (for single-instance LUs).
511
pInstanceName :: Field
512
pInstanceName = simpleField "instance_name" [t| String |]
513

    
514
-- | A list of instances.
515
pInstances :: Field
516
pInstances = defaultField [| [] |] $
517
             simpleField "instances" [t| [NonEmptyString] |]
518

    
519
-- | A generic name.
520
pName :: Field
521
pName = simpleField "name" [t| NonEmptyString |]
522

    
523
-- | Tags list.
524
pTagsList :: Field
525
pTagsList = simpleField "tags" [t| [String] |]
526

    
527
-- | Tags object.
528
pTagsObject :: Field
529
pTagsObject =
530
  customField 'decodeTagObject 'encodeTagObject [tagNameField] $
531
  simpleField "kind" [t| TagObject |]
532

    
533
-- | Selected output fields.
534
pOutputFields :: Field
535
pOutputFields = simpleField "output_fields" [t| [NonEmptyString] |]
536

    
537
-- | How long to wait for instance to shut down.
538
pShutdownTimeout :: Field
539
pShutdownTimeout = defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
540
                   simpleField "shutdown_timeout" [t| NonNegative Int |]
541

    
542
-- | Another name for the shutdown timeout, because we like to be
543
-- inconsistent.
544
pShutdownTimeout' :: Field
545
pShutdownTimeout' =
546
  renameField "InstShutdownTimeout" .
547
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
548
  simpleField "timeout" [t| NonNegative Int |]
549

    
550
-- | Whether to shutdown the instance in backup-export.
551
pShutdownInstance :: Field
552
pShutdownInstance = defaultTrue "shutdown"
553

    
554
-- | Whether to force the operation.
555
pForce :: Field
556
pForce = defaultFalse "force"
557

    
558
-- | Whether to ignore offline nodes.
559
pIgnoreOfflineNodes :: Field
560
pIgnoreOfflineNodes = defaultFalse "ignore_offline_nodes"
561

    
562
-- | A required node name (for single-node LUs).
563
pNodeName :: Field
564
pNodeName = simpleField "node_name" [t| NonEmptyString |]
565

    
566
-- | List of nodes.
567
pNodeNames :: Field
568
pNodeNames =
569
  defaultField [| [] |] $ simpleField "node_names" [t| [NonEmptyString] |]
570

    
571
-- | A required node group name (for single-group LUs).
572
pGroupName :: Field
573
pGroupName = simpleField "group_name" [t| NonEmptyString |]
574

    
575
-- | Migration type (live\/non-live).
576
pMigrationMode :: Field
577
pMigrationMode =
578
  renameField "MigrationMode" .
579
  optionalField $
580
  simpleField "mode" [t| MigrationMode |]
581

    
582
-- | Obsolete \'live\' migration mode (boolean).
583
pMigrationLive :: Field
584
pMigrationLive =
585
  renameField "OldLiveMode" . optionalField $ booleanField "live"
586

    
587
-- | Migration cleanup parameter.
588
pMigrationCleanup :: Field
589
pMigrationCleanup = renameField "MigrationCleanup" $ defaultFalse "cleanup"
590

    
591
-- | Whether to force an unknown OS variant.
592
pForceVariant :: Field
593
pForceVariant = defaultFalse "force_variant"
594

    
595
-- | Whether to wait for the disk to synchronize.
596
pWaitForSync :: Field
597
pWaitForSync = defaultTrue "wait_for_sync"
598

    
599
-- | Whether to wait for the disk to synchronize (defaults to false).
600
pWaitForSyncFalse :: Field
601
pWaitForSyncFalse = defaultField [| False |] pWaitForSync
602

    
603
-- | Whether to ignore disk consistency
604
pIgnoreConsistency :: Field
605
pIgnoreConsistency = defaultFalse "ignore_consistency"
606

    
607
-- | Storage name.
608
pStorageName :: Field
609
pStorageName =
610
  renameField "StorageName" $ simpleField "name" [t| NonEmptyString |]
611

    
612
-- | Whether to use synchronization.
613
pUseLocking :: Field
614
pUseLocking = defaultFalse "use_locking"
615

    
616
-- | Whether to employ opportunistic locking for nodes, meaning nodes already
617
-- locked by another opcode won't be considered for instance allocation (only
618
-- when an iallocator is used).
619
pOpportunisticLocking :: Field
620
pOpportunisticLocking = defaultFalse "opportunistic_locking"
621

    
622
-- | Whether to check name.
623
pNameCheck :: Field
624
pNameCheck = defaultTrue "name_check"
625

    
626
-- | Instance allocation policy.
627
pNodeGroupAllocPolicy :: Field
628
pNodeGroupAllocPolicy = optionalField $
629
                        simpleField "alloc_policy" [t| AllocPolicy |]
630

    
631
-- | Default node parameters for group.
632
pGroupNodeParams :: Field
633
pGroupNodeParams = optionalField $ simpleField "ndparams" [t| UncheckedDict |]
634

    
635
-- | Resource(s) to query for.
636
pQueryWhat :: Field
637
pQueryWhat = simpleField "what" [t| Qlang.QueryTypeOp |]
638

    
639
-- | Whether to release locks as soon as possible.
640
pEarlyRelease :: Field
641
pEarlyRelease = defaultFalse "early_release"
642

    
643
-- | Whether to ensure instance's IP address is inactive.
644
pIpCheck :: Field
645
pIpCheck = defaultTrue "ip_check"
646

    
647
-- | Check for conflicting IPs.
648
pIpConflictsCheck :: Field
649
pIpConflictsCheck = defaultTrue "conflicts_check"
650

    
651
-- | Do not remember instance state changes.
652
pNoRemember :: Field
653
pNoRemember = defaultFalse "no_remember"
654

    
655
-- | Target node for instance migration/failover.
656
pMigrationTargetNode :: Field
657
pMigrationTargetNode = optionalNEStringField "target_node"
658

    
659
-- | Target node for instance move (required).
660
pMoveTargetNode :: Field
661
pMoveTargetNode =
662
  renameField "MoveTargetNode" $
663
  simpleField "target_node" [t| NonEmptyString |]
664

    
665
-- | Pause instance at startup.
666
pStartupPaused :: Field
667
pStartupPaused = defaultFalse "startup_paused"
668

    
669
-- | Verbose mode.
670
pVerbose :: Field
671
pVerbose = defaultFalse "verbose"
672

    
673
-- ** Parameters for cluster verification
674

    
675
-- | Whether to simulate errors (useful for debugging).
676
pDebugSimulateErrors :: Field
677
pDebugSimulateErrors = defaultFalse "debug_simulate_errors"
678

    
679
-- | Error codes.
680
pErrorCodes :: Field
681
pErrorCodes = defaultFalse "error_codes"
682

    
683
-- | Which checks to skip.
684
pSkipChecks :: Field
685
pSkipChecks = defaultField [| Set.empty |] $
686
              simpleField "skip_checks" [t| Set.Set VerifyOptionalChecks |]
687

    
688
-- | List of error codes that should be treated as warnings.
689
pIgnoreErrors :: Field
690
pIgnoreErrors = defaultField [| Set.empty |] $
691
                simpleField "ignore_errors" [t| Set.Set CVErrorCode |]
692

    
693
-- | Optional group name.
694
pOptGroupName :: Field
695
pOptGroupName = renameField "OptGroupName" .
696
                optionalField $ simpleField "group_name" [t| NonEmptyString |]
697

    
698
-- | Disk templates' parameter defaults.
699
pDiskParams :: Field
700
pDiskParams = optionalField $
701
              simpleField "diskparams" [t| GenericContainer DiskTemplate
702
                                           UncheckedDict |]
703

    
704
-- * Parameters for node resource model
705

    
706
-- | Set hypervisor states.
707
pHvState :: Field
708
pHvState = optionalField $ simpleField "hv_state" [t| UncheckedDict |]
709

    
710
-- | Set disk states.
711
pDiskState :: Field
712
pDiskState = optionalField $ simpleField "disk_state" [t| UncheckedDict |]
713

    
714
-- | Whether to ignore ipolicy violations.
715
pIgnoreIpolicy :: Field
716
pIgnoreIpolicy = defaultFalse "ignore_ipolicy"
717

    
718
-- | Allow runtime changes while migrating.
719
pAllowRuntimeChgs :: Field
720
pAllowRuntimeChgs = defaultTrue "allow_runtime_changes"
721

    
722
-- | Utility type for OpClusterSetParams.
723
type TestClusterOsListItem = (DdmSimple, NonEmptyString)
724

    
725
-- | Utility type of OsList.
726
type TestClusterOsList = [TestClusterOsListItem]
727

    
728
-- Utility type for NIC definitions.
729
--type TestNicDef = INicParams
730

    
731
-- | List of instance disks.
732
pInstDisks :: Field
733
pInstDisks = renameField "instDisks" $ simpleField "disks" [t| [IDiskParams] |]
734

    
735
-- | Instance disk template.
736
pDiskTemplate :: Field
737
pDiskTemplate = simpleField "disk_template" [t| DiskTemplate |]
738

    
739
-- | Instance disk template.
740
pOptDiskTemplate :: Field
741
pOptDiskTemplate =
742
  optionalField .
743
  renameField "OptDiskTemplate" $
744
  simpleField "disk_template" [t| DiskTemplate |]
745

    
746
-- | File driver.
747
pFileDriver :: Field
748
pFileDriver = optionalField $ simpleField "file_driver" [t| FileDriver |]
749

    
750
-- | Directory for storing file-backed disks.
751
pFileStorageDir :: Field
752
pFileStorageDir = optionalNEStringField "file_storage_dir"
753

    
754
-- | Volume group name.
755
pVgName :: Field
756
pVgName = optionalStringField "vg_name"
757

    
758
-- | List of enabled hypervisors.
759
pEnabledHypervisors :: Field
760
pEnabledHypervisors =
761
  optionalField $
762
  simpleField "enabled_hypervisors" [t| NonEmpty Hypervisor |]
763

    
764
-- | List of enabled storage methods.
765
-- FIXME: Remove once enabled disk templates are fully implemented.
766
pEnabledStorageTypes :: Field
767
pEnabledStorageTypes =
768
  optionalField $
769
  simpleField "enabled_storage_types" [t| NonEmpty StorageType |]
770

    
771
-- | List of enabled disk templates.
772
pEnabledDiskTemplates :: Field
773
pEnabledDiskTemplates =
774
  optionalField $
775
  simpleField "enabled_disk_templates" [t| NonEmpty DiskTemplate |]
776

    
777
-- | Selected hypervisor for an instance.
778
pHypervisor :: Field
779
pHypervisor =
780
  optionalField $
781
  simpleField "hypervisor" [t| Hypervisor |]
782

    
783
-- | Cluster-wide hypervisor parameters, hypervisor-dependent.
784
pClusterHvParams :: Field
785
pClusterHvParams =
786
  renameField "ClusterHvParams" .
787
  optionalField $
788
  simpleField "hvparams" [t| Container UncheckedDict |]
789

    
790
-- | Instance hypervisor parameters.
791
pInstHvParams :: Field
792
pInstHvParams =
793
  renameField "InstHvParams" .
794
  defaultField [| toJSObject [] |] $
795
  simpleField "hvparams" [t| UncheckedDict |]
796

    
797
-- | Cluster-wide beparams.
798
pClusterBeParams :: Field
799
pClusterBeParams =
800
  renameField "ClusterBeParams" .
801
  optionalField $ simpleField "beparams" [t| UncheckedDict |]
802

    
803
-- | Instance beparams.
804
pInstBeParams :: Field
805
pInstBeParams =
806
  renameField "InstBeParams" .
807
  defaultField [| toJSObject [] |] $
808
  simpleField "beparams" [t| UncheckedDict |]
809

    
810
-- | Reset instance parameters to default if equal.
811
pResetDefaults :: Field
812
pResetDefaults = defaultFalse "identify_defaults"
813

    
814
-- | Cluster-wide per-OS hypervisor parameter defaults.
815
pOsHvp :: Field
816
pOsHvp = optionalField $ simpleField "os_hvp" [t| Container UncheckedDict |]
817

    
818
-- | Cluster-wide OS parameter defaults.
819
pClusterOsParams :: Field
820
pClusterOsParams =
821
  renameField "ClusterOsParams" .
822
  optionalField $ simpleField "osparams" [t| Container UncheckedDict |]
823

    
824
-- | Instance OS parameters.
825
pInstOsParams :: Field
826
pInstOsParams =
827
  renameField "InstOsParams" . defaultField [| toJSObject [] |] $
828
  simpleField "osparams" [t| UncheckedDict |]
829

    
830
-- | Temporary OS parameters (currently only in reinstall, might be
831
-- added to install as well).
832
pTempOsParams :: Field
833
pTempOsParams =
834
  renameField "TempOsParams" .
835
  optionalField $ simpleField "osparams" [t| UncheckedDict |]
836

    
837
-- | Temporary hypervisor parameters, hypervisor-dependent.
838
pTempHvParams :: Field
839
pTempHvParams =
840
  renameField "TempHvParams" .
841
  defaultField [| toJSObject [] |] $
842
  simpleField "hvparams" [t| UncheckedDict |]
843

    
844
-- | Temporary backend parameters.
845
pTempBeParams :: Field
846
pTempBeParams =
847
  renameField "TempBeParams" .
848
  defaultField [| toJSObject [] |] $
849
  simpleField "beparams" [t| UncheckedDict |]
850

    
851
-- | Candidate pool size.
852
pCandidatePoolSize :: Field
853
pCandidatePoolSize =
854
  optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]
855

    
856
-- | Set UID pool, must be list of lists describing UID ranges (two
857
-- items, start and end inclusive.
858
pUidPool :: Field
859
pUidPool = optionalField $ simpleField "uid_pool" [t| [[(Int, Int)]] |]
860

    
861
-- | Extend UID pool, must be list of lists describing UID ranges (two
862
-- items, start and end inclusive.
863
pAddUids :: Field
864
pAddUids = optionalField $ simpleField "add_uids" [t| [[(Int, Int)]] |]
865

    
866
-- | Shrink UID pool, must be list of lists describing UID ranges (two
867
-- items, start and end inclusive) to be removed.
868
pRemoveUids :: Field
869
pRemoveUids = optionalField $ simpleField "remove_uids" [t| [[(Int, Int)]] |]
870

    
871
-- | Whether to automatically maintain node health.
872
pMaintainNodeHealth :: Field
873
pMaintainNodeHealth = optionalField $ booleanField "maintain_node_health"
874

    
875
-- | Whether to wipe disks before allocating them to instances.
876
pPreallocWipeDisks :: Field
877
pPreallocWipeDisks = optionalField $ booleanField "prealloc_wipe_disks"
878

    
879
-- | Cluster-wide NIC parameter defaults.
880
pNicParams :: Field
881
pNicParams = optionalField $ simpleField "nicparams" [t| INicParams |]
882

    
883
-- | Instance NIC definitions.
884
pInstNics :: Field
885
pInstNics = simpleField "nics" [t| [INicParams] |]
886

    
887
-- | Cluster-wide node parameter defaults.
888
pNdParams :: Field
889
pNdParams = optionalField $ simpleField "ndparams" [t| UncheckedDict |]
890

    
891
-- | Cluster-wide ipolicy specs.
892
pIpolicy :: Field
893
pIpolicy = optionalField $ simpleField "ipolicy" [t| UncheckedDict |]
894

    
895
-- | DRBD helper program.
896
pDrbdHelper :: Field
897
pDrbdHelper = optionalStringField "drbd_helper"
898

    
899
-- | Default iallocator for cluster.
900
pDefaultIAllocator :: Field
901
pDefaultIAllocator = optionalStringField "default_iallocator"
902

    
903
-- | Master network device.
904
pMasterNetdev :: Field
905
pMasterNetdev = optionalStringField "master_netdev"
906

    
907
-- | Netmask of the master IP.
908
pMasterNetmask :: Field
909
pMasterNetmask =
910
  optionalField $ simpleField "master_netmask" [t| NonNegative Int |]
911

    
912
-- | List of reserved LVs.
913
pReservedLvs :: Field
914
pReservedLvs =
915
  optionalField $ simpleField "reserved_lvs" [t| [NonEmptyString] |]
916

    
917
-- | Modify list of hidden operating systems: each modification must
918
-- have two items, the operation and the OS name; the operation can be
919
-- add or remove.
920
pHiddenOs :: Field
921
pHiddenOs = optionalField $ simpleField "hidden_os" [t| TestClusterOsList |]
922

    
923
-- | Modify list of blacklisted operating systems: each modification
924
-- must have two items, the operation and the OS name; the operation
925
-- can be add or remove.
926
pBlacklistedOs :: Field
927
pBlacklistedOs =
928
  optionalField $ simpleField "blacklisted_os" [t| TestClusterOsList |]
929

    
930
-- | Whether to use an external master IP address setup script.
931
pUseExternalMipScript :: Field
932
pUseExternalMipScript = optionalField $ booleanField "use_external_mip_script"
933

    
934
-- | Requested fields.
935
pQueryFields :: Field
936
pQueryFields = simpleField "fields" [t| [NonEmptyString] |]
937

    
938
-- | Query filter.
939
pQueryFilter :: Field
940
pQueryFilter = simpleField "qfilter" [t| Qlang.Filter String |]
941

    
942
-- | OOB command to run.
943
pOobCommand :: Field
944
pOobCommand = simpleField "command" [t| OobCommand |]
945

    
946
-- | Timeout before the OOB helper will be terminated.
947
pOobTimeout :: Field
948
pOobTimeout =
949
  defaultField [| C.oobTimeout |] $ simpleField "timeout" [t| Int |]
950

    
951
-- | Ignores the node offline status for power off.
952
pIgnoreStatus :: Field
953
pIgnoreStatus = defaultFalse "ignore_status"
954

    
955
-- | Time in seconds to wait between powering on nodes.
956
pPowerDelay :: Field
957
pPowerDelay =
958
  -- FIXME: we can't use the proper type "NonNegative Double", since
959
  -- the default constant is a plain Double, not a non-negative one.
960
  defaultField [| C.oobPowerDelay |] $
961
  simpleField "power_delay" [t| Double |]
962

    
963
-- | Primary IP address.
964
pPrimaryIp :: Field
965
pPrimaryIp = optionalStringField "primary_ip"
966

    
967
-- | Secondary IP address.
968
pSecondaryIp :: Field
969
pSecondaryIp = optionalNEStringField "secondary_ip"
970

    
971
-- | Whether node is re-added to cluster.
972
pReadd :: Field
973
pReadd = defaultFalse "readd"
974

    
975
-- | Initial node group.
976
pNodeGroup :: Field
977
pNodeGroup = optionalNEStringField "group"
978

    
979
-- | Whether node can become master or master candidate.
980
pMasterCapable :: Field
981
pMasterCapable = optionalField $ booleanField "master_capable"
982

    
983
-- | Whether node can host instances.
984
pVmCapable :: Field
985
pVmCapable = optionalField $ booleanField "vm_capable"
986

    
987
-- | List of names.
988
pNames :: Field
989
pNames = defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
990

    
991
-- | List of node names.
992
pNodes :: Field
993
pNodes = defaultField [| [] |] $ simpleField "nodes" [t| [NonEmptyString] |]
994

    
995
-- | Required list of node names.
996
pRequiredNodes :: Field
997
pRequiredNodes =
998
  renameField "ReqNodes " $ simpleField "nodes" [t| [NonEmptyString] |]
999

    
1000
-- | Storage type.
1001
pStorageType :: Field
1002
pStorageType = simpleField "storage_type" [t| StorageType |]
1003

    
1004
-- | Storage changes (unchecked).
1005
pStorageChanges :: Field
1006
pStorageChanges = simpleField "changes" [t| UncheckedDict |]
1007

    
1008
-- | Whether the node should become a master candidate.
1009
pMasterCandidate :: Field
1010
pMasterCandidate = optionalField $ booleanField "master_candidate"
1011

    
1012
-- | Whether the node should be marked as offline.
1013
pOffline :: Field
1014
pOffline = optionalField $ booleanField "offline"
1015

    
1016
-- | Whether the node should be marked as drained.
1017
pDrained ::Field
1018
pDrained = optionalField $ booleanField "drained"
1019

    
1020
-- | Whether node(s) should be promoted to master candidate if necessary.
1021
pAutoPromote :: Field
1022
pAutoPromote = defaultFalse "auto_promote"
1023

    
1024
-- | Whether the node should be marked as powered
1025
pPowered :: Field
1026
pPowered = optionalField $ booleanField "powered"
1027

    
1028
-- | Iallocator for deciding the target node for shared-storage
1029
-- instances during migrate and failover.
1030
pIallocator :: Field
1031
pIallocator = optionalNEStringField "iallocator"
1032

    
1033
-- | New secondary node.
1034
pRemoteNode :: Field
1035
pRemoteNode = optionalNEStringField "remote_node"
1036

    
1037
-- | Node evacuation mode.
1038
pEvacMode :: Field
1039
pEvacMode = renameField "EvacMode" $ simpleField "mode" [t| NodeEvacMode |]
1040

    
1041
-- | Instance creation mode.
1042
pInstCreateMode :: Field
1043
pInstCreateMode =
1044
  renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]
1045

    
1046
-- | Do not install the OS (will disable automatic start).
1047
pNoInstall :: Field
1048
pNoInstall = optionalField $ booleanField "no_install"
1049

    
1050
-- | OS type for instance installation.
1051
pInstOs :: Field
1052
pInstOs = optionalNEStringField "os_type"
1053

    
1054
-- | Primary node for an instance.
1055
pPrimaryNode :: Field
1056
pPrimaryNode = optionalNEStringField "pnode"
1057

    
1058
-- | Secondary node for an instance.
1059
pSecondaryNode :: Field
1060
pSecondaryNode = optionalNEStringField "snode"
1061

    
1062
-- | Signed handshake from source (remote import only).
1063
pSourceHandshake :: Field
1064
pSourceHandshake =
1065
  optionalField $ simpleField "source_handshake" [t| UncheckedList |]
1066

    
1067
-- | Source instance name (remote import only).
1068
pSourceInstance :: Field
1069
pSourceInstance = optionalNEStringField "source_instance_name"
1070

    
1071
-- | How long source instance was given to shut down (remote import only).
1072
-- FIXME: non-negative int, whereas the constant is a plain int.
1073
pSourceShutdownTimeout :: Field
1074
pSourceShutdownTimeout =
1075
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
1076
  simpleField "source_shutdown_timeout" [t| NonNegative Int |]
1077

    
1078
-- | Source X509 CA in PEM format (remote import only).
1079
pSourceX509Ca :: Field
1080
pSourceX509Ca = optionalNEStringField "source_x509_ca"
1081

    
1082
-- | Source node for import.
1083
pSrcNode :: Field
1084
pSrcNode = optionalNEStringField "src_node"
1085

    
1086
-- | Source directory for import.
1087
pSrcPath :: Field
1088
pSrcPath = optionalNEStringField "src_path"
1089

    
1090
-- | Whether to start instance after creation.
1091
pStartInstance :: Field
1092
pStartInstance = defaultTrue "start"
1093

    
1094
-- | Instance tags. FIXME: unify/simplify with pTags, once that
1095
-- migrates to NonEmpty String.
1096
pInstTags :: Field
1097
pInstTags =
1098
  renameField "InstTags" .
1099
  defaultField [| [] |] $
1100
  simpleField "tags" [t| [NonEmptyString] |]
1101

    
1102
-- | Unchecked list of OpInstanceCreate, used in OpInstanceMultiAlloc.
1103
pMultiAllocInstances :: Field
1104
pMultiAllocInstances =
1105
  renameField "InstMultiAlloc" .
1106
  defaultField [| [] |] $
1107
  simpleField "instances"[t| UncheckedList |]
1108

    
1109
-- | Ignore failures parameter.
1110
pIgnoreFailures :: Field
1111
pIgnoreFailures = defaultFalse "ignore_failures"
1112

    
1113
-- | New instance or cluster name.
1114
pNewName :: Field
1115
pNewName = simpleField "new_name" [t| NonEmptyString |]
1116

    
1117
-- | Whether to start the instance even if secondary disks are failing.
1118
pIgnoreSecondaries :: Field
1119
pIgnoreSecondaries = defaultFalse "ignore_secondaries"
1120

    
1121
-- | How to reboot the instance.
1122
pRebootType :: Field
1123
pRebootType = simpleField "reboot_type" [t| RebootType |]
1124

    
1125
-- | Whether to ignore recorded disk size.
1126
pIgnoreDiskSize :: Field
1127
pIgnoreDiskSize = defaultFalse "ignore_size"
1128

    
1129
-- | Disk list for recreate disks.
1130
pRecreateDisksInfo :: Field
1131
pRecreateDisksInfo =
1132
  renameField "RecreateDisksInfo" .
1133
  defaultField [| RecreateDisksAll |] $
1134
  simpleField "disks" [t| RecreateDisksInfo |]
1135

    
1136
-- | Whether to only return configuration data without querying nodes.
1137
pStatic :: Field
1138
pStatic = defaultFalse "static"
1139

    
1140
-- | InstanceSetParams NIC changes.
1141
pInstParamsNicChanges :: Field
1142
pInstParamsNicChanges =
1143
  renameField "InstNicChanges" .
1144
  defaultField [| SetParamsEmpty |] $
1145
  simpleField "nics" [t| SetParamsMods INicParams |]
1146

    
1147
-- | InstanceSetParams Disk changes.
1148
pInstParamsDiskChanges :: Field
1149
pInstParamsDiskChanges =
1150
  renameField "InstDiskChanges" .
1151
  defaultField [| SetParamsEmpty |] $
1152
  simpleField "disks" [t| SetParamsMods IDiskParams |]
1153

    
1154
-- | New runtime memory.
1155
pRuntimeMem :: Field
1156
pRuntimeMem = optionalField $ simpleField "runtime_mem" [t| Positive Int |]
1157

    
1158
-- | Change the instance's OS without reinstalling the instance
1159
pOsNameChange :: Field
1160
pOsNameChange = optionalNEStringField "os_name"
1161

    
1162
-- | Disk index for e.g. grow disk.
1163
pDiskIndex :: Field
1164
pDiskIndex = renameField "DiskIndex " $ simpleField "disk" [t| DiskIndex |]
1165

    
1166
-- | Disk amount to add or grow to.
1167
pDiskChgAmount :: Field
1168
pDiskChgAmount =
1169
  renameField "DiskChgAmount" $ simpleField "amount" [t| NonNegative Int |]
1170

    
1171
-- | Whether the amount parameter is an absolute target or a relative one.
1172
pDiskChgAbsolute :: Field
1173
pDiskChgAbsolute = renameField "DiskChkAbsolute" $ defaultFalse "absolute"
1174

    
1175
-- | Destination group names or UUIDs (defaults to \"all but current group\".
1176
pTargetGroups :: Field
1177
pTargetGroups =
1178
  optionalField $ simpleField "target_groups" [t| [NonEmptyString] |]
1179

    
1180
-- | Export mode field.
1181
pExportMode :: Field
1182
pExportMode =
1183
  renameField "ExportMode" $ simpleField "mode" [t| ExportMode |]
1184

    
1185
-- | Export target_node field, depends on mode.
1186
pExportTargetNode :: Field
1187
pExportTargetNode =
1188
  renameField "ExportTarget" $
1189
  simpleField "target_node" [t| ExportTarget |]
1190

    
1191
-- | Whether to remove instance after export.
1192
pRemoveInstance :: Field
1193
pRemoveInstance = defaultFalse "remove_instance"
1194

    
1195
-- | Whether to ignore failures while removing instances.
1196
pIgnoreRemoveFailures :: Field
1197
pIgnoreRemoveFailures = defaultFalse "ignore_remove_failures"
1198

    
1199
-- | Name of X509 key (remote export only).
1200
pX509KeyName :: Field
1201
pX509KeyName = optionalField $ simpleField "x509_key_name" [t| UncheckedList |]
1202

    
1203
-- | Destination X509 CA (remote export only).
1204
pX509DestCA :: Field
1205
pX509DestCA = optionalNEStringField "destination_x509_ca"
1206

    
1207
-- | Search pattern (regular expression). FIXME: this should be
1208
-- compiled at load time?
1209
pTagSearchPattern :: Field
1210
pTagSearchPattern =
1211
  renameField "TagSearchPattern" $ simpleField "pattern" [t| NonEmptyString |]
1212

    
1213
-- | Restricted command name.
1214
pRestrictedCommand :: Field
1215
pRestrictedCommand =
1216
  renameField "RestrictedCommand" $
1217
  simpleField "command" [t| NonEmptyString |]
1218

    
1219
-- | Replace disks mode.
1220
pReplaceDisksMode :: Field
1221
pReplaceDisksMode =
1222
  renameField "ReplaceDisksMode" $ simpleField "mode" [t| ReplaceDisksMode |]
1223

    
1224
-- | List of disk indices.
1225
pReplaceDisksList :: Field
1226
pReplaceDisksList =
1227
  renameField "ReplaceDisksList" $ simpleField "disks" [t| [DiskIndex] |]
1228

    
1229
-- | Whether do allow failover in migrations.
1230
pAllowFailover :: Field
1231
pAllowFailover = defaultFalse "allow_failover"
1232

    
1233
-- * Test opcode parameters
1234

    
1235
-- | Duration parameter for 'OpTestDelay'.
1236
pDelayDuration :: Field
1237
pDelayDuration =
1238
  renameField "DelayDuration" $ simpleField "duration" [t| Double |]
1239

    
1240
-- | on_master field for 'OpTestDelay'.
1241
pDelayOnMaster :: Field
1242
pDelayOnMaster = renameField "DelayOnMaster" $ defaultTrue "on_master"
1243

    
1244
-- | on_nodes field for 'OpTestDelay'.
1245
pDelayOnNodes :: Field
1246
pDelayOnNodes =
1247
  renameField "DelayOnNodes" .
1248
  defaultField [| [] |] $
1249
  simpleField "on_nodes" [t| [NonEmptyString] |]
1250

    
1251
-- | Repeat parameter for OpTestDelay.
1252
pDelayRepeat :: Field
1253
pDelayRepeat =
1254
  renameField "DelayRepeat" .
1255
  defaultField [| forceNonNeg (0::Int) |] $
1256
  simpleField "repeat" [t| NonNegative Int |]
1257

    
1258
-- | IAllocator test direction.
1259
pIAllocatorDirection :: Field
1260
pIAllocatorDirection =
1261
  renameField "IAllocatorDirection" $
1262
  simpleField "direction" [t| IAllocatorTestDir |]
1263

    
1264
-- | IAllocator test mode.
1265
pIAllocatorMode :: Field
1266
pIAllocatorMode =
1267
  renameField "IAllocatorMode" $
1268
  simpleField "mode" [t| IAllocatorMode |]
1269

    
1270
-- | IAllocator target name (new instance, node to evac, etc.).
1271
pIAllocatorReqName :: Field
1272
pIAllocatorReqName =
1273
  renameField "IAllocatorReqName" $ simpleField "name" [t| NonEmptyString |]
1274

    
1275
-- | Custom OpTestIAllocator nics.
1276
pIAllocatorNics :: Field
1277
pIAllocatorNics =
1278
  renameField "IAllocatorNics" $ simpleField "nics" [t| [UncheckedDict] |]
1279

    
1280
-- | Custom OpTestAllocator disks.
1281
pIAllocatorDisks :: Field
1282
pIAllocatorDisks =
1283
  renameField "IAllocatorDisks" $ simpleField "disks" [t| UncheckedList |]
1284

    
1285
-- | IAllocator memory field.
1286
pIAllocatorMemory :: Field
1287
pIAllocatorMemory =
1288
  renameField "IAllocatorMem" .
1289
  optionalField $
1290
  simpleField "memory" [t| NonNegative Int |]
1291

    
1292
-- | IAllocator vcpus field.
1293
pIAllocatorVCpus :: Field
1294
pIAllocatorVCpus =
1295
  renameField "IAllocatorVCpus" .
1296
  optionalField $
1297
  simpleField "vcpus" [t| NonNegative Int |]
1298

    
1299
-- | IAllocator os field.
1300
pIAllocatorOs :: Field
1301
pIAllocatorOs = renameField "IAllocatorOs" $ optionalNEStringField "os"
1302

    
1303
-- | IAllocator instances field.
1304
pIAllocatorInstances :: Field
1305
pIAllocatorInstances =
1306
  renameField "IAllocatorInstances " .
1307
  optionalField $
1308
  simpleField "instances" [t| [NonEmptyString] |]
1309

    
1310
-- | IAllocator evac mode.
1311
pIAllocatorEvacMode :: Field
1312
pIAllocatorEvacMode =
1313
  renameField "IAllocatorEvacMode" .
1314
  optionalField $
1315
  simpleField "evac_mode" [t| NodeEvacMode |]
1316

    
1317
-- | IAllocator spindle use.
1318
pIAllocatorSpindleUse :: Field
1319
pIAllocatorSpindleUse =
1320
  renameField "IAllocatorSpindleUse" .
1321
  defaultField [| forceNonNeg (1::Int) |] $
1322
  simpleField "spindle_use" [t| NonNegative Int |]
1323

    
1324
-- | IAllocator count field.
1325
pIAllocatorCount :: Field
1326
pIAllocatorCount =
1327
  renameField "IAllocatorCount" .
1328
  defaultField [| forceNonNeg (1::Int) |] $
1329
  simpleField "count" [t| NonNegative Int |]
1330

    
1331
-- | 'OpTestJqueue' notify_waitlock.
1332
pJQueueNotifyWaitLock :: Field
1333
pJQueueNotifyWaitLock = defaultFalse "notify_waitlock"
1334

    
1335
-- | 'OpTestJQueue' notify_exec.
1336
pJQueueNotifyExec :: Field
1337
pJQueueNotifyExec = defaultFalse "notify_exec"
1338

    
1339
-- | 'OpTestJQueue' log_messages.
1340
pJQueueLogMessages :: Field
1341
pJQueueLogMessages =
1342
  defaultField [| [] |] $ simpleField "log_messages" [t| [String] |]
1343

    
1344
-- | 'OpTestJQueue' fail attribute.
1345
pJQueueFail :: Field
1346
pJQueueFail =
1347
  renameField "JQueueFail" $ defaultFalse "fail"
1348

    
1349
-- | 'OpTestDummy' result field.
1350
pTestDummyResult :: Field
1351
pTestDummyResult =
1352
  renameField "TestDummyResult" $ simpleField "result" [t| UncheckedValue |]
1353

    
1354
-- | 'OpTestDummy' messages field.
1355
pTestDummyMessages :: Field
1356
pTestDummyMessages =
1357
  renameField "TestDummyMessages" $
1358
  simpleField "messages" [t| UncheckedValue |]
1359

    
1360
-- | 'OpTestDummy' fail field.
1361
pTestDummyFail :: Field
1362
pTestDummyFail =
1363
  renameField "TestDummyFail" $ simpleField "fail" [t| UncheckedValue |]
1364

    
1365
-- | 'OpTestDummy' submit_jobs field.
1366
pTestDummySubmitJobs :: Field
1367
pTestDummySubmitJobs =
1368
  renameField "TestDummySubmitJobs" $
1369
  simpleField "submit_jobs" [t| UncheckedValue |]
1370

    
1371
-- * Network parameters
1372

    
1373
-- | Network name.
1374
pNetworkName :: Field
1375
pNetworkName = simpleField "network_name" [t| NonEmptyString |]
1376

    
1377
-- | Network address (IPv4 subnet). FIXME: no real type for this.
1378
pNetworkAddress4 :: Field
1379
pNetworkAddress4 =
1380
  renameField "NetworkAddress4" $
1381
  simpleField "network" [t| NonEmptyString |]
1382

    
1383
-- | Network gateway (IPv4 address). FIXME: no real type for this.
1384
pNetworkGateway4 :: Field
1385
pNetworkGateway4 =
1386
  renameField "NetworkGateway4" $
1387
  optionalNEStringField "gateway"
1388

    
1389
-- | Network address (IPv6 subnet). FIXME: no real type for this.
1390
pNetworkAddress6 :: Field
1391
pNetworkAddress6 =
1392
  renameField "NetworkAddress6" $
1393
  optionalNEStringField "network6"
1394

    
1395
-- | Network gateway (IPv6 address). FIXME: no real type for this.
1396
pNetworkGateway6 :: Field
1397
pNetworkGateway6 =
1398
  renameField "NetworkGateway6" $
1399
  optionalNEStringField "gateway6"
1400

    
1401
-- | Network specific mac prefix (that overrides the cluster one).
1402
pNetworkMacPrefix :: Field
1403
pNetworkMacPrefix =
1404
  renameField "NetMacPrefix" $
1405
  optionalNEStringField "mac_prefix"
1406

    
1407
-- | Network add reserved IPs.
1408
pNetworkAddRsvdIps :: Field
1409
pNetworkAddRsvdIps =
1410
  renameField "NetworkAddRsvdIps" .
1411
  optionalField $
1412
  simpleField "add_reserved_ips" [t| [NonEmptyString] |]
1413

    
1414
-- | Network remove reserved IPs.
1415
pNetworkRemoveRsvdIps :: Field
1416
pNetworkRemoveRsvdIps =
1417
  renameField "NetworkRemoveRsvdIps" .
1418
  optionalField $
1419
  simpleField "remove_reserved_ips" [t| [NonEmptyString] |]
1420

    
1421
-- | Network mode when connecting to a group.
1422
pNetworkMode :: Field
1423
pNetworkMode = simpleField "network_mode" [t| NICMode |]
1424

    
1425
-- | Network link when connecting to a group.
1426
pNetworkLink :: Field
1427
pNetworkLink = simpleField "network_link" [t| NonEmptyString |]
1428

    
1429
-- * Common opcode parameters
1430

    
1431
-- | Run checks only, don't execute.
1432
pDryRun :: Field
1433
pDryRun = optionalField $ booleanField "dry_run"
1434

    
1435
-- | Debug level.
1436
pDebugLevel :: Field
1437
pDebugLevel = optionalField $ simpleField "debug_level" [t| NonNegative Int |]
1438

    
1439
-- | Opcode priority. Note: python uses a separate constant, we're
1440
-- using the actual value we know it's the default.
1441
pOpPriority :: Field
1442
pOpPriority =
1443
  defaultField [| OpPrioNormal |] $
1444
  simpleField "priority" [t| OpSubmitPriority |]
1445

    
1446
-- | Job dependencies.
1447
pDependencies :: Field
1448
pDependencies =
1449
  optionalNullSerField $ simpleField "depends" [t| [JobDependency] |]
1450

    
1451
-- | Comment field.
1452
pComment :: Field
1453
pComment = optionalNullSerField $ stringField "comment"
1454

    
1455
-- | The description of the state change reason.
1456
pReason :: Field
1457
pReason = simpleField "reason" [t| (InstReasonSrc, NonEmptyString) |]
1458

    
1459
-- * Entire opcode parameter list
1460

    
1461
-- | Old-style query opcode, with locking.
1462
dOldQuery :: [Field]
1463
dOldQuery =
1464
  [ pOutputFields
1465
  , pNames
1466
  , pUseLocking
1467
  ]
1468

    
1469
-- | Old-style query opcode, without locking.
1470
dOldQueryNoLocking :: [Field]
1471
dOldQueryNoLocking =
1472
  [ pOutputFields
1473
  , pNames
1474
  ]