Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpParams.hs @ ad1c1e41

History | View | Annotate | Download (42.2 kB)

1
{-# LANGUAGE TemplateHaskell #-}
2

    
3
{-| Implementation of opcodes parameters.
4

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

    
11
-}
12

    
13
{-
14

    
15
Copyright (C) 2012 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
  , pFileDriver
101
  , pFileStorageDir
102
  , pVgName
103
  , pEnabledHypervisors
104
  , pHypervisor
105
  , pClusterHvParams
106
  , pInstHvParams
107
  , pClusterBeParams
108
  , pInstBeParams
109
  , pResetDefaults
110
  , pOsHvp
111
  , pClusterOsParams
112
  , pInstOsParams
113
  , pCandidatePoolSize
114
  , pUidPool
115
  , pAddUids
116
  , pRemoveUids
117
  , pMaintainNodeHealth
118
  , pPreallocWipeDisks
119
  , pNicParams
120
  , pInstNics
121
  , pNdParams
122
  , pIpolicy
123
  , pDrbdHelper
124
  , pDefaultIAllocator
125
  , pMasterNetdev
126
  , pMasterNetmask
127
  , pReservedLvs
128
  , pHiddenOs
129
  , pBlacklistedOs
130
  , pUseExternalMipScript
131
  , pQueryFields
132
  , pQueryFilter
133
  , pOobCommand
134
  , pOobTimeout
135
  , pIgnoreStatus
136
  , pPowerDelay
137
  , pPrimaryIp
138
  , pSecondaryIp
139
  , pReadd
140
  , pNodeGroup
141
  , pMasterCapable
142
  , pVmCapable
143
  , pNames
144
  , pNodes
145
  , pRequiredNodes
146
  , pStorageType
147
  , pStorageChanges
148
  , pMasterCandidate
149
  , pOffline
150
  , pDrained
151
  , pAutoPromote
152
  , pPowered
153
  , pIallocator
154
  , pRemoteNode
155
  , pEvacMode
156
  , pInstCreateMode
157
  , pNoInstall
158
  , pInstOs
159
  , pPrimaryNode
160
  , pSecondaryNode
161
  , pSourceHandshake
162
  , pSourceInstance
163
  , pSourceShutdownTimeout
164
  , pSourceX509Ca
165
  , pSrcNode
166
  , pSrcPath
167
  , pStartInstance
168
  , pInstTags
169
  , pMultiAllocInstances
170
  , pTempOsParams
171
  , pTempHvParams
172
  , pTempBeParams
173
  , pIgnoreFailures
174
  , pNewName
175
  , pIgnoreSecondaries
176
  , pRebootType
177
  , pIgnoreDiskSize
178
  , pRecreateDisksInfo
179
  , pStatic
180
  , pInstParamsNicChanges
181
  , pInstParamsDiskChanges
182
  , pRuntimeMem
183
  , pOsNameChange
184
  , pDiskIndex
185
  , pDiskChgAmount
186
  , pDiskChgAbsolute
187
  , pTargetGroups
188
  , pExportMode
189
  , pExportTargetNode
190
  , pRemoveInstance
191
  , pIgnoreRemoveFailures
192
  , pX509KeyName
193
  , pX509DestCA
194
  , pTagSearchPattern
195
  , pRestrictedCommand
196
  , pReplaceDisksMode
197
  , pReplaceDisksList
198
  , pAllowFailover
199
  , pDelayDuration
200
  , pDelayOnMaster
201
  , pDelayOnNodes
202
  , pDelayRepeat
203
  , pIAllocatorDirection
204
  , pIAllocatorMode
205
  , pIAllocatorReqName
206
  , pIAllocatorNics
207
  , pIAllocatorDisks
208
  , pIAllocatorMemory
209
  , pIAllocatorVCpus
210
  , pIAllocatorOs
211
  , pIAllocatorInstances
212
  , pIAllocatorEvacMode
213
  , pIAllocatorSpindleUse
214
  , pIAllocatorCount
215
  , pJQueueNotifyWaitLock
216
  , pJQueueNotifyExec
217
  , pJQueueLogMessages
218
  , pJQueueFail
219
  , pTestDummyResult
220
  , pTestDummyMessages
221
  , pTestDummyFail
222
  , pTestDummySubmitJobs
223
  , pNetworkName
224
  , pNetworkType
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
  , dOldQuery
240
  , dOldQueryNoLocking
241
  ) where
242

    
243
import Control.Monad (liftM)
244
import qualified Data.Set as Set
245
import Text.JSON (readJSON, showJSON, JSON, JSValue(..), fromJSString,
246
                  JSObject, toJSObject)
247
import qualified Text.JSON
248
import Text.JSON.Pretty (pp_value)
249

    
250
import Ganeti.BasicTypes
251
import qualified Ganeti.Constants as C
252
import Ganeti.THH
253
import Ganeti.JSON
254
import Ganeti.Types
255
import qualified Ganeti.Query.Language as Qlang
256

    
257
-- * Helper functions and types
258

    
259
-- * Type aliases
260

    
261
-- | Build a boolean field.
262
booleanField :: String -> Field
263
booleanField = flip simpleField [t| Bool |]
264

    
265
-- | Default a field to 'False'.
266
defaultFalse :: String -> Field
267
defaultFalse = defaultField [| False |] . booleanField
268

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

    
273
-- | An alias for a 'String' field.
274
stringField :: String -> Field
275
stringField = flip simpleField [t| String |]
276

    
277
-- | An alias for an optional string field.
278
optionalStringField :: String -> Field
279
optionalStringField = optionalField . stringField
280

    
281
-- | An alias for an optional non-empty string field.
282
optionalNEStringField :: String -> Field
283
optionalNEStringField = optionalField . flip simpleField [t| NonEmptyString |]
284

    
285
-- | Unchecked value, should be replaced by a better definition.
286
type UncheckedValue = JSValue
287

    
288
-- | Unchecked dict, should be replaced by a better definition.
289
type UncheckedDict = JSObject JSValue
290

    
291
-- | Unchecked list, shoild be replaced by a better definition.
292
type UncheckedList = [JSValue]
293

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

    
303
-- ** Tags
304

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

    
314
-- | Data type holding a tag object (type and object name).
315
data TagObject = TagInstance String
316
               | TagNode     String
317
               | TagGroup    String
318
               | TagCluster
319
               deriving (Show, Eq)
320

    
321
-- | Tag type for a given tag object.
322
tagTypeOf :: TagObject -> TagType
323
tagTypeOf (TagInstance {}) = TagTypeInstance
324
tagTypeOf (TagNode     {}) = TagTypeNode
325
tagTypeOf (TagGroup    {}) = TagTypeGroup
326
tagTypeOf (TagCluster  {}) = TagTypeCluster
327

    
328
-- | Gets the potential tag object name.
329
tagNameOf :: TagObject -> Maybe String
330
tagNameOf (TagInstance s) = Just s
331
tagNameOf (TagNode     s) = Just s
332
tagNameOf (TagGroup    s) = Just s
333
tagNameOf  TagCluster     = Nothing
334

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

    
346
-- | Name of the tag \"name\" field.
347
tagNameField :: String
348
tagNameField = "name"
349

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

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

    
362
-- ** Disks
363

    
364
-- | Replace disks type.
365
$(declareSADT "ReplaceDisksMode"
366
  [ ("ReplaceOnPrimary",    'C.replaceDiskPri)
367
  , ("ReplaceOnSecondary",  'C.replaceDiskSec)
368
  , ("ReplaceNewSecondary", 'C.replaceDiskChg)
369
  , ("ReplaceAuto",         'C.replaceDiskAuto)
370
  ])
371
$(makeJSONInstance ''ReplaceDisksMode)
372

    
373
-- | Disk index type (embedding constraints on the index value via a
374
-- smart constructor).
375
newtype DiskIndex = DiskIndex { unDiskIndex :: Int }
376
  deriving (Show, Eq, Ord)
377

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

    
385
instance JSON DiskIndex where
386
  readJSON v = readJSON v >>= mkDiskIndex
387
  showJSON = showJSON . unDiskIndex
388

    
389
-- ** I* param types
390

    
391
-- | Type holding disk access modes.
392
$(declareSADT "DiskAccess"
393
  [ ("DiskReadOnly",  'C.diskRdonly)
394
  , ("DiskReadWrite", 'C.diskRdwr)
395
  ])
396
$(makeJSONInstance ''DiskAccess)
397

    
398
-- | NIC modification definition.
399
$(buildObject "INicParams" "inic"
400
  [ optionalField $ simpleField C.inicMac  [t| NonEmptyString |]
401
  , optionalField $ simpleField C.inicIp   [t| String         |]
402
  , optionalField $ simpleField C.inicMode [t| NonEmptyString |]
403
  , optionalField $ simpleField C.inicLink [t| NonEmptyString |]
404
  ])
405

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

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

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

    
437
instance JSON RecreateDisksInfo where
438
  readJSON = readRecreateDisks
439
  showJSON  RecreateDisksAll            = showJSON ()
440
  showJSON (RecreateDisksIndices idx)   = showJSON idx
441
  showJSON (RecreateDisksParams params) = showJSON params
442

    
443
-- | Simple type for old-style ddm changes.
444
data DdmOldChanges = DdmOldIndex (NonNegative Int)
445
                   | DdmOldMod DdmSimple
446
                     deriving (Eq, Show)
447

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

    
457
instance JSON DdmOldChanges where
458
  showJSON (DdmOldIndex i) = showJSON i
459
  showJSON (DdmOldMod m)   = showJSON m
460
  readJSON = readDdmOldChanges
461

    
462
-- | Instance disk or nic modifications.
463
data SetParamsMods a
464
  = SetParamsEmpty
465
  | SetParamsDeprecated (NonEmpty (DdmOldChanges, a))
466
  | SetParamsNew (NonEmpty (DdmFull, Int, a))
467
    deriving (Eq, Show)
468

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

    
477
instance (JSON a) => JSON (SetParamsMods a) where
478
  showJSON SetParamsEmpty = showJSON ()
479
  showJSON (SetParamsDeprecated v) = showJSON v
480
  showJSON (SetParamsNew v) = showJSON v
481
  readJSON = readSetParams
482

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

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

    
499
instance JSON ExportTarget where
500
  showJSON (ExportTargetLocal s)  = showJSON s
501
  showJSON (ExportTargetRemote l) = showJSON l
502
  readJSON = readExportTarget
503

    
504
-- * Parameters
505

    
506
-- | A required instance name (for single-instance LUs).
507
pInstanceName :: Field
508
pInstanceName = simpleField "instance_name" [t| String |]
509

    
510
-- | A list of instances.
511
pInstances :: Field
512
pInstances = defaultField [| [] |] $
513
             simpleField "instances" [t| [NonEmptyString] |]
514

    
515
-- | A generic name.
516
pName :: Field
517
pName = simpleField "name" [t| NonEmptyString |]
518

    
519
-- | Tags list.
520
pTagsList :: Field
521
pTagsList = simpleField "tags" [t| [String] |]
522

    
523
-- | Tags object.
524
pTagsObject :: Field
525
pTagsObject =
526
  customField 'decodeTagObject 'encodeTagObject [tagNameField] $
527
  simpleField "kind" [t| TagObject |]
528

    
529
-- | Selected output fields.
530
pOutputFields :: Field
531
pOutputFields = simpleField "output_fields" [t| [NonEmptyString] |]
532

    
533
-- | How long to wait for instance to shut down.
534
pShutdownTimeout :: Field
535
pShutdownTimeout = defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
536
                   simpleField "shutdown_timeout" [t| NonNegative Int |]
537

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

    
546
-- | Whether to shutdown the instance in backup-export.
547
pShutdownInstance :: Field
548
pShutdownInstance = defaultTrue "shutdown"
549

    
550
-- | Whether to force the operation.
551
pForce :: Field
552
pForce = defaultFalse "force"
553

    
554
-- | Whether to ignore offline nodes.
555
pIgnoreOfflineNodes :: Field
556
pIgnoreOfflineNodes = defaultFalse "ignore_offline_nodes"
557

    
558
-- | A required node name (for single-node LUs).
559
pNodeName :: Field
560
pNodeName = simpleField "node_name" [t| NonEmptyString |]
561

    
562
-- | List of nodes.
563
pNodeNames :: Field
564
pNodeNames =
565
  defaultField [| [] |] $ simpleField "node_names" [t| [NonEmptyString] |]
566

    
567
-- | A required node group name (for single-group LUs).
568
pGroupName :: Field
569
pGroupName = simpleField "group_name" [t| NonEmptyString |]
570

    
571
-- | Migration type (live\/non-live).
572
pMigrationMode :: Field
573
pMigrationMode =
574
  renameField "MigrationMode" .
575
  optionalField $
576
  simpleField "mode" [t| MigrationMode |]
577

    
578
-- | Obsolete \'live\' migration mode (boolean).
579
pMigrationLive :: Field
580
pMigrationLive =
581
  renameField "OldLiveMode" . optionalField $ booleanField "live"
582

    
583
-- | Migration cleanup parameter.
584
pMigrationCleanup :: Field
585
pMigrationCleanup = renameField "MigrationCleanup" $ defaultFalse "cleanup"
586

    
587
-- | Whether to force an unknown OS variant.
588
pForceVariant :: Field
589
pForceVariant = defaultFalse "force_variant"
590

    
591
-- | Whether to wait for the disk to synchronize.
592
pWaitForSync :: Field
593
pWaitForSync = defaultTrue "wait_for_sync"
594

    
595
-- | Whether to wait for the disk to synchronize (defaults to false).
596
pWaitForSyncFalse :: Field
597
pWaitForSyncFalse = defaultField [| False |] pWaitForSync
598

    
599
-- | Whether to ignore disk consistency
600
pIgnoreConsistency :: Field
601
pIgnoreConsistency = defaultFalse "ignore_consistency"
602

    
603
-- | Storage name.
604
pStorageName :: Field
605
pStorageName =
606
  renameField "StorageName" $ simpleField "name" [t| NonEmptyString |]
607

    
608
-- | Whether to use synchronization.
609
pUseLocking :: Field
610
pUseLocking = defaultFalse "use_locking"
611

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

    
618
-- | Whether to check name.
619
pNameCheck :: Field
620
pNameCheck = defaultTrue "name_check"
621

    
622
-- | Instance allocation policy.
623
pNodeGroupAllocPolicy :: Field
624
pNodeGroupAllocPolicy = optionalField $
625
                        simpleField "alloc_policy" [t| AllocPolicy |]
626

    
627
-- | Default node parameters for group.
628
pGroupNodeParams :: Field
629
pGroupNodeParams = optionalField $ simpleField "ndparams" [t| UncheckedDict |]
630

    
631
-- | Resource(s) to query for.
632
pQueryWhat :: Field
633
pQueryWhat = simpleField "what" [t| Qlang.QueryTypeOp |]
634

    
635
-- | Whether to release locks as soon as possible.
636
pEarlyRelease :: Field
637
pEarlyRelease = defaultFalse "early_release"
638

    
639
-- | Whether to ensure instance's IP address is inactive.
640
pIpCheck :: Field
641
pIpCheck = defaultTrue "ip_check"
642

    
643
-- | Check for conflicting IPs.
644
pIpConflictsCheck :: Field
645
pIpConflictsCheck = defaultTrue "conflicts_check"
646

    
647
-- | Do not remember instance state changes.
648
pNoRemember :: Field
649
pNoRemember = defaultFalse "no_remember"
650

    
651
-- | Target node for instance migration/failover.
652
pMigrationTargetNode :: Field
653
pMigrationTargetNode = optionalNEStringField "target_node"
654

    
655
-- | Target node for instance move (required).
656
pMoveTargetNode :: Field
657
pMoveTargetNode =
658
  renameField "MoveTargetNode" $
659
  simpleField "target_node" [t| NonEmptyString |]
660

    
661
-- | Pause instance at startup.
662
pStartupPaused :: Field
663
pStartupPaused = defaultFalse "startup_paused"
664

    
665
-- | Verbose mode.
666
pVerbose :: Field
667
pVerbose = defaultFalse "verbose"
668

    
669
-- ** Parameters for cluster verification
670

    
671
-- | Whether to simulate errors (useful for debugging).
672
pDebugSimulateErrors :: Field
673
pDebugSimulateErrors = defaultFalse "debug_simulate_errors"
674

    
675
-- | Error codes.
676
pErrorCodes :: Field
677
pErrorCodes = defaultFalse "error_codes"
678

    
679
-- | Which checks to skip.
680
pSkipChecks :: Field
681
pSkipChecks = defaultField [| Set.empty |] $
682
              simpleField "skip_checks" [t| Set.Set VerifyOptionalChecks |]
683

    
684
-- | List of error codes that should be treated as warnings.
685
pIgnoreErrors :: Field
686
pIgnoreErrors = defaultField [| Set.empty |] $
687
                simpleField "ignore_errors" [t| Set.Set CVErrorCode |]
688

    
689
-- | Optional group name.
690
pOptGroupName :: Field
691
pOptGroupName = renameField "OptGroupName" .
692
                optionalField $ simpleField "group_name" [t| NonEmptyString |]
693

    
694
-- | Disk templates' parameter defaults.
695
pDiskParams :: Field
696
pDiskParams = optionalField $
697
              simpleField "diskparams" [t| GenericContainer DiskTemplate
698
                                           UncheckedDict |]
699

    
700
-- * Parameters for node resource model
701

    
702
-- | Set hypervisor states.
703
pHvState :: Field
704
pHvState = optionalField $ simpleField "hv_state" [t| UncheckedDict |]
705

    
706
-- | Set disk states.
707
pDiskState :: Field
708
pDiskState = optionalField $ simpleField "disk_state" [t| UncheckedDict |]
709

    
710
-- | Whether to ignore ipolicy violations.
711
pIgnoreIpolicy :: Field
712
pIgnoreIpolicy = defaultFalse "ignore_ipolicy"
713

    
714
-- | Allow runtime changes while migrating.
715
pAllowRuntimeChgs :: Field
716
pAllowRuntimeChgs = defaultTrue "allow_runtime_changes"
717

    
718
-- | Utility type for OpClusterSetParams.
719
type TestClusterOsListItem = (DdmSimple, NonEmptyString)
720

    
721
-- | Utility type of OsList.
722
type TestClusterOsList = [TestClusterOsListItem]
723

    
724
-- Utility type for NIC definitions.
725
--type TestNicDef = INicParams
726

    
727
-- | List of instance disks.
728
pInstDisks :: Field
729
pInstDisks = renameField "instDisks" $ simpleField "disks" [t| [IDiskParams] |]
730

    
731
-- | Instance disk template.
732
pDiskTemplate :: Field
733
pDiskTemplate = simpleField "disk_template" [t| DiskTemplate |]
734

    
735
-- | File driver.
736
pFileDriver :: Field
737
pFileDriver = optionalField $ simpleField "file_driver" [t| FileDriver |]
738

    
739
-- | Directory for storing file-backed disks.
740
pFileStorageDir :: Field
741
pFileStorageDir = optionalNEStringField "file_storage_dir"
742

    
743
-- | Volume group name.
744
pVgName :: Field
745
pVgName = optionalStringField "vg_name"
746

    
747
-- | List of enabled hypervisors.
748
pEnabledHypervisors :: Field
749
pEnabledHypervisors =
750
  optionalField $
751
  simpleField "enabled_hypervisors" [t| NonEmpty Hypervisor |]
752

    
753
-- | Selected hypervisor for an instance.
754
pHypervisor :: Field
755
pHypervisor =
756
  optionalField $
757
  simpleField "hypervisor" [t| Hypervisor |]
758

    
759
-- | Cluster-wide hypervisor parameters, hypervisor-dependent.
760
pClusterHvParams :: Field
761
pClusterHvParams =
762
  renameField "ClusterHvParams" .
763
  optionalField $
764
  simpleField "hvparams" [t| Container UncheckedDict |]
765

    
766
-- | Instance hypervisor parameters.
767
pInstHvParams :: Field
768
pInstHvParams =
769
  renameField "InstHvParams" .
770
  defaultField [| toJSObject [] |] $
771
  simpleField "hvparams" [t| UncheckedDict |]
772

    
773
-- | Cluster-wide beparams.
774
pClusterBeParams :: Field
775
pClusterBeParams =
776
  renameField "ClusterBeParams" .
777
  optionalField $ simpleField "beparams" [t| UncheckedDict |]
778

    
779
-- | Instance beparams.
780
pInstBeParams :: Field
781
pInstBeParams =
782
  renameField "InstBeParams" .
783
  defaultField [| toJSObject [] |] $
784
  simpleField "beparams" [t| UncheckedDict |]
785

    
786
-- | Reset instance parameters to default if equal.
787
pResetDefaults :: Field
788
pResetDefaults = defaultFalse "identify_defaults"
789

    
790
-- | Cluster-wide per-OS hypervisor parameter defaults.
791
pOsHvp :: Field
792
pOsHvp = optionalField $ simpleField "os_hvp" [t| Container UncheckedDict |]
793

    
794
-- | Cluster-wide OS parameter defaults.
795
pClusterOsParams :: Field
796
pClusterOsParams =
797
  renameField "ClusterOsParams" .
798
  optionalField $ simpleField "osparams" [t| Container UncheckedDict |]
799

    
800
-- | Instance OS parameters.
801
pInstOsParams :: Field
802
pInstOsParams =
803
  renameField "InstOsParams" . defaultField [| toJSObject [] |] $
804
  simpleField "osparams" [t| UncheckedDict |]
805

    
806
-- | Temporary OS parameters (currently only in reinstall, might be
807
-- added to install as well).
808
pTempOsParams :: Field
809
pTempOsParams =
810
  renameField "TempOsParams" .
811
  optionalField $ simpleField "osparams" [t| UncheckedDict |]
812

    
813
-- | Temporary hypervisor parameters, hypervisor-dependent.
814
pTempHvParams :: Field
815
pTempHvParams =
816
  renameField "TempHvParams" .
817
  defaultField [| toJSObject [] |] $
818
  simpleField "hvparams" [t| UncheckedDict |]
819

    
820
-- | Temporary backend parameters.
821
pTempBeParams :: Field
822
pTempBeParams =
823
  renameField "TempBeParams" .
824
  defaultField [| toJSObject [] |] $
825
  simpleField "beparams" [t| UncheckedDict |]
826

    
827
-- | Candidate pool size.
828
pCandidatePoolSize :: Field
829
pCandidatePoolSize =
830
  optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]
831

    
832
-- | Set UID pool, must be list of lists describing UID ranges (two
833
-- items, start and end inclusive.
834
pUidPool :: Field
835
pUidPool = optionalField $ simpleField "uid_pool" [t| [[(Int, Int)]] |]
836

    
837
-- | Extend UID pool, must be list of lists describing UID ranges (two
838
-- items, start and end inclusive.
839
pAddUids :: Field
840
pAddUids = optionalField $ simpleField "add_uids" [t| [[(Int, Int)]] |]
841

    
842
-- | Shrink UID pool, must be list of lists describing UID ranges (two
843
-- items, start and end inclusive) to be removed.
844
pRemoveUids :: Field
845
pRemoveUids = optionalField $ simpleField "remove_uids" [t| [[(Int, Int)]] |]
846

    
847
-- | Whether to automatically maintain node health.
848
pMaintainNodeHealth :: Field
849
pMaintainNodeHealth = optionalField $ booleanField "maintain_node_health"
850

    
851
-- | Whether to wipe disks before allocating them to instances.
852
pPreallocWipeDisks :: Field
853
pPreallocWipeDisks = optionalField $ booleanField "prealloc_wipe_disks"
854

    
855
-- | Cluster-wide NIC parameter defaults.
856
pNicParams :: Field
857
pNicParams = optionalField $ simpleField "nicparams" [t| INicParams |]
858

    
859
-- | Instance NIC definitions.
860
pInstNics :: Field
861
pInstNics = simpleField "nics" [t| [INicParams] |]
862

    
863
-- | Cluster-wide node parameter defaults.
864
pNdParams :: Field
865
pNdParams = optionalField $ simpleField "ndparams" [t| UncheckedDict |]
866

    
867
-- | Cluster-wide ipolicy specs.
868
pIpolicy :: Field
869
pIpolicy = optionalField $ simpleField "ipolicy" [t| UncheckedDict |]
870

    
871
-- | DRBD helper program.
872
pDrbdHelper :: Field
873
pDrbdHelper = optionalStringField "drbd_helper"
874

    
875
-- | Default iallocator for cluster.
876
pDefaultIAllocator :: Field
877
pDefaultIAllocator = optionalStringField "default_iallocator"
878

    
879
-- | Master network device.
880
pMasterNetdev :: Field
881
pMasterNetdev = optionalStringField "master_netdev"
882

    
883
-- | Netmask of the master IP.
884
pMasterNetmask :: Field
885
pMasterNetmask =
886
  optionalField $ simpleField "master_netmask" [t| NonNegative Int |]
887

    
888
-- | List of reserved LVs.
889
pReservedLvs :: Field
890
pReservedLvs =
891
  optionalField $ simpleField "reserved_lvs" [t| [NonEmptyString] |]
892

    
893
-- | Modify list of hidden operating systems: each modification must
894
-- have two items, the operation and the OS name; the operation can be
895
-- add or remove.
896
pHiddenOs :: Field
897
pHiddenOs = optionalField $ simpleField "hidden_os" [t| TestClusterOsList |]
898

    
899
-- | Modify list of blacklisted operating systems: each modification
900
-- must have two items, the operation and the OS name; the operation
901
-- can be add or remove.
902
pBlacklistedOs :: Field
903
pBlacklistedOs =
904
  optionalField $ simpleField "blacklisted_os" [t| TestClusterOsList |]
905

    
906
-- | Whether to use an external master IP address setup script.
907
pUseExternalMipScript :: Field
908
pUseExternalMipScript = optionalField $ booleanField "use_external_mip_script"
909

    
910
-- | Requested fields.
911
pQueryFields :: Field
912
pQueryFields = simpleField "fields" [t| [NonEmptyString] |]
913

    
914
-- | Query filter.
915
pQueryFilter :: Field
916
pQueryFilter = simpleField "qfilter" [t| Qlang.Filter String |]
917

    
918
-- | OOB command to run.
919
pOobCommand :: Field
920
pOobCommand = simpleField "command" [t| OobCommand |]
921

    
922
-- | Timeout before the OOB helper will be terminated.
923
pOobTimeout :: Field
924
pOobTimeout =
925
  defaultField [| C.oobTimeout |] $ simpleField "timeout" [t| Int |]
926

    
927
-- | Ignores the node offline status for power off.
928
pIgnoreStatus :: Field
929
pIgnoreStatus = defaultFalse "ignore_status"
930

    
931
-- | Time in seconds to wait between powering on nodes.
932
pPowerDelay :: Field
933
pPowerDelay =
934
  -- FIXME: we can't use the proper type "NonNegative Double", since
935
  -- the default constant is a plain Double, not a non-negative one.
936
  defaultField [| C.oobPowerDelay |] $
937
  simpleField "power_delay" [t| Double |]
938

    
939
-- | Primary IP address.
940
pPrimaryIp :: Field
941
pPrimaryIp = optionalStringField "primary_ip"
942

    
943
-- | Secondary IP address.
944
pSecondaryIp :: Field
945
pSecondaryIp = optionalNEStringField "secondary_ip"
946

    
947
-- | Whether node is re-added to cluster.
948
pReadd :: Field
949
pReadd = defaultFalse "readd"
950

    
951
-- | Initial node group.
952
pNodeGroup :: Field
953
pNodeGroup = optionalNEStringField "group"
954

    
955
-- | Whether node can become master or master candidate.
956
pMasterCapable :: Field
957
pMasterCapable = optionalField $ booleanField "master_capable"
958

    
959
-- | Whether node can host instances.
960
pVmCapable :: Field
961
pVmCapable = optionalField $ booleanField "vm_capable"
962

    
963
-- | List of names.
964
pNames :: Field
965
pNames = defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
966

    
967
-- | List of node names.
968
pNodes :: Field
969
pNodes = defaultField [| [] |] $ simpleField "nodes" [t| [NonEmptyString] |]
970

    
971
-- | Required list of node names.
972
pRequiredNodes :: Field
973
pRequiredNodes =
974
  renameField "ReqNodes " $ simpleField "nodes" [t| [NonEmptyString] |]
975

    
976
-- | Storage type.
977
pStorageType :: Field
978
pStorageType = simpleField "storage_type" [t| StorageType |]
979

    
980
-- | Storage changes (unchecked).
981
pStorageChanges :: Field
982
pStorageChanges = simpleField "changes" [t| UncheckedDict |]
983

    
984
-- | Whether the node should become a master candidate.
985
pMasterCandidate :: Field
986
pMasterCandidate = optionalField $ booleanField "master_candidate"
987

    
988
-- | Whether the node should be marked as offline.
989
pOffline :: Field
990
pOffline = optionalField $ booleanField "offline"
991

    
992
-- | Whether the node should be marked as drained.
993
pDrained ::Field
994
pDrained = optionalField $ booleanField "drained"
995

    
996
-- | Whether node(s) should be promoted to master candidate if necessary.
997
pAutoPromote :: Field
998
pAutoPromote = defaultFalse "auto_promote"
999

    
1000
-- | Whether the node should be marked as powered
1001
pPowered :: Field
1002
pPowered = optionalField $ booleanField "powered"
1003

    
1004
-- | Iallocator for deciding the target node for shared-storage
1005
-- instances during migrate and failover.
1006
pIallocator :: Field
1007
pIallocator = optionalNEStringField "iallocator"
1008

    
1009
-- | New secondary node.
1010
pRemoteNode :: Field
1011
pRemoteNode = optionalNEStringField "remote_node"
1012

    
1013
-- | Node evacuation mode.
1014
pEvacMode :: Field
1015
pEvacMode = renameField "EvacMode" $ simpleField "mode" [t| NodeEvacMode |]
1016

    
1017
-- | Instance creation mode.
1018
pInstCreateMode :: Field
1019
pInstCreateMode =
1020
  renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]
1021

    
1022
-- | Do not install the OS (will disable automatic start).
1023
pNoInstall :: Field
1024
pNoInstall = optionalField $ booleanField "no_install"
1025

    
1026
-- | OS type for instance installation.
1027
pInstOs :: Field
1028
pInstOs = optionalNEStringField "os_type"
1029

    
1030
-- | Primary node for an instance.
1031
pPrimaryNode :: Field
1032
pPrimaryNode = optionalNEStringField "pnode"
1033

    
1034
-- | Secondary node for an instance.
1035
pSecondaryNode :: Field
1036
pSecondaryNode = optionalNEStringField "snode"
1037

    
1038
-- | Signed handshake from source (remote import only).
1039
pSourceHandshake :: Field
1040
pSourceHandshake =
1041
  optionalField $ simpleField "source_handshake" [t| UncheckedList |]
1042

    
1043
-- | Source instance name (remote import only).
1044
pSourceInstance :: Field
1045
pSourceInstance = optionalNEStringField "source_instance_name"
1046

    
1047
-- | How long source instance was given to shut down (remote import only).
1048
-- FIXME: non-negative int, whereas the constant is a plain int.
1049
pSourceShutdownTimeout :: Field
1050
pSourceShutdownTimeout =
1051
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
1052
  simpleField "source_shutdown_timeout" [t| NonNegative Int |]
1053

    
1054
-- | Source X509 CA in PEM format (remote import only).
1055
pSourceX509Ca :: Field
1056
pSourceX509Ca = optionalNEStringField "source_x509_ca"
1057

    
1058
-- | Source node for import.
1059
pSrcNode :: Field
1060
pSrcNode = optionalNEStringField "src_node"
1061

    
1062
-- | Source directory for import.
1063
pSrcPath :: Field
1064
pSrcPath = optionalNEStringField "src_path"
1065

    
1066
-- | Whether to start instance after creation.
1067
pStartInstance :: Field
1068
pStartInstance = defaultTrue "start"
1069

    
1070
-- | Instance tags. FIXME: unify/simplify with pTags, once that
1071
-- migrates to NonEmpty String.
1072
pInstTags :: Field
1073
pInstTags =
1074
  renameField "InstTags" .
1075
  defaultField [| [] |] $
1076
  simpleField "tags" [t| [NonEmptyString] |]
1077

    
1078
-- | Unchecked list of OpInstanceCreate, used in OpInstanceMultiAlloc.
1079
pMultiAllocInstances :: Field
1080
pMultiAllocInstances =
1081
  renameField "InstMultiAlloc" .
1082
  defaultField [| [] |] $
1083
  simpleField "instances"[t| UncheckedList |]
1084

    
1085
-- | Ignore failures parameter.
1086
pIgnoreFailures :: Field
1087
pIgnoreFailures = defaultFalse "ignore_failures"
1088

    
1089
-- | New instance or cluster name.
1090
pNewName :: Field
1091
pNewName = simpleField "new_name" [t| NonEmptyString |]
1092

    
1093
-- | Whether to start the instance even if secondary disks are failing.
1094
pIgnoreSecondaries :: Field
1095
pIgnoreSecondaries = defaultFalse "ignore_secondaries"
1096

    
1097
-- | How to reboot the instance.
1098
pRebootType :: Field
1099
pRebootType = simpleField "reboot_type" [t| RebootType |]
1100

    
1101
-- | Whether to ignore recorded disk size.
1102
pIgnoreDiskSize :: Field
1103
pIgnoreDiskSize = defaultFalse "ignore_size"
1104

    
1105
-- | Disk list for recreate disks.
1106
pRecreateDisksInfo :: Field
1107
pRecreateDisksInfo =
1108
  renameField "RecreateDisksInfo" .
1109
  defaultField [| RecreateDisksAll |] $
1110
  simpleField "disks" [t| RecreateDisksInfo |]
1111

    
1112
-- | Whether to only return configuration data without querying nodes.
1113
pStatic :: Field
1114
pStatic = defaultFalse "static"
1115

    
1116
-- | InstanceSetParams NIC changes.
1117
pInstParamsNicChanges :: Field
1118
pInstParamsNicChanges =
1119
  renameField "InstNicChanges" .
1120
  defaultField [| SetParamsEmpty |] $
1121
  simpleField "nics" [t| SetParamsMods INicParams |]
1122

    
1123
-- | InstanceSetParams Disk changes.
1124
pInstParamsDiskChanges :: Field
1125
pInstParamsDiskChanges =
1126
  renameField "InstDiskChanges" .
1127
  defaultField [| SetParamsEmpty |] $
1128
  simpleField "disks" [t| SetParamsMods IDiskParams |]
1129

    
1130
-- | New runtime memory.
1131
pRuntimeMem :: Field
1132
pRuntimeMem = optionalField $ simpleField "runtime_mem" [t| Positive Int |]
1133

    
1134
-- | Change the instance's OS without reinstalling the instance
1135
pOsNameChange :: Field
1136
pOsNameChange = optionalNEStringField "os_name"
1137

    
1138
-- | Disk index for e.g. grow disk.
1139
pDiskIndex :: Field
1140
pDiskIndex = renameField "DiskIndex " $ simpleField "disk" [t| DiskIndex |]
1141

    
1142
-- | Disk amount to add or grow to.
1143
pDiskChgAmount :: Field
1144
pDiskChgAmount =
1145
  renameField "DiskChgAmount" $ simpleField "amount" [t| NonNegative Int |]
1146

    
1147
-- | Whether the amount parameter is an absolute target or a relative one.
1148
pDiskChgAbsolute :: Field
1149
pDiskChgAbsolute = renameField "DiskChkAbsolute" $ defaultFalse "absolute"
1150

    
1151
-- | Destination group names or UUIDs (defaults to \"all but current group\".
1152
pTargetGroups :: Field
1153
pTargetGroups =
1154
  optionalField $ simpleField "target_groups" [t| [NonEmptyString] |]
1155

    
1156
-- | Export mode field.
1157
pExportMode :: Field
1158
pExportMode =
1159
  renameField "ExportMode" $ simpleField "mode" [t| ExportMode |]
1160

    
1161
-- | Export target_node field, depends on mode.
1162
pExportTargetNode :: Field
1163
pExportTargetNode =
1164
  renameField "ExportTarget" $
1165
  simpleField "target_node" [t| ExportTarget |]
1166

    
1167
-- | Whether to remove instance after export.
1168
pRemoveInstance :: Field
1169
pRemoveInstance = defaultFalse "remove_instance"
1170

    
1171
-- | Whether to ignore failures while removing instances.
1172
pIgnoreRemoveFailures :: Field
1173
pIgnoreRemoveFailures = defaultFalse "ignore_remove_failures"
1174

    
1175
-- | Name of X509 key (remote export only).
1176
pX509KeyName :: Field
1177
pX509KeyName = optionalField $ simpleField "x509_key_name" [t| UncheckedList |]
1178

    
1179
-- | Destination X509 CA (remote export only).
1180
pX509DestCA :: Field
1181
pX509DestCA = optionalNEStringField "destination_x509_ca"
1182

    
1183
-- | Search pattern (regular expression). FIXME: this should be
1184
-- compiled at load time?
1185
pTagSearchPattern :: Field
1186
pTagSearchPattern =
1187
  renameField "TagSearchPattern" $ simpleField "pattern" [t| NonEmptyString |]
1188

    
1189
-- | Restricted command name.
1190
pRestrictedCommand :: Field
1191
pRestrictedCommand =
1192
  renameField "RestrictedCommand" $
1193
  simpleField "command" [t| NonEmptyString |]
1194

    
1195
-- | Replace disks mode.
1196
pReplaceDisksMode :: Field
1197
pReplaceDisksMode =
1198
  renameField "ReplaceDisksMode" $ simpleField "mode" [t| ReplaceDisksMode |]
1199

    
1200
-- | List of disk indices.
1201
pReplaceDisksList :: Field
1202
pReplaceDisksList =
1203
  renameField "ReplaceDisksList" $ simpleField "disks" [t| [DiskIndex] |]
1204

    
1205
-- | Whether do allow failover in migrations.
1206
pAllowFailover :: Field
1207
pAllowFailover = defaultFalse "allow_failover"
1208

    
1209
-- * Test opcode parameters
1210

    
1211
-- | Duration parameter for 'OpTestDelay'.
1212
pDelayDuration :: Field
1213
pDelayDuration =
1214
  renameField "DelayDuration" $ simpleField "duration" [t| Double |]
1215

    
1216
-- | on_master field for 'OpTestDelay'.
1217
pDelayOnMaster :: Field
1218
pDelayOnMaster = renameField "DelayOnMaster" $ defaultTrue "on_master"
1219

    
1220
-- | on_nodes field for 'OpTestDelay'.
1221
pDelayOnNodes :: Field
1222
pDelayOnNodes =
1223
  renameField "DelayOnNodes" .
1224
  defaultField [| [] |] $
1225
  simpleField "on_nodes" [t| [NonEmptyString] |]
1226

    
1227
-- | Repeat parameter for OpTestDelay.
1228
pDelayRepeat :: Field
1229
pDelayRepeat =
1230
  renameField "DelayRepeat" .
1231
  defaultField [| forceNonNeg (0::Int) |] $
1232
  simpleField "repeat" [t| NonNegative Int |]
1233

    
1234
-- | IAllocator test direction.
1235
pIAllocatorDirection :: Field
1236
pIAllocatorDirection =
1237
  renameField "IAllocatorDirection" $
1238
  simpleField "direction" [t| IAllocatorTestDir |]
1239

    
1240
-- | IAllocator test mode.
1241
pIAllocatorMode :: Field
1242
pIAllocatorMode =
1243
  renameField "IAllocatorMode" $
1244
  simpleField "mode" [t| IAllocatorMode |]
1245

    
1246
-- | IAllocator target name (new instance, node to evac, etc.).
1247
pIAllocatorReqName :: Field
1248
pIAllocatorReqName =
1249
  renameField "IAllocatorReqName" $ simpleField "name" [t| NonEmptyString |]
1250

    
1251
-- | Custom OpTestIAllocator nics.
1252
pIAllocatorNics :: Field
1253
pIAllocatorNics =
1254
  renameField "IAllocatorNics" $ simpleField "nics" [t| [UncheckedDict] |]
1255

    
1256
-- | Custom OpTestAllocator disks.
1257
pIAllocatorDisks :: Field
1258
pIAllocatorDisks =
1259
  renameField "IAllocatorDisks" $ simpleField "disks" [t| UncheckedList |]
1260

    
1261
-- | IAllocator memory field.
1262
pIAllocatorMemory :: Field
1263
pIAllocatorMemory =
1264
  renameField "IAllocatorMem" .
1265
  optionalField $
1266
  simpleField "memory" [t| NonNegative Int |]
1267

    
1268
-- | IAllocator vcpus field.
1269
pIAllocatorVCpus :: Field
1270
pIAllocatorVCpus =
1271
  renameField "IAllocatorVCpus" .
1272
  optionalField $
1273
  simpleField "vcpus" [t| NonNegative Int |]
1274

    
1275
-- | IAllocator os field.
1276
pIAllocatorOs :: Field
1277
pIAllocatorOs = renameField "IAllocatorOs" $ optionalNEStringField "os"
1278

    
1279
-- | IAllocator instances field.
1280
pIAllocatorInstances :: Field
1281
pIAllocatorInstances =
1282
  renameField "IAllocatorInstances " .
1283
  optionalField $
1284
  simpleField "instances" [t| [NonEmptyString] |]
1285

    
1286
-- | IAllocator evac mode.
1287
pIAllocatorEvacMode :: Field
1288
pIAllocatorEvacMode =
1289
  renameField "IAllocatorEvacMode" .
1290
  optionalField $
1291
  simpleField "evac_mode" [t| NodeEvacMode |]
1292

    
1293
-- | IAllocator spindle use.
1294
pIAllocatorSpindleUse :: Field
1295
pIAllocatorSpindleUse =
1296
  renameField "IAllocatorSpindleUse" .
1297
  defaultField [| forceNonNeg (1::Int) |] $
1298
  simpleField "spindle_use" [t| NonNegative Int |]
1299

    
1300
-- | IAllocator count field.
1301
pIAllocatorCount :: Field
1302
pIAllocatorCount =
1303
  renameField "IAllocatorCount" .
1304
  defaultField [| forceNonNeg (1::Int) |] $
1305
  simpleField "count" [t| NonNegative Int |]
1306

    
1307
-- | 'OpTestJqueue' notify_waitlock.
1308
pJQueueNotifyWaitLock :: Field
1309
pJQueueNotifyWaitLock = defaultFalse "notify_waitlock"
1310

    
1311
-- | 'OpTestJQueue' notify_exec.
1312
pJQueueNotifyExec :: Field
1313
pJQueueNotifyExec = defaultFalse "notify_exec"
1314

    
1315
-- | 'OpTestJQueue' log_messages.
1316
pJQueueLogMessages :: Field
1317
pJQueueLogMessages =
1318
  defaultField [| [] |] $ simpleField "log_messages" [t| [String] |]
1319

    
1320
-- | 'OpTestJQueue' fail attribute.
1321
pJQueueFail :: Field
1322
pJQueueFail =
1323
  renameField "JQueueFail" $ defaultFalse "fail"
1324

    
1325
-- | 'OpTestDummy' result field.
1326
pTestDummyResult :: Field
1327
pTestDummyResult =
1328
  renameField "TestDummyResult" $ simpleField "result" [t| UncheckedValue |]
1329

    
1330
-- | 'OpTestDummy' messages field.
1331
pTestDummyMessages :: Field
1332
pTestDummyMessages =
1333
  renameField "TestDummyMessages" $
1334
  simpleField "messages" [t| UncheckedValue |]
1335

    
1336
-- | 'OpTestDummy' fail field.
1337
pTestDummyFail :: Field
1338
pTestDummyFail =
1339
  renameField "TestDummyFail" $ simpleField "fail" [t| UncheckedValue |]
1340

    
1341
-- | 'OpTestDummy' submit_jobs field.
1342
pTestDummySubmitJobs :: Field
1343
pTestDummySubmitJobs =
1344
  renameField "TestDummySubmitJobs" $
1345
  simpleField "submit_jobs" [t| UncheckedValue |]
1346

    
1347
-- * Network parameters
1348

    
1349
-- | Network name.
1350
pNetworkName :: Field
1351
pNetworkName = simpleField "network_name" [t| NonEmptyString |]
1352

    
1353
-- | Network type field.
1354
pNetworkType :: Field
1355
pNetworkType = optionalField $ simpleField "network_type" [t| NetworkType |]
1356

    
1357
-- | Network address (IPv4 subnet). FIXME: no real type for this.
1358
pNetworkAddress4 :: Field
1359
pNetworkAddress4 =
1360
  renameField "NetworkAddress4" $
1361
  simpleField "network" [t| NonEmptyString |]
1362

    
1363
-- | Network gateway (IPv4 address). FIXME: no real type for this.
1364
pNetworkGateway4 :: Field
1365
pNetworkGateway4 =
1366
  renameField "NetworkGateway4" $
1367
  optionalNEStringField "gateway"
1368

    
1369
-- | Network address (IPv6 subnet). FIXME: no real type for this.
1370
pNetworkAddress6 :: Field
1371
pNetworkAddress6 =
1372
  renameField "NetworkAddress6" $
1373
  optionalNEStringField "network6"
1374

    
1375
-- | Network gateway (IPv6 address). FIXME: no real type for this.
1376
pNetworkGateway6 :: Field
1377
pNetworkGateway6 =
1378
  renameField "NetworkGateway6" $
1379
  optionalNEStringField "gateway6"
1380

    
1381
-- | Network specific mac prefix (that overrides the cluster one).
1382
pNetworkMacPrefix :: Field
1383
pNetworkMacPrefix =
1384
  renameField "NetMacPrefix" $
1385
  optionalNEStringField "mac_prefix"
1386

    
1387
-- | Network add reserved IPs.
1388
pNetworkAddRsvdIps :: Field
1389
pNetworkAddRsvdIps =
1390
  renameField "NetworkAddRsvdIps" .
1391
  optionalField $
1392
  simpleField "add_reserved_ips" [t| [NonEmptyString] |]
1393

    
1394
-- | Network remove reserved IPs.
1395
pNetworkRemoveRsvdIps :: Field
1396
pNetworkRemoveRsvdIps =
1397
  renameField "NetworkRemoveRsvdIps" .
1398
  optionalField $
1399
  simpleField "remove_reserved_ips" [t| [NonEmptyString] |]
1400

    
1401
-- | Network mode when connecting to a group.
1402
pNetworkMode :: Field
1403
pNetworkMode = simpleField "network_mode" [t| NICMode |]
1404

    
1405
-- | Network link when connecting to a group.
1406
pNetworkLink :: Field
1407
pNetworkLink = simpleField "network_link" [t| NonEmptyString |]
1408

    
1409
-- * Common opcode parameters
1410

    
1411
-- | Run checks only, don't execute.
1412
pDryRun :: Field
1413
pDryRun = optionalField $ booleanField "dry_run"
1414

    
1415
-- | Debug level.
1416
pDebugLevel :: Field
1417
pDebugLevel = optionalField $ simpleField "debug_level" [t| NonNegative Int |]
1418

    
1419
-- | Opcode priority. Note: python uses a separate constant, we're
1420
-- using the actual value we know it's the default.
1421
pOpPriority :: Field
1422
pOpPriority =
1423
  defaultField [| OpPrioNormal |] $
1424
  simpleField "priority" [t| OpSubmitPriority |]
1425

    
1426
-- | Job dependencies.
1427
pDependencies :: Field
1428
pDependencies = optionalField $ simpleField "depends" [t| [JobDependency] |]
1429

    
1430
-- | Comment field.
1431
pComment :: Field
1432
pComment = optionalField $ stringField "comment"
1433

    
1434
-- * Entire opcode parameter list
1435

    
1436
-- | Old-style query opcode, with locking.
1437
dOldQuery :: [Field]
1438
dOldQuery =
1439
  [ pOutputFields
1440
  , pNames
1441
  , pUseLocking
1442
  ]
1443

    
1444
-- | Old-style query opcode, without locking.
1445
dOldQueryNoLocking :: [Field]
1446
dOldQueryNoLocking =
1447
  [ pOutputFields
1448
  , pNames
1449
  ]