Statistics
| Branch: | Tag: | Revision:

root / htools / Ganeti / OpParams.hs @ 3131adc7

History | View | Annotate | Download (39.9 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
  , decodeTagObject
39
  , encodeTagObject
40
  , ReplaceDisksMode(..)
41
  , DiskIndex
42
  , mkDiskIndex
43
  , unDiskIndex
44
  , DiskAccess(..)
45
  , INicParams(..)
46
  , IDiskParams(..)
47
  , RecreateDisksInfo(..)
48
  , DdmOldChanges(..)
49
  , SetParamsMods(..)
50
  , ExportTarget(..)
51
  , pInstanceName
52
  , pInstances
53
  , pName
54
  , pTagsList
55
  , pTagsObject
56
  , pOutputFields
57
  , pShutdownTimeout
58
  , pShutdownTimeout'
59
  , pForce
60
  , pIgnoreOfflineNodes
61
  , pNodeName
62
  , pNodeNames
63
  , pGroupName
64
  , pMigrationMode
65
  , pMigrationLive
66
  , pForceVariant
67
  , pWaitForSync
68
  , pWaitForSyncFalse
69
  , pIgnoreConsistency
70
  , pStorageName
71
  , pUseLocking
72
  , pNameCheck
73
  , pNodeGroupAllocPolicy
74
  , pGroupNodeParams
75
  , pQueryWhat
76
  , pEarlyRelease
77
  , pIpCheck
78
  , pIpConflictsCheck
79
  , pNoRemember
80
  , pMigrationTargetNode
81
  , pMoveTargetNode
82
  , pStartupPaused
83
  , pVerbose
84
  , pDebugSimulateErrors
85
  , pErrorCodes
86
  , pSkipChecks
87
  , pIgnoreErrors
88
  , pOptGroupName
89
  , pDiskParams
90
  , pHvState
91
  , pDiskState
92
  , pIgnoreIpolicy
93
  , pAllowRuntimeChgs
94
  , pInstDisks
95
  , pDiskTemplate
96
  , pFileDriver
97
  , pFileStorageDir
98
  , pVgName
99
  , pEnabledHypervisors
100
  , pHypervisor
101
  , pClusterHvParams
102
  , pInstHvParams
103
  , pClusterBeParams
104
  , pInstBeParams
105
  , pResetDefaults
106
  , pOsHvp
107
  , pClusterOsParams
108
  , pInstOsParams
109
  , pCandidatePoolSize
110
  , pUidPool
111
  , pAddUids
112
  , pRemoveUids
113
  , pMaintainNodeHealth
114
  , pPreallocWipeDisks
115
  , pNicParams
116
  , pInstNics
117
  , pNdParams
118
  , pIpolicy
119
  , pDrbdHelper
120
  , pDefaultIAllocator
121
  , pMasterNetdev
122
  , pMasterNetmask
123
  , pReservedLvs
124
  , pHiddenOs
125
  , pBlacklistedOs
126
  , pUseExternalMipScript
127
  , pQueryFields
128
  , pQueryFilter
129
  , pOobCommand
130
  , pOobTimeout
131
  , pIgnoreStatus
132
  , pPowerDelay
133
  , pPrimaryIp
134
  , pSecondaryIp
135
  , pReadd
136
  , pNodeGroup
137
  , pMasterCapable
138
  , pVmCapable
139
  , pNames
140
  , pNodes
141
  , pRequiredNodes
142
  , pStorageType
143
  , pStorageChanges
144
  , pMasterCandidate
145
  , pOffline
146
  , pDrained
147
  , pAutoPromote
148
  , pPowered
149
  , pIallocator
150
  , pRemoteNode
151
  , pEvacMode
152
  , pInstCreateMode
153
  , pNoInstall
154
  , pInstOs
155
  , pPrimaryNode
156
  , pSecondaryNode
157
  , pSourceHandshake
158
  , pSourceInstance
159
  , pSourceShutdownTimeout
160
  , pSourceX509Ca
161
  , pSrcNode
162
  , pSrcPath
163
  , pStartInstance
164
  , pInstTags
165
  , pMultiAllocInstances
166
  , pTempOsParams
167
  , pTempHvParams
168
  , pTempBeParams
169
  , pIgnoreFailures
170
  , pNewName
171
  , pIgnoreSecondaries
172
  , pRebootType
173
  , pIgnoreDiskSize
174
  , pRecreateDisksInfo
175
  , pStatic
176
  , pInstParamsNicChanges
177
  , pInstParamsDiskChanges
178
  , pRuntimeMem
179
  , pOsNameChange
180
  , pDiskIndex
181
  , pDiskChgAmount
182
  , pDiskChgAbsolute
183
  , pTargetGroups
184
  , pExportMode
185
  , pExportTargetNode
186
  , pRemoveInstance
187
  , pIgnoreRemoveFailures
188
  , pX509KeyName
189
  , pX509DestCA
190
  , pTagSearchPattern
191
  , pRestrictedCommand
192
  , pDelayRepeat
193
  , pIAllocatorDirection
194
  , pIAllocatorMode
195
  , pIAllocatorReqName
196
  , pIAllocatorNics
197
  , pIAllocatorDisks
198
  , pIAllocatorMemory
199
  , pIAllocatorVCpus
200
  , pIAllocatorOs
201
  , pIAllocatorInstances
202
  , pIAllocatorEvacMode
203
  , pIAllocatorSpindleUse
204
  , pIAllocatorCount
205
  , pJQueueNotifyWaitLock
206
  , pJQueueNotifyExec
207
  , pJQueueLogMessages
208
  , pJQueueFail
209
  , pTestDummyResult
210
  , pTestDummyMessages
211
  , pTestDummyFail
212
  , pTestDummySubmitJobs
213
  , pNetworkName
214
  , pNetworkType
215
  , pNetworkAddress4
216
  , pNetworkGateway4
217
  , pNetworkAddress6
218
  , pNetworkGateway6
219
  , pNetworkMacPrefix
220
  , pNetworkAddRsvdIps
221
  , pNetworkRemoveRsvdIps
222
  , pNetworkMode
223
  , pNetworkLink
224
  , dOldQuery
225
  , dOldQueryNoLocking
226
  ) where
227

    
228
import Control.Monad (liftM)
229
import qualified Data.Set as Set
230
import Text.JSON (readJSON, showJSON, JSON, JSValue(..), fromJSString,
231
                  JSObject, toJSObject)
232
import qualified Text.JSON
233
import Text.JSON.Pretty (pp_value)
234

    
235
import Ganeti.BasicTypes
236
import qualified Ganeti.Constants as C
237
import Ganeti.THH
238
import Ganeti.JSON
239
import Ganeti.Types
240
import qualified Ganeti.Query.Language as Qlang
241

    
242
-- * Helper functions and types
243

    
244
-- * Type aliases
245

    
246
-- | Build a boolean field.
247
booleanField :: String -> Field
248
booleanField = flip simpleField [t| Bool |]
249

    
250
-- | Default a field to 'False'.
251
defaultFalse :: String -> Field
252
defaultFalse = defaultField [| False |] . booleanField
253

    
254
-- | Default a field to 'True'.
255
defaultTrue :: String -> Field
256
defaultTrue = defaultField [| True |] . booleanField
257

    
258
-- | An alias for a 'String' field.
259
stringField :: String -> Field
260
stringField = flip simpleField [t| String |]
261

    
262
-- | An alias for an optional string field.
263
optionalStringField :: String -> Field
264
optionalStringField = optionalField . stringField
265

    
266
-- | An alias for an optional non-empty string field.
267
optionalNEStringField :: String -> Field
268
optionalNEStringField = optionalField . flip simpleField [t| NonEmptyString |]
269

    
270
-- | Unchecked value, should be replaced by a better definition.
271
type UncheckedValue = JSValue
272

    
273
-- | Unchecked dict, should be replaced by a better definition.
274
type UncheckedDict = JSObject JSValue
275

    
276
-- | Unchecked list, shoild be replaced by a better definition.
277
type UncheckedList = [JSValue]
278

    
279
-- | Function to force a non-negative value, without returning via a
280
-- monad. This is needed for, and should be used /only/ in the case of
281
-- forcing constants. In case the constant is wrong (< 0), this will
282
-- become a runtime error.
283
forceNonNeg :: (Num a, Ord a, Show a) => a -> NonNegative a
284
forceNonNeg i = case mkNonNegative i of
285
                  Ok n -> n
286
                  Bad msg -> error msg
287

    
288
-- ** Tags
289

    
290
-- | Data type representing what items do the tag operations apply to.
291
$(declareSADT "TagType"
292
  [ ("TagTypeInstance", 'C.tagInstance)
293
  , ("TagTypeNode",     'C.tagNode)
294
  , ("TagTypeGroup",    'C.tagNodegroup)
295
  , ("TagTypeCluster",  'C.tagCluster)
296
  ])
297
$(makeJSONInstance ''TagType)
298

    
299
-- | Data type holding a tag object (type and object name).
300
data TagObject = TagInstance String
301
               | TagNode     String
302
               | TagGroup    String
303
               | TagCluster
304
               deriving (Show, Read, Eq)
305

    
306
-- | Tag type for a given tag object.
307
tagTypeOf :: TagObject -> TagType
308
tagTypeOf (TagInstance {}) = TagTypeInstance
309
tagTypeOf (TagNode     {}) = TagTypeNode
310
tagTypeOf (TagGroup    {}) = TagTypeGroup
311
tagTypeOf (TagCluster  {}) = TagTypeCluster
312

    
313
-- | Gets the potential tag object name.
314
tagNameOf :: TagObject -> Maybe String
315
tagNameOf (TagInstance s) = Just s
316
tagNameOf (TagNode     s) = Just s
317
tagNameOf (TagGroup    s) = Just s
318
tagNameOf  TagCluster     = Nothing
319

    
320
-- | Builds a 'TagObject' from a tag type and name.
321
tagObjectFrom :: (Monad m) => TagType -> JSValue -> m TagObject
322
tagObjectFrom TagTypeInstance (JSString s) =
323
  return . TagInstance $ fromJSString s
324
tagObjectFrom TagTypeNode     (JSString s) = return . TagNode $ fromJSString s
325
tagObjectFrom TagTypeGroup    (JSString s) = return . TagGroup $ fromJSString s
326
tagObjectFrom TagTypeCluster   JSNull      = return TagCluster
327
tagObjectFrom t v =
328
  fail $ "Invalid tag type/name combination: " ++ show t ++ "/" ++
329
         show (pp_value v)
330

    
331
-- | Name of the tag \"name\" field.
332
tagNameField :: String
333
tagNameField = "name"
334

    
335
-- | Custom encoder for 'TagObject' as represented in an opcode.
336
encodeTagObject :: TagObject -> (JSValue, [(String, JSValue)])
337
encodeTagObject t = ( showJSON (tagTypeOf t)
338
                    , [(tagNameField, maybe JSNull showJSON (tagNameOf t))] )
339

    
340
-- | Custom decoder for 'TagObject' as represented in an opcode.
341
decodeTagObject :: (Monad m) => [(String, JSValue)] -> JSValue -> m TagObject
342
decodeTagObject obj kind = do
343
  ttype <- fromJVal kind
344
  tname <- fromObj obj tagNameField
345
  tagObjectFrom ttype tname
346

    
347
-- ** Disks
348

    
349
-- | Replace disks type.
350
$(declareSADT "ReplaceDisksMode"
351
  [ ("ReplaceOnPrimary",    'C.replaceDiskPri)
352
  , ("ReplaceOnSecondary",  'C.replaceDiskSec)
353
  , ("ReplaceNewSecondary", 'C.replaceDiskChg)
354
  , ("ReplaceAuto",         'C.replaceDiskAuto)
355
  ])
356
$(makeJSONInstance ''ReplaceDisksMode)
357

    
358
-- | Disk index type (embedding constraints on the index value via a
359
-- smart constructor).
360
newtype DiskIndex = DiskIndex { unDiskIndex :: Int }
361
  deriving (Show, Read, Eq, Ord)
362

    
363
-- | Smart constructor for 'DiskIndex'.
364
mkDiskIndex :: (Monad m) => Int -> m DiskIndex
365
mkDiskIndex i | i >= 0 && i < C.maxDisks = return (DiskIndex i)
366
              | otherwise = fail $ "Invalid value for disk index '" ++
367
                            show i ++ "', required between 0 and " ++
368
                            show C.maxDisks
369

    
370
instance JSON DiskIndex where
371
  readJSON v = readJSON v >>= mkDiskIndex
372
  showJSON = showJSON . unDiskIndex
373

    
374
-- ** I* param types
375

    
376
-- | Type holding disk access modes.
377
$(declareSADT "DiskAccess"
378
  [ ("DiskReadOnly",  'C.diskRdonly)
379
  , ("DiskReadWrite", 'C.diskRdwr)
380
  ])
381
$(makeJSONInstance ''DiskAccess)
382

    
383
-- | NIC modification definition.
384
$(buildObject "INicParams" "inic"
385
  [ optionalField $ simpleField C.inicMac  [t| NonEmptyString |]
386
  , optionalField $ simpleField C.inicIp   [t| String         |]
387
  , optionalField $ simpleField C.inicMode [t| NonEmptyString |]
388
  , optionalField $ simpleField C.inicLink [t| NonEmptyString |]
389
  ])
390

    
391
-- | Disk modification definition. FIXME: disksize should be VTYPE_UNIT.
392
$(buildObject "IDiskParams" "idisk"
393
  [ optionalField $ simpleField C.idiskSize   [t| Int            |]
394
  , optionalField $ simpleField C.idiskMode   [t| DiskAccess     |]
395
  , optionalField $ simpleField C.idiskAdopt  [t| NonEmptyString |]
396
  , optionalField $ simpleField C.idiskVg     [t| NonEmptyString |]
397
  , optionalField $ simpleField C.idiskMetavg [t| NonEmptyString |]
398
  ])
399

    
400
-- | Disk changes type for OpInstanceRecreateDisks. This is a bit
401
-- strange, because the type in Python is something like Either
402
-- [DiskIndex] [DiskChanges], but we can't represent the type of an
403
-- empty list in JSON, so we have to add a custom case for the empty
404
-- list.
405
data RecreateDisksInfo
406
  = RecreateDisksAll
407
  | RecreateDisksIndices (NonEmpty DiskIndex)
408
  | RecreateDisksParams (NonEmpty (DiskIndex, IDiskParams))
409
    deriving (Eq, Read, Show)
410

    
411
readRecreateDisks :: JSValue -> Text.JSON.Result RecreateDisksInfo
412
readRecreateDisks (JSArray []) = return RecreateDisksAll
413
readRecreateDisks v =
414
  case readJSON v::Text.JSON.Result [DiskIndex] of
415
    Text.JSON.Ok indices -> liftM RecreateDisksIndices (mkNonEmpty indices)
416
    _ -> case readJSON v::Text.JSON.Result [(DiskIndex, IDiskParams)] of
417
           Text.JSON.Ok params -> liftM RecreateDisksParams (mkNonEmpty params)
418
           _ -> fail $ "Can't parse disk information as either list of disk"
419
                ++ " indices or list of disk parameters; value recevied:"
420
                ++ show (pp_value v)
421

    
422
instance JSON RecreateDisksInfo where
423
  readJSON = readRecreateDisks
424
  showJSON  RecreateDisksAll            = showJSON ()
425
  showJSON (RecreateDisksIndices idx)   = showJSON idx
426
  showJSON (RecreateDisksParams params) = showJSON params
427

    
428
-- | Simple type for old-style ddm changes.
429
data DdmOldChanges = DdmOldIndex (NonNegative Int)
430
                   | DdmOldMod DdmSimple
431
                     deriving (Eq, Read, Show)
432

    
433
readDdmOldChanges :: JSValue -> Text.JSON.Result DdmOldChanges
434
readDdmOldChanges v =
435
  case readJSON v::Text.JSON.Result (NonNegative Int) of
436
    Text.JSON.Ok nn -> return $ DdmOldIndex nn
437
    _ -> case readJSON v::Text.JSON.Result DdmSimple of
438
           Text.JSON.Ok ddms -> return $ DdmOldMod ddms
439
           _ -> fail $ "Can't parse value '" ++ show (pp_value v) ++ "' as"
440
                ++ " either index or modification"
441

    
442
instance JSON DdmOldChanges where
443
  showJSON (DdmOldIndex i) = showJSON i
444
  showJSON (DdmOldMod m)   = showJSON m
445
  readJSON = readDdmOldChanges
446

    
447
-- | Instance disk or nic modifications.
448
data SetParamsMods a
449
  = SetParamsEmpty
450
  | SetParamsDeprecated (NonEmpty (DdmOldChanges, a))
451
  | SetParamsNew (NonEmpty (DdmFull, Int, a))
452
    deriving (Eq, Read, Show)
453

    
454
-- | Custom deserialiser for 'SetParamsMods'.
455
readSetParams :: (JSON a) => JSValue -> Text.JSON.Result (SetParamsMods a)
456
readSetParams (JSArray []) = return SetParamsEmpty
457
readSetParams v =
458
  case readJSON v::Text.JSON.Result [(DdmOldChanges, JSValue)] of
459
    Text.JSON.Ok _ -> liftM SetParamsDeprecated $ readJSON v
460
    _ -> liftM SetParamsNew $ readJSON v
461

    
462
instance (JSON a) => JSON (SetParamsMods a) where
463
  showJSON SetParamsEmpty = showJSON ()
464
  showJSON (SetParamsDeprecated v) = showJSON v
465
  showJSON (SetParamsNew v) = showJSON v
466
  readJSON = readSetParams
467

    
468
-- | Custom type for target_node parameter of OpBackupExport, which
469
-- varies depending on mode. FIXME: this uses an UncheckedList since
470
-- we don't care about individual rows (just like the Python code
471
-- tests). But the proper type could be parsed if we wanted.
472
data ExportTarget = ExportTargetLocal NonEmptyString
473
                  | ExportTargetRemote UncheckedList
474
                    deriving (Eq, Read, Show)
475

    
476
-- | Custom reader for 'ExportTarget'.
477
readExportTarget :: JSValue -> Text.JSON.Result ExportTarget
478
readExportTarget (JSString s) = liftM ExportTargetLocal $
479
                                mkNonEmpty (fromJSString s)
480
readExportTarget (JSArray arr) = return $ ExportTargetRemote arr
481
readExportTarget v = fail $ "Invalid value received for 'target_node': " ++
482
                     show (pp_value v)
483

    
484
instance JSON ExportTarget where
485
  showJSON (ExportTargetLocal s)  = showJSON s
486
  showJSON (ExportTargetRemote l) = showJSON l
487
  readJSON = readExportTarget
488

    
489
-- * Parameters
490

    
491
-- | A required instance name (for single-instance LUs).
492
pInstanceName :: Field
493
pInstanceName = simpleField "instance_name" [t| String |]
494

    
495
-- | A list of instances.
496
pInstances :: Field
497
pInstances = defaultField [| [] |] $
498
             simpleField "instances" [t| [NonEmptyString] |]
499

    
500
-- | A generic name.
501
pName :: Field
502
pName = simpleField "name" [t| NonEmptyString |]
503

    
504
-- | Tags list.
505
pTagsList :: Field
506
pTagsList = simpleField "tags" [t| [String] |]
507

    
508
-- | Tags object.
509
pTagsObject :: Field
510
pTagsObject = customField 'decodeTagObject 'encodeTagObject $
511
              simpleField "kind" [t| TagObject |]
512

    
513
-- | Selected output fields.
514
pOutputFields :: Field
515
pOutputFields = simpleField "output_fields" [t| [NonEmptyString] |]
516

    
517
-- | How long to wait for instance to shut down.
518
pShutdownTimeout :: Field
519
pShutdownTimeout = defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
520
                   simpleField "shutdown_timeout" [t| NonNegative Int |]
521

    
522
-- | Another name for the shutdown timeout, because we like to be
523
-- inconsistent.
524
pShutdownTimeout' :: Field
525
pShutdownTimeout' =
526
  renameField "InstShutdownTimeout" .
527
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
528
  simpleField "timeout" [t| NonNegative Int |]
529

    
530
-- | Whether to force the operation.
531
pForce :: Field
532
pForce = defaultFalse "force"
533

    
534
-- | Whether to ignore offline nodes.
535
pIgnoreOfflineNodes :: Field
536
pIgnoreOfflineNodes = defaultFalse "ignore_offline_nodes"
537

    
538
-- | A required node name (for single-node LUs).
539
pNodeName :: Field
540
pNodeName = simpleField "node_name" [t| NonEmptyString |]
541

    
542
-- | List of nodes.
543
pNodeNames :: Field
544
pNodeNames =
545
  defaultField [| [] |] $ simpleField "node_names" [t| [NonEmptyString] |]
546

    
547
-- | A required node group name (for single-group LUs).
548
pGroupName :: Field
549
pGroupName = simpleField "group_name" [t| NonEmptyString |]
550

    
551
-- | Migration type (live\/non-live).
552
pMigrationMode :: Field
553
pMigrationMode =
554
  renameField "MigrationMode" .
555
  optionalField $
556
  simpleField "mode" [t| MigrationMode |]
557

    
558
-- | Obsolete \'live\' migration mode (boolean).
559
pMigrationLive :: Field
560
pMigrationLive =
561
  renameField "OldLiveMode" . optionalField $ booleanField "live"
562

    
563
-- | Whether to force an unknown OS variant.
564
pForceVariant :: Field
565
pForceVariant = defaultFalse "force_variant"
566

    
567
-- | Whether to wait for the disk to synchronize.
568
pWaitForSync :: Field
569
pWaitForSync = defaultTrue "wait_for_sync"
570

    
571
-- | Whether to wait for the disk to synchronize (defaults to false).
572
pWaitForSyncFalse :: Field
573
pWaitForSyncFalse = defaultField [| False |] pWaitForSync
574

    
575
-- | Whether to ignore disk consistency
576
pIgnoreConsistency :: Field
577
pIgnoreConsistency = defaultFalse "ignore_consistency"
578

    
579
-- | Storage name.
580
pStorageName :: Field
581
pStorageName =
582
  renameField "StorageName" $ simpleField "name" [t| NonEmptyString |]
583

    
584
-- | Whether to use synchronization.
585
pUseLocking :: Field
586
pUseLocking = defaultFalse "use_locking"
587

    
588
-- | Whether to check name.
589
pNameCheck :: Field
590
pNameCheck = defaultTrue "name_check"
591

    
592
-- | Instance allocation policy.
593
pNodeGroupAllocPolicy :: Field
594
pNodeGroupAllocPolicy = optionalField $
595
                        simpleField "alloc_policy" [t| AllocPolicy |]
596

    
597
-- | Default node parameters for group.
598
pGroupNodeParams :: Field
599
pGroupNodeParams = optionalField $ simpleField "ndparams" [t| UncheckedDict |]
600

    
601
-- | Resource(s) to query for.
602
pQueryWhat :: Field
603
pQueryWhat = simpleField "what" [t| Qlang.QueryTypeOp |]
604

    
605
-- | Whether to release locks as soon as possible.
606
pEarlyRelease :: Field
607
pEarlyRelease = defaultFalse "early_release"
608

    
609
-- | Whether to ensure instance's IP address is inactive.
610
pIpCheck :: Field
611
pIpCheck = defaultTrue "ip_check"
612

    
613
-- | Check for conflicting IPs.
614
pIpConflictsCheck :: Field
615
pIpConflictsCheck = defaultTrue "conflicts_check"
616

    
617
-- | Do not remember instance state changes.
618
pNoRemember :: Field
619
pNoRemember = defaultFalse "no_remember"
620

    
621
-- | Target node for instance migration/failover.
622
pMigrationTargetNode :: Field
623
pMigrationTargetNode = optionalNEStringField "target_node"
624

    
625
-- | Target node for instance move (required).
626
pMoveTargetNode :: Field
627
pMoveTargetNode =
628
  renameField "MoveTargetNode" $
629
  simpleField "target_node" [t| NonEmptyString |]
630

    
631
-- | Pause instance at startup.
632
pStartupPaused :: Field
633
pStartupPaused = defaultFalse "startup_paused"
634

    
635
-- | Verbose mode.
636
pVerbose :: Field
637
pVerbose = defaultFalse "verbose"
638

    
639
-- ** Parameters for cluster verification
640

    
641
-- | Whether to simulate errors (useful for debugging).
642
pDebugSimulateErrors :: Field
643
pDebugSimulateErrors = defaultFalse "debug_simulate_errors"
644

    
645
-- | Error codes.
646
pErrorCodes :: Field
647
pErrorCodes = defaultFalse "error_codes"
648

    
649
-- | Which checks to skip.
650
pSkipChecks :: Field
651
pSkipChecks = defaultField [| Set.empty |] $
652
              simpleField "skip_checks" [t| Set.Set VerifyOptionalChecks |]
653

    
654
-- | List of error codes that should be treated as warnings.
655
pIgnoreErrors :: Field
656
pIgnoreErrors = defaultField [| Set.empty |] $
657
                simpleField "ignore_errors" [t| Set.Set CVErrorCode |]
658

    
659
-- | Optional group name.
660
pOptGroupName :: Field
661
pOptGroupName = renameField "OptGroupName" .
662
                optionalField $ simpleField "group_name" [t| NonEmptyString |]
663

    
664
-- | Disk templates' parameter defaults.
665
pDiskParams :: Field
666
pDiskParams = optionalField $
667
              simpleField "diskparams" [t| GenericContainer DiskTemplate
668
                                           UncheckedDict |]
669

    
670
-- * Parameters for node resource model
671

    
672
-- | Set hypervisor states.
673
pHvState :: Field
674
pHvState = optionalField $ simpleField "hv_state" [t| UncheckedDict |]
675

    
676
-- | Set disk states.
677
pDiskState :: Field
678
pDiskState = optionalField $ simpleField "disk_state" [t| UncheckedDict |]
679

    
680
-- | Whether to ignore ipolicy violations.
681
pIgnoreIpolicy :: Field
682
pIgnoreIpolicy = defaultFalse "ignore_ipolicy"
683

    
684
-- | Allow runtime changes while migrating.
685
pAllowRuntimeChgs :: Field
686
pAllowRuntimeChgs = defaultTrue "allow_runtime_changes"
687

    
688
-- | Utility type for OpClusterSetParams.
689
type TestClusterOsListItem = (DdmSimple, NonEmptyString)
690

    
691
-- | Utility type of OsList.
692
type TestClusterOsList = [TestClusterOsListItem]
693

    
694
-- Utility type for NIC definitions.
695
--type TestNicDef = INicParams
696

    
697
-- | List of instance disks.
698
pInstDisks :: Field
699
pInstDisks = renameField "instDisks" $ simpleField "disks" [t| [IDiskParams] |]
700

    
701
-- | Instance disk template.
702
pDiskTemplate :: Field
703
pDiskTemplate = simpleField "disk_template" [t| DiskTemplate |]
704

    
705
-- | File driver.
706
pFileDriver :: Field
707
pFileDriver = optionalField $ simpleField "file_driver" [t| FileDriver |]
708

    
709
-- | Directory for storing file-backed disks.
710
pFileStorageDir :: Field
711
pFileStorageDir = optionalNEStringField "file_storage_dir"
712

    
713
-- | Volume group name.
714
pVgName :: Field
715
pVgName = optionalStringField "vg_name"
716

    
717
-- | List of enabled hypervisors.
718
pEnabledHypervisors :: Field
719
pEnabledHypervisors =
720
  optionalField $
721
  simpleField "enabled_hypervisors" [t| NonEmpty Hypervisor |]
722

    
723
-- | Selected hypervisor for an instance.
724
pHypervisor :: Field
725
pHypervisor =
726
  optionalField $
727
  simpleField "hypervisor" [t| Hypervisor |]
728

    
729
-- | Cluster-wide hypervisor parameters, hypervisor-dependent.
730
pClusterHvParams :: Field
731
pClusterHvParams =
732
  renameField "ClusterHvParams" .
733
  optionalField $
734
  simpleField "hvparams" [t| Container UncheckedDict |]
735

    
736
-- | Instance hypervisor parameters.
737
pInstHvParams :: Field
738
pInstHvParams =
739
  renameField "InstHvParams" .
740
  defaultField [| toJSObject [] |] $
741
  simpleField "hvparams" [t| UncheckedDict |]
742

    
743
-- | Cluster-wide beparams.
744
pClusterBeParams :: Field
745
pClusterBeParams =
746
  renameField "ClusterBeParams" .
747
  optionalField $ simpleField "beparams" [t| UncheckedDict |]
748

    
749
-- | Instance beparams.
750
pInstBeParams :: Field
751
pInstBeParams =
752
  renameField "InstBeParams" .
753
  defaultField [| toJSObject [] |] $
754
  simpleField "beparams" [t| UncheckedDict |]
755

    
756
-- | Reset instance parameters to default if equal.
757
pResetDefaults :: Field
758
pResetDefaults = defaultFalse "identify_defaults"
759

    
760
-- | Cluster-wide per-OS hypervisor parameter defaults.
761
pOsHvp :: Field
762
pOsHvp = optionalField $ simpleField "os_hvp" [t| Container UncheckedDict |]
763

    
764
-- | Cluster-wide OS parameter defaults.
765
pClusterOsParams :: Field
766
pClusterOsParams =
767
  renameField "ClusterOsParams" .
768
  optionalField $ simpleField "osparams" [t| Container UncheckedDict |]
769

    
770
-- | Instance OS parameters.
771
pInstOsParams :: Field
772
pInstOsParams =
773
  renameField "InstOsParams" . defaultField [| toJSObject [] |] $
774
  simpleField "osparams" [t| UncheckedDict |]
775

    
776
-- | Temporary OS parameters (currently only in reinstall, might be
777
-- added to install as well).
778
pTempOsParams :: Field
779
pTempOsParams =
780
  renameField "TempOsParams" .
781
  optionalField $ simpleField "osparams" [t| UncheckedDict |]
782

    
783
-- | Temporary hypervisor parameters, hypervisor-dependent.
784
pTempHvParams :: Field
785
pTempHvParams =
786
  renameField "TempHvParams" .
787
  defaultField [| toJSObject [] |] $
788
  simpleField "hvparams" [t| UncheckedDict |]
789

    
790
-- | Temporary backend parameters.
791
pTempBeParams :: Field
792
pTempBeParams =
793
  renameField "TempBeParams" .
794
  defaultField [| toJSObject [] |] $
795
  simpleField "beparams" [t| UncheckedDict |]
796

    
797
-- | Candidate pool size.
798
pCandidatePoolSize :: Field
799
pCandidatePoolSize =
800
  optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]
801

    
802
-- | Set UID pool, must be list of lists describing UID ranges (two
803
-- items, start and end inclusive.
804
pUidPool :: Field
805
pUidPool = optionalField $ simpleField "uid_pool" [t| [[(Int, Int)]] |]
806

    
807
-- | Extend UID pool, must be list of lists describing UID ranges (two
808
-- items, start and end inclusive.
809
pAddUids :: Field
810
pAddUids = optionalField $ simpleField "add_uids" [t| [[(Int, Int)]] |]
811

    
812
-- | Shrink UID pool, must be list of lists describing UID ranges (two
813
-- items, start and end inclusive) to be removed.
814
pRemoveUids :: Field
815
pRemoveUids = optionalField $ simpleField "remove_uids" [t| [[(Int, Int)]] |]
816

    
817
-- | Whether to automatically maintain node health.
818
pMaintainNodeHealth :: Field
819
pMaintainNodeHealth = optionalField $ booleanField "maintain_node_health"
820

    
821
-- | Whether to wipe disks before allocating them to instances.
822
pPreallocWipeDisks :: Field
823
pPreallocWipeDisks = optionalField $ booleanField "prealloc_wipe_disks"
824

    
825
-- | Cluster-wide NIC parameter defaults.
826
pNicParams :: Field
827
pNicParams = optionalField $ simpleField "nicparams" [t| INicParams |]
828

    
829
-- | Instance NIC definitions.
830
pInstNics :: Field
831
pInstNics = simpleField "nics" [t| [INicParams] |]
832

    
833
-- | Cluster-wide node parameter defaults.
834
pNdParams :: Field
835
pNdParams = optionalField $ simpleField "ndparams" [t| UncheckedDict |]
836

    
837
-- | Cluster-wide ipolicy specs.
838
pIpolicy :: Field
839
pIpolicy = optionalField $ simpleField "ipolicy" [t| UncheckedDict |]
840

    
841
-- | DRBD helper program.
842
pDrbdHelper :: Field
843
pDrbdHelper = optionalStringField "drbd_helper"
844

    
845
-- | Default iallocator for cluster.
846
pDefaultIAllocator :: Field
847
pDefaultIAllocator = optionalStringField "default_iallocator"
848

    
849
-- | Master network device.
850
pMasterNetdev :: Field
851
pMasterNetdev = optionalStringField "master_netdev"
852

    
853
-- | Netmask of the master IP.
854
pMasterNetmask :: Field
855
pMasterNetmask = optionalField $ simpleField "master_netmask" [t| Int |]
856

    
857
-- | List of reserved LVs.
858
pReservedLvs :: Field
859
pReservedLvs =
860
  optionalField $ simpleField "reserved_lvs" [t| [NonEmptyString] |]
861

    
862
-- | Modify list of hidden operating systems: each modification must
863
-- have two items, the operation and the OS name; the operation can be
864
-- add or remove.
865
pHiddenOs :: Field
866
pHiddenOs = optionalField $ simpleField "hidden_os" [t| TestClusterOsList |]
867

    
868
-- | Modify list of blacklisted operating systems: each modification
869
-- must have two items, the operation and the OS name; the operation
870
-- can be add or remove.
871
pBlacklistedOs :: Field
872
pBlacklistedOs =
873
  optionalField $ simpleField "blacklisted_os" [t| TestClusterOsList |]
874

    
875
-- | Whether to use an external master IP address setup script.
876
pUseExternalMipScript :: Field
877
pUseExternalMipScript = optionalField $ booleanField "use_external_mip_script"
878

    
879
-- | Requested fields.
880
pQueryFields :: Field
881
pQueryFields = simpleField "fields" [t| [NonEmptyString] |]
882

    
883
-- | Query filter.
884
pQueryFilter :: Field
885
pQueryFilter = simpleField "qfilter" [t| Qlang.Filter String |]
886

    
887
-- | OOB command to run.
888
pOobCommand :: Field
889
pOobCommand = simpleField "command" [t| OobCommand |]
890

    
891
-- | Timeout before the OOB helper will be terminated.
892
pOobTimeout :: Field
893
pOobTimeout =
894
  defaultField [| C.oobTimeout |] $ simpleField "timeout" [t| Int |]
895

    
896
-- | Ignores the node offline status for power off.
897
pIgnoreStatus :: Field
898
pIgnoreStatus = defaultFalse "ignore_status"
899

    
900
-- | Time in seconds to wait between powering on nodes.
901
pPowerDelay :: Field
902
pPowerDelay =
903
  -- FIXME: we can't use the proper type "NonNegative Double", since
904
  -- the default constant is a plain Double, not a non-negative one.
905
  defaultField [| C.oobPowerDelay |] $
906
  simpleField "power_delay" [t| Double |]
907

    
908
-- | Primary IP address.
909
pPrimaryIp :: Field
910
pPrimaryIp = optionalStringField "primary_ip"
911

    
912
-- | Secondary IP address.
913
pSecondaryIp :: Field
914
pSecondaryIp = optionalNEStringField "secondary_ip"
915

    
916
-- | Whether node is re-added to cluster.
917
pReadd :: Field
918
pReadd = defaultFalse "readd"
919

    
920
-- | Initial node group.
921
pNodeGroup :: Field
922
pNodeGroup = optionalNEStringField "group"
923

    
924
-- | Whether node can become master or master candidate.
925
pMasterCapable :: Field
926
pMasterCapable = optionalField $ booleanField "master_capable"
927

    
928
-- | Whether node can host instances.
929
pVmCapable :: Field
930
pVmCapable = optionalField $ booleanField "vm_capable"
931

    
932
-- | List of names.
933
pNames :: Field
934
pNames = defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
935

    
936
-- | List of node names.
937
pNodes :: Field
938
pNodes = defaultField [| [] |] $ simpleField "nodes" [t| [NonEmptyString] |]
939

    
940
-- | Required list of node names.
941
pRequiredNodes :: Field
942
pRequiredNodes =
943
  renameField "ReqNodes " $ simpleField "nodes" [t| [NonEmptyString] |]
944

    
945
-- | Storage type.
946
pStorageType :: Field
947
pStorageType = simpleField "storage_type" [t| StorageType |]
948

    
949
-- | Storage changes (unchecked).
950
pStorageChanges :: Field
951
pStorageChanges = simpleField "changes" [t| UncheckedDict |]
952

    
953
-- | Whether the node should become a master candidate.
954
pMasterCandidate :: Field
955
pMasterCandidate = optionalField $ booleanField "master_candidate"
956

    
957
-- | Whether the node should be marked as offline.
958
pOffline :: Field
959
pOffline = optionalField $ booleanField "offline"
960

    
961
-- | Whether the node should be marked as drained.
962
pDrained ::Field
963
pDrained = optionalField $ booleanField "drained"
964

    
965
-- | Whether node(s) should be promoted to master candidate if necessary.
966
pAutoPromote :: Field
967
pAutoPromote = defaultFalse "auto_promote"
968

    
969
-- | Whether the node should be marked as powered
970
pPowered :: Field
971
pPowered = optionalField $ booleanField "powered"
972

    
973
-- | Iallocator for deciding the target node for shared-storage
974
-- instances during migrate and failover.
975
pIallocator :: Field
976
pIallocator = optionalNEStringField "iallocator"
977

    
978
-- | New secondary node.
979
pRemoteNode :: Field
980
pRemoteNode = optionalNEStringField "remote_node"
981

    
982
-- | Node evacuation mode.
983
pEvacMode :: Field
984
pEvacMode = renameField "EvacMode" $ simpleField "mode" [t| NodeEvacMode |]
985

    
986
-- | Instance creation mode.
987
pInstCreateMode :: Field
988
pInstCreateMode =
989
  renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]
990

    
991
-- | Do not install the OS (will disable automatic start).
992
pNoInstall :: Field
993
pNoInstall = optionalField $ booleanField "no_install"
994

    
995
-- | OS type for instance installation.
996
pInstOs :: Field
997
pInstOs = optionalNEStringField "os_type"
998

    
999
-- | Primary node for an instance.
1000
pPrimaryNode :: Field
1001
pPrimaryNode = optionalNEStringField "pnode"
1002

    
1003
-- | Secondary node for an instance.
1004
pSecondaryNode :: Field
1005
pSecondaryNode = optionalNEStringField "snode"
1006

    
1007
-- | Signed handshake from source (remote import only).
1008
pSourceHandshake :: Field
1009
pSourceHandshake =
1010
  optionalField $ simpleField "source_handshake" [t| UncheckedList |]
1011

    
1012
-- | Source instance name (remote import only).
1013
pSourceInstance :: Field
1014
pSourceInstance = optionalNEStringField "source_instance_name"
1015

    
1016
-- | How long source instance was given to shut down (remote import only).
1017
-- FIXME: non-negative int, whereas the constant is a plain int.
1018
pSourceShutdownTimeout :: Field
1019
pSourceShutdownTimeout =
1020
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
1021
  simpleField "source_shutdown_timeout" [t| NonNegative Int |]
1022

    
1023
-- | Source X509 CA in PEM format (remote import only).
1024
pSourceX509Ca :: Field
1025
pSourceX509Ca = optionalNEStringField "source_x509_ca"
1026

    
1027
-- | Source node for import.
1028
pSrcNode :: Field
1029
pSrcNode = optionalNEStringField "src_node"
1030

    
1031
-- | Source directory for import.
1032
pSrcPath :: Field
1033
pSrcPath = optionalNEStringField "src_path"
1034

    
1035
-- | Whether to start instance after creation.
1036
pStartInstance :: Field
1037
pStartInstance = defaultTrue "start"
1038

    
1039
-- | Instance tags. FIXME: unify/simplify with pTags, once that
1040
-- migrates to NonEmpty String.
1041
pInstTags :: Field
1042
pInstTags =
1043
  renameField "InstTags" .
1044
  defaultField [| [] |] $
1045
  simpleField "tags" [t| [NonEmptyString] |]
1046

    
1047
-- | Unchecked list of OpInstanceCreate, used in OpInstanceMultiAlloc.
1048
pMultiAllocInstances :: Field
1049
pMultiAllocInstances =
1050
  renameField "InstMultiAlloc" .
1051
  defaultField [| [] |] $
1052
  simpleField "instances"[t| UncheckedList |]
1053

    
1054
-- | Ignore failures parameter.
1055
pIgnoreFailures :: Field
1056
pIgnoreFailures = defaultFalse "ignore_failures"
1057

    
1058
-- | New instance or cluster name.
1059
pNewName :: Field
1060
pNewName = simpleField "new_name" [t| NonEmptyString |]
1061

    
1062
-- | Whether to start the instance even if secondary disks are failing.
1063
pIgnoreSecondaries :: Field
1064
pIgnoreSecondaries = defaultFalse "ignore_secondaries"
1065

    
1066
-- | How to reboot the instance.
1067
pRebootType :: Field
1068
pRebootType = simpleField "reboot_type" [t| RebootType |]
1069

    
1070
-- | Whether to ignore recorded disk size.
1071
pIgnoreDiskSize :: Field
1072
pIgnoreDiskSize = defaultFalse "ignore_size"
1073

    
1074
-- | Disk list for recreate disks.
1075
pRecreateDisksInfo :: Field
1076
pRecreateDisksInfo =
1077
  renameField "RecreateDisksInfo" .
1078
  defaultField [| RecreateDisksAll |] $
1079
  simpleField "disks" [t| RecreateDisksInfo |]
1080

    
1081
-- | Whether to only return configuration data without querying nodes.
1082
pStatic :: Field
1083
pStatic = defaultFalse "static"
1084

    
1085
-- | InstanceSetParams NIC changes.
1086
pInstParamsNicChanges :: Field
1087
pInstParamsNicChanges =
1088
  renameField "InstNicChanges" .
1089
  defaultField [| SetParamsEmpty |] $
1090
  simpleField "nics" [t| SetParamsMods INicParams |]
1091

    
1092
-- | InstanceSetParams Disk changes.
1093
pInstParamsDiskChanges :: Field
1094
pInstParamsDiskChanges =
1095
  renameField "InstDiskChanges" .
1096
  defaultField [| SetParamsEmpty |] $
1097
  simpleField "disks" [t| SetParamsMods IDiskParams |]
1098

    
1099
-- | New runtime memory.
1100
pRuntimeMem :: Field
1101
pRuntimeMem = optionalField $ simpleField "runtime_mem" [t| Positive Int |]
1102

    
1103
-- | Change the instance's OS without reinstalling the instance
1104
pOsNameChange :: Field
1105
pOsNameChange = optionalNEStringField "os_name"
1106

    
1107
-- | Disk index for e.g. grow disk.
1108
pDiskIndex :: Field
1109
pDiskIndex = renameField "DiskIndex " $ simpleField "disk" [t| DiskIndex |]
1110

    
1111
-- | Disk amount to add or grow to.
1112
pDiskChgAmount :: Field
1113
pDiskChgAmount =
1114
  renameField "DiskChgAmount" $ simpleField "amount" [t| NonNegative Int |]
1115

    
1116
-- | Whether the amount parameter is an absolute target or a relative one.
1117
pDiskChgAbsolute :: Field
1118
pDiskChgAbsolute = renameField "DiskChkAbsolute" $ defaultFalse "absolute"
1119

    
1120
-- | Destination group names or UUIDs (defaults to \"all but current group\".
1121
pTargetGroups :: Field
1122
pTargetGroups =
1123
  optionalField $ simpleField "target_groups" [t| [NonEmptyString] |]
1124

    
1125
-- | Export mode field.
1126
pExportMode :: Field
1127
pExportMode =
1128
  renameField "ExportMode" $ simpleField "mode" [t| ExportMode |]
1129

    
1130
-- | Export target_node field, depends on mode.
1131
pExportTargetNode :: Field
1132
pExportTargetNode =
1133
  renameField "ExportTarget" $
1134
  simpleField "target_node" [t| ExportTarget |]
1135

    
1136
-- | Whether to remove instance after export.
1137
pRemoveInstance :: Field
1138
pRemoveInstance = defaultFalse "remove_instance"
1139

    
1140
-- | Whether to ignore failures while removing instances.
1141
pIgnoreRemoveFailures :: Field
1142
pIgnoreRemoveFailures = defaultFalse "ignore_remove_failures"
1143

    
1144
-- | Name of X509 key (remote export only).
1145
pX509KeyName :: Field
1146
pX509KeyName = optionalField $ simpleField "x509_key_name" [t| UncheckedList |]
1147

    
1148
-- | Destination X509 CA (remote export only).
1149
pX509DestCA :: Field
1150
pX509DestCA = optionalNEStringField "destination_x509_ca"
1151

    
1152
-- | Search pattern (regular expression). FIXME: this should be
1153
-- compiled at load time?
1154
pTagSearchPattern :: Field
1155
pTagSearchPattern =
1156
  renameField "TagSearchPattern" $ simpleField "pattern" [t| NonEmptyString |]
1157

    
1158
-- | Restricted command name.
1159
pRestrictedCommand :: Field
1160
pRestrictedCommand =
1161
  renameField "RestrictedCommand" $
1162
  simpleField "command" [t| NonEmptyString |]
1163

    
1164
-- * Test opcode parameters
1165

    
1166
-- | Repeat parameter for OpTestDelay.
1167
pDelayRepeat :: Field
1168
pDelayRepeat =
1169
  renameField "DelayRepeat" .
1170
  defaultField [| forceNonNeg (0::Int) |] $
1171
  simpleField "repeat" [t| NonNegative Int |]
1172

    
1173
-- | IAllocator test direction.
1174
pIAllocatorDirection :: Field
1175
pIAllocatorDirection =
1176
  renameField "IAllocatorDirection" $
1177
  simpleField "direction" [t| IAllocatorTestDir |]
1178

    
1179
-- | IAllocator test mode.
1180
pIAllocatorMode :: Field
1181
pIAllocatorMode =
1182
  renameField "IAllocatorMode" $
1183
  simpleField "mode" [t| IAllocatorMode |]
1184

    
1185
-- | IAllocator target name (new instance, node to evac, etc.).
1186
pIAllocatorReqName :: Field
1187
pIAllocatorReqName =
1188
  renameField "IAllocatorReqName" $ simpleField "name" [t| NonEmptyString |]
1189

    
1190
-- | Custom OpTestIAllocator nics.
1191
pIAllocatorNics :: Field
1192
pIAllocatorNics =
1193
  renameField "IAllocatorNics" $ simpleField "nics" [t| [UncheckedDict] |]
1194

    
1195
-- | Custom OpTestAllocator disks.
1196
pIAllocatorDisks :: Field
1197
pIAllocatorDisks =
1198
  renameField "IAllocatorDisks" $ simpleField "disks" [t| UncheckedList |]
1199

    
1200
-- | IAllocator memory field.
1201
pIAllocatorMemory :: Field
1202
pIAllocatorMemory =
1203
  renameField "IAllocatorMem" .
1204
  optionalField $
1205
  simpleField "memory" [t| NonNegative Int |]
1206

    
1207
-- | IAllocator vcpus field.
1208
pIAllocatorVCpus :: Field
1209
pIAllocatorVCpus =
1210
  renameField "IAllocatorVCpus" .
1211
  optionalField $
1212
  simpleField "vcpus" [t| NonNegative Int |]
1213

    
1214
-- | IAllocator os field.
1215
pIAllocatorOs :: Field
1216
pIAllocatorOs = renameField "IAllocatorOs" $ optionalNEStringField "os"
1217

    
1218
-- | IAllocator instances field.
1219
pIAllocatorInstances :: Field
1220
pIAllocatorInstances =
1221
  renameField "IAllocatorInstances " .
1222
  optionalField $
1223
  simpleField "instances" [t| [NonEmptyString] |]
1224

    
1225
-- | IAllocator evac mode.
1226
pIAllocatorEvacMode :: Field
1227
pIAllocatorEvacMode =
1228
  renameField "IAllocatorEvacMode" .
1229
  optionalField $
1230
  simpleField "evac_mode" [t| NodeEvacMode |]
1231

    
1232
-- | IAllocator spindle use.
1233
pIAllocatorSpindleUse :: Field
1234
pIAllocatorSpindleUse =
1235
  renameField "IAllocatorSpindleUse" .
1236
  defaultField [| forceNonNeg (1::Int) |] $
1237
  simpleField "spindle_use" [t| NonNegative Int |]
1238

    
1239
-- | IAllocator count field.
1240
pIAllocatorCount :: Field
1241
pIAllocatorCount =
1242
  renameField "IAllocatorCount" .
1243
  defaultField [| forceNonNeg (1::Int) |] $
1244
  simpleField "count" [t| NonNegative Int |]
1245

    
1246
-- | 'OpTestJqueue' notify_waitlock.
1247
pJQueueNotifyWaitLock :: Field
1248
pJQueueNotifyWaitLock = defaultFalse "notify_waitlock"
1249

    
1250
-- | 'OpTestJQueue' notify_exec.
1251
pJQueueNotifyExec :: Field
1252
pJQueueNotifyExec = defaultFalse "notify_exec"
1253

    
1254
-- | 'OpTestJQueue' log_messages.
1255
pJQueueLogMessages :: Field
1256
pJQueueLogMessages =
1257
  defaultField [| [] |] $ simpleField "log_messages" [t| [String] |]
1258

    
1259
-- | 'OpTestJQueue' fail attribute.
1260
pJQueueFail :: Field
1261
pJQueueFail =
1262
  renameField "JQueueFail" $ defaultFalse "fail"
1263

    
1264
-- | 'OpTestDummy' result field.
1265
pTestDummyResult :: Field
1266
pTestDummyResult =
1267
  renameField "TestDummyResult" $ simpleField "result" [t| UncheckedValue |]
1268

    
1269
-- | 'OpTestDummy' messages field.
1270
pTestDummyMessages :: Field
1271
pTestDummyMessages =
1272
  renameField "TestDummyMessages" $
1273
  simpleField "messages" [t| UncheckedValue |]
1274

    
1275
-- | 'OpTestDummy' fail field.
1276
pTestDummyFail :: Field
1277
pTestDummyFail =
1278
  renameField "TestDummyFail" $ simpleField "fail" [t| UncheckedValue |]
1279

    
1280
-- | 'OpTestDummy' submit_jobs field.
1281
pTestDummySubmitJobs :: Field
1282
pTestDummySubmitJobs =
1283
  renameField "TestDummySubmitJobs" $
1284
  simpleField "submit_jobs" [t| UncheckedValue |]
1285

    
1286
-- * Network parameters
1287

    
1288
-- | Network name.
1289
pNetworkName :: Field
1290
pNetworkName = simpleField "network_name" [t| NonEmptyString |]
1291

    
1292
-- | Network type field.
1293
pNetworkType :: Field
1294
pNetworkType = optionalField $ simpleField "network_type" [t| NetworkType |]
1295

    
1296
-- | Network address (IPv4 subnet). FIXME: no real type for this.
1297
pNetworkAddress4 :: Field
1298
pNetworkAddress4 =
1299
  renameField "NetworkAddress4" $
1300
  simpleField "network" [t| NonEmptyString |]
1301

    
1302
-- | Network gateway (IPv4 address). FIXME: no real type for this.
1303
pNetworkGateway4 :: Field
1304
pNetworkGateway4 =
1305
  renameField "NetworkGateway4" $
1306
  optionalNEStringField "gateway"
1307

    
1308
-- | Network address (IPv6 subnet). FIXME: no real type for this.
1309
pNetworkAddress6 :: Field
1310
pNetworkAddress6 =
1311
  renameField "NetworkAddress6" $
1312
  optionalNEStringField "network6"
1313

    
1314
-- | Network gateway (IPv6 address). FIXME: no real type for this.
1315
pNetworkGateway6 :: Field
1316
pNetworkGateway6 =
1317
  renameField "NetworkGateway6" $
1318
  optionalNEStringField "gateway6"
1319

    
1320
-- | Network specific mac prefix (that overrides the cluster one).
1321
pNetworkMacPrefix :: Field
1322
pNetworkMacPrefix =
1323
  renameField "NetMacPrefix" $
1324
  optionalNEStringField "mac_prefix"
1325

    
1326
-- | Network add reserved IPs.
1327
pNetworkAddRsvdIps :: Field
1328
pNetworkAddRsvdIps =
1329
  renameField "NetworkAddRsvdIps" .
1330
  optionalField $
1331
  simpleField "add_reserved_ips" [t| [NonEmptyString] |]
1332

    
1333
-- | Network remove reserved IPs.
1334
pNetworkRemoveRsvdIps :: Field
1335
pNetworkRemoveRsvdIps =
1336
  renameField "NetworkRemoveRsvdIps" .
1337
  optionalField $
1338
  simpleField "remove_reserved_ips" [t| [NonEmptyString] |]
1339

    
1340
-- | Network mode when connecting to a group.
1341
pNetworkMode :: Field
1342
pNetworkMode = simpleField "network_mode" [t| NICMode |]
1343

    
1344
-- | Network link when connecting to a group.
1345
pNetworkLink :: Field
1346
pNetworkLink = simpleField "network_link" [t| NonEmptyString |]
1347

    
1348
-- * Entire opcode parameter list
1349

    
1350
-- | Old-style query opcode, with locking.
1351
dOldQuery :: [Field]
1352
dOldQuery =
1353
  [ pOutputFields
1354
  , pNames
1355
  , pUseLocking
1356
  ]
1357

    
1358
-- | Old-style query opcode, without locking.
1359
dOldQueryNoLocking :: [Field]
1360
dOldQueryNoLocking =
1361
  [ pOutputFields
1362
  , pNames
1363
  ]