OpParams.hs 43.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{-# LANGUAGE TemplateHaskell #-}

{-| Implementation of opcodes parameters.

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

-}

{-

Copyright (C) 2012 Google Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.

-}

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

246
import Control.Monad (liftM)
Iustin Pop's avatar
Iustin Pop committed
247
248
import qualified Data.Set as Set
import Text.JSON (readJSON, showJSON, JSON, JSValue(..), fromJSString,
249
                  JSObject, toJSObject)
250
import qualified Text.JSON
251
252
import Text.JSON.Pretty (pp_value)

253
import Ganeti.BasicTypes
254
255
256
import qualified Ganeti.Constants as C
import Ganeti.THH
import Ganeti.JSON
Iustin Pop's avatar
Iustin Pop committed
257
258
import Ganeti.Types
import qualified Ganeti.Query.Language as Qlang
259
260
261

-- * Helper functions and types

Iustin Pop's avatar
Iustin Pop committed
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
-- * Type aliases

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

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

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

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

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

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

Iustin Pop's avatar
Iustin Pop committed
288
289
-- | Unchecked value, should be replaced by a better definition.
type UncheckedValue = JSValue
Iustin Pop's avatar
Iustin Pop committed
290
291
292
293

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

294
295
296
297
298
299
300
301
302
303
304
305
-- | Unchecked list, shoild be replaced by a better definition.
type UncheckedList = [JSValue]

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

306
307
308
309
310
311
312
313
-- ** Tags

-- | Data type representing what items do the tag operations apply to.
$(declareSADT "TagType"
  [ ("TagTypeInstance", 'C.tagInstance)
  , ("TagTypeNode",     'C.tagNode)
  , ("TagTypeGroup",    'C.tagNodegroup)
  , ("TagTypeCluster",  'C.tagCluster)
314
  , ("TagTypeNetwork",  'C.tagNetwork)
315
316
317
318
319
320
321
  ])
$(makeJSONInstance ''TagType)

-- | Data type holding a tag object (type and object name).
data TagObject = TagInstance String
               | TagNode     String
               | TagGroup    String
322
               | TagNetwork  String
323
               | TagCluster
324
               deriving (Show, Eq)
325
326
327
328
329
330
331

-- | Tag type for a given tag object.
tagTypeOf :: TagObject -> TagType
tagTypeOf (TagInstance {}) = TagTypeInstance
tagTypeOf (TagNode     {}) = TagTypeNode
tagTypeOf (TagGroup    {}) = TagTypeGroup
tagTypeOf (TagCluster  {}) = TagTypeCluster
332
tagTypeOf (TagNetwork  {}) = TagTypeNetwork
333
334
335
336
337
338

-- | Gets the potential tag object name.
tagNameOf :: TagObject -> Maybe String
tagNameOf (TagInstance s) = Just s
tagNameOf (TagNode     s) = Just s
tagNameOf (TagGroup    s) = Just s
339
tagNameOf (TagNetwork  s) = Just s
340
341
342
343
344
345
346
347
tagNameOf  TagCluster     = Nothing

-- | Builds a 'TagObject' from a tag type and name.
tagObjectFrom :: (Monad m) => TagType -> JSValue -> m TagObject
tagObjectFrom TagTypeInstance (JSString s) =
  return . TagInstance $ fromJSString s
tagObjectFrom TagTypeNode     (JSString s) = return . TagNode $ fromJSString s
tagObjectFrom TagTypeGroup    (JSString s) = return . TagGroup $ fromJSString s
348
349
tagObjectFrom TagTypeNetwork  (JSString s) =
  return . TagNetwork $ fromJSString s
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
tagObjectFrom TagTypeCluster   JSNull      = return TagCluster
tagObjectFrom t v =
  fail $ "Invalid tag type/name combination: " ++ show t ++ "/" ++
         show (pp_value v)

-- | Name of the tag \"name\" field.
tagNameField :: String
tagNameField = "name"

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

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

-- ** Disks

-- | Replace disks type.
$(declareSADT "ReplaceDisksMode"
  [ ("ReplaceOnPrimary",    'C.replaceDiskPri)
  , ("ReplaceOnSecondary",  'C.replaceDiskSec)
  , ("ReplaceNewSecondary", 'C.replaceDiskChg)
  , ("ReplaceAuto",         'C.replaceDiskAuto)
  ])
$(makeJSONInstance ''ReplaceDisksMode)

-- | Disk index type (embedding constraints on the index value via a
-- smart constructor).
newtype DiskIndex = DiskIndex { unDiskIndex :: Int }
385
  deriving (Show, Eq, Ord)
386
387
388
389
390
391
392
393
394
395
396
397

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

instance JSON DiskIndex where
  readJSON v = readJSON v >>= mkDiskIndex
  showJSON = showJSON . unDiskIndex

Iustin Pop's avatar
Iustin Pop committed
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
-- ** I* param types

-- | Type holding disk access modes.
$(declareSADT "DiskAccess"
  [ ("DiskReadOnly",  'C.diskRdonly)
  , ("DiskReadWrite", 'C.diskRdwr)
  ])
$(makeJSONInstance ''DiskAccess)

-- | NIC modification definition.
$(buildObject "INicParams" "inic"
  [ optionalField $ simpleField C.inicMac  [t| NonEmptyString |]
  , optionalField $ simpleField C.inicIp   [t| String         |]
  , optionalField $ simpleField C.inicMode [t| NonEmptyString |]
  , optionalField $ simpleField C.inicLink [t| NonEmptyString |]
413
  , optionalField $ simpleField C.inicName [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
414
415
  ])

416
-- | Disk modification definition. FIXME: disksize should be VTYPE_UNIT.
Iustin Pop's avatar
Iustin Pop committed
417
$(buildObject "IDiskParams" "idisk"
418
419
420
421
422
  [ optionalField $ simpleField C.idiskSize   [t| Int            |]
  , optionalField $ simpleField C.idiskMode   [t| DiskAccess     |]
  , optionalField $ simpleField C.idiskAdopt  [t| NonEmptyString |]
  , optionalField $ simpleField C.idiskVg     [t| NonEmptyString |]
  , optionalField $ simpleField C.idiskMetavg [t| NonEmptyString |]
423
  , optionalField $ simpleField C.idiskName   [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
424
425
  ])

426
427
428
429
430
431
432
433
434
-- | Disk changes type for OpInstanceRecreateDisks. This is a bit
-- strange, because the type in Python is something like Either
-- [DiskIndex] [DiskChanges], but we can't represent the type of an
-- empty list in JSON, so we have to add a custom case for the empty
-- list.
data RecreateDisksInfo
  = RecreateDisksAll
  | RecreateDisksIndices (NonEmpty DiskIndex)
  | RecreateDisksParams (NonEmpty (DiskIndex, IDiskParams))
435
    deriving (Eq, Show)
436
437
438
439
440
441
442
443
444

readRecreateDisks :: JSValue -> Text.JSON.Result RecreateDisksInfo
readRecreateDisks (JSArray []) = return RecreateDisksAll
readRecreateDisks v =
  case readJSON v::Text.JSON.Result [DiskIndex] of
    Text.JSON.Ok indices -> liftM RecreateDisksIndices (mkNonEmpty indices)
    _ -> case readJSON v::Text.JSON.Result [(DiskIndex, IDiskParams)] of
           Text.JSON.Ok params -> liftM RecreateDisksParams (mkNonEmpty params)
           _ -> fail $ "Can't parse disk information as either list of disk"
445
                ++ " indices or list of disk parameters; value received:"
446
447
448
449
450
451
452
453
454
455
456
                ++ show (pp_value v)

instance JSON RecreateDisksInfo where
  readJSON = readRecreateDisks
  showJSON  RecreateDisksAll            = showJSON ()
  showJSON (RecreateDisksIndices idx)   = showJSON idx
  showJSON (RecreateDisksParams params) = showJSON params

-- | Simple type for old-style ddm changes.
data DdmOldChanges = DdmOldIndex (NonNegative Int)
                   | DdmOldMod DdmSimple
457
                     deriving (Eq, Show)
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477

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

instance JSON DdmOldChanges where
  showJSON (DdmOldIndex i) = showJSON i
  showJSON (DdmOldMod m)   = showJSON m
  readJSON = readDdmOldChanges

-- | Instance disk or nic modifications.
data SetParamsMods a
  = SetParamsEmpty
  | SetParamsDeprecated (NonEmpty (DdmOldChanges, a))
  | SetParamsNew (NonEmpty (DdmFull, Int, a))
478
    deriving (Eq, Show)
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493

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

instance (JSON a) => JSON (SetParamsMods a) where
  showJSON SetParamsEmpty = showJSON ()
  showJSON (SetParamsDeprecated v) = showJSON v
  showJSON (SetParamsNew v) = showJSON v
  readJSON = readSetParams

Iustin Pop's avatar
Iustin Pop committed
494
495
496
497
498
499
-- | Custom type for target_node parameter of OpBackupExport, which
-- varies depending on mode. FIXME: this uses an UncheckedList since
-- we don't care about individual rows (just like the Python code
-- tests). But the proper type could be parsed if we wanted.
data ExportTarget = ExportTargetLocal NonEmptyString
                  | ExportTargetRemote UncheckedList
500
                    deriving (Eq, Show)
Iustin Pop's avatar
Iustin Pop committed
501
502
503
504
505
506
507
508
509
510
511
512
513
514

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

instance JSON ExportTarget where
  showJSON (ExportTargetLocal s)  = showJSON s
  showJSON (ExportTargetRemote l) = showJSON l
  readJSON = readExportTarget

515
516
-- * Parameters

Iustin Pop's avatar
Iustin Pop committed
517
-- | A required instance name (for single-instance LUs).
518
519
520
pInstanceName :: Field
pInstanceName = simpleField "instance_name" [t| String |]

Iustin Pop's avatar
Iustin Pop committed
521
522
523
524
525
526
527
528
529
-- | A list of instances.
pInstances :: Field
pInstances = defaultField [| [] |] $
             simpleField "instances" [t| [NonEmptyString] |]

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

530
531
532
533
534
535
-- | Tags list.
pTagsList :: Field
pTagsList = simpleField "tags" [t| [String] |]

-- | Tags object.
pTagsObject :: Field
Iustin Pop's avatar
Iustin Pop committed
536
537
538
pTagsObject =
  customField 'decodeTagObject 'encodeTagObject [tagNameField] $
  simpleField "kind" [t| TagObject |]
Iustin Pop's avatar
Iustin Pop committed
539
540
541
542
543
544
545

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

-- | How long to wait for instance to shut down.
pShutdownTimeout :: Field
546
pShutdownTimeout = defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
Iustin Pop's avatar
Iustin Pop committed
547
548
                   simpleField "shutdown_timeout" [t| NonNegative Int |]

549
550
551
552
553
554
555
556
-- | Another name for the shutdown timeout, because we like to be
-- inconsistent.
pShutdownTimeout' :: Field
pShutdownTimeout' =
  renameField "InstShutdownTimeout" .
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
  simpleField "timeout" [t| NonNegative Int |]

557
558
559
560
-- | Whether to shutdown the instance in backup-export.
pShutdownInstance :: Field
pShutdownInstance = defaultTrue "shutdown"

Iustin Pop's avatar
Iustin Pop committed
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
-- | Whether to force the operation.
pForce :: Field
pForce = defaultFalse "force"

-- | Whether to ignore offline nodes.
pIgnoreOfflineNodes :: Field
pIgnoreOfflineNodes = defaultFalse "ignore_offline_nodes"

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

-- | List of nodes.
pNodeNames :: Field
pNodeNames =
  defaultField [| [] |] $ simpleField "node_names" [t| [NonEmptyString] |]

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

-- | Migration type (live\/non-live).
pMigrationMode :: Field
pMigrationMode =
Iustin Pop's avatar
Iustin Pop committed
585
  renameField "MigrationMode" .
Iustin Pop's avatar
Iustin Pop committed
586
587
588
589
590
591
  optionalField $
  simpleField "mode" [t| MigrationMode |]

-- | Obsolete \'live\' migration mode (boolean).
pMigrationLive :: Field
pMigrationLive =
Iustin Pop's avatar
Iustin Pop committed
592
  renameField "OldLiveMode" . optionalField $ booleanField "live"
Iustin Pop's avatar
Iustin Pop committed
593

594
595
596
597
-- | Migration cleanup parameter.
pMigrationCleanup :: Field
pMigrationCleanup = renameField "MigrationCleanup" $ defaultFalse "cleanup"

Iustin Pop's avatar
Iustin Pop committed
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
-- | Whether to force an unknown OS variant.
pForceVariant :: Field
pForceVariant = defaultFalse "force_variant"

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

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

-- | Whether to ignore disk consistency
pIgnoreConsistency :: Field
pIgnoreConsistency = defaultFalse "ignore_consistency"

-- | Storage name.
pStorageName :: Field
pStorageName =
  renameField "StorageName" $ simpleField "name" [t| NonEmptyString |]

-- | Whether to use synchronization.
pUseLocking :: Field
pUseLocking = defaultFalse "use_locking"

623
624
625
626
627
628
-- | Whether to employ opportunistic locking for nodes, meaning nodes already
-- locked by another opcode won't be considered for instance allocation (only
-- when an iallocator is used).
pOpportunisticLocking :: Field
pOpportunisticLocking = defaultFalse "opportunistic_locking"

Iustin Pop's avatar
Iustin Pop committed
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
-- | Whether to check name.
pNameCheck :: Field
pNameCheck = defaultTrue "name_check"

-- | Instance allocation policy.
pNodeGroupAllocPolicy :: Field
pNodeGroupAllocPolicy = optionalField $
                        simpleField "alloc_policy" [t| AllocPolicy |]

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

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

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

650
651
652
653
654
655
656
-- | Whether to ensure instance's IP address is inactive.
pIpCheck :: Field
pIpCheck = defaultTrue "ip_check"

-- | Check for conflicting IPs.
pIpConflictsCheck :: Field
pIpConflictsCheck = defaultTrue "conflicts_check"
Iustin Pop's avatar
Iustin Pop committed
657
658
659
660
661
662
663
664
665

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

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

666
667
668
669
670
671
-- | Target node for instance move (required).
pMoveTargetNode :: Field
pMoveTargetNode =
  renameField "MoveTargetNode" $
  simpleField "target_node" [t| NonEmptyString |]

Iustin Pop's avatar
Iustin Pop committed
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
-- | Pause instance at startup.
pStartupPaused :: Field
pStartupPaused = defaultFalse "startup_paused"

-- | Verbose mode.
pVerbose :: Field
pVerbose = defaultFalse "verbose"

-- ** Parameters for cluster verification

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

-- | Error codes.
pErrorCodes :: Field
pErrorCodes = defaultFalse "error_codes"

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

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

-- | Optional group name.
pOptGroupName :: Field
Iustin Pop's avatar
Iustin Pop committed
702
pOptGroupName = renameField "OptGroupName" .
Iustin Pop's avatar
Iustin Pop committed
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
                optionalField $ simpleField "group_name" [t| NonEmptyString |]

-- | Disk templates' parameter defaults.
pDiskParams :: Field
pDiskParams = optionalField $
              simpleField "diskparams" [t| GenericContainer DiskTemplate
                                           UncheckedDict |]

-- * Parameters for node resource model

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

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

-- | Whether to ignore ipolicy violations.
pIgnoreIpolicy :: Field
pIgnoreIpolicy = defaultFalse "ignore_ipolicy"

-- | Allow runtime changes while migrating.
pAllowRuntimeChgs :: Field
pAllowRuntimeChgs = defaultTrue "allow_runtime_changes"

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

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

-- Utility type for NIC definitions.
--type TestNicDef = INicParams
737
738
739
740
741
742
743
744
745

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

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

746
747
748
749
750
751
752
-- | Instance disk template.
pOptDiskTemplate :: Field
pOptDiskTemplate =
  optionalField .
  renameField "OptDiskTemplate" $
  simpleField "disk_template" [t| DiskTemplate |]

753
754
755
756
757
758
759
-- | File driver.
pFileDriver :: Field
pFileDriver = optionalField $ simpleField "file_driver" [t| FileDriver |]

-- | Directory for storing file-backed disks.
pFileStorageDir :: Field
pFileStorageDir = optionalNEStringField "file_storage_dir"
Iustin Pop's avatar
Iustin Pop committed
760
761
762
763
764
765
766
767
768
769
770

-- | Volume group name.
pVgName :: Field
pVgName = optionalStringField "vg_name"

-- | List of enabled hypervisors.
pEnabledHypervisors :: Field
pEnabledHypervisors =
  optionalField $
  simpleField "enabled_hypervisors" [t| NonEmpty Hypervisor |]

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

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

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

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

Iustin Pop's avatar
Iustin Pop committed
797
798
-- | Cluster-wide beparams.
pClusterBeParams :: Field
799
800
801
802
803
804
805
806
807
808
809
810
811
812
pClusterBeParams =
  renameField "ClusterBeParams" .
  optionalField $ simpleField "beparams" [t| UncheckedDict |]

-- | Instance beparams.
pInstBeParams :: Field
pInstBeParams =
  renameField "InstBeParams" .
  defaultField [| toJSObject [] |] $
  simpleField "beparams" [t| UncheckedDict |]

-- | Reset instance parameters to default if equal.
pResetDefaults :: Field
pResetDefaults = defaultFalse "identify_defaults"
Iustin Pop's avatar
Iustin Pop committed
813
814
815
816
817
818

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

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

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

830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
-- | Temporary OS parameters (currently only in reinstall, might be
-- added to install as well).
pTempOsParams :: Field
pTempOsParams =
  renameField "TempOsParams" .
  optionalField $ simpleField "osparams" [t| UncheckedDict |]

-- | Temporary hypervisor parameters, hypervisor-dependent.
pTempHvParams :: Field
pTempHvParams =
  renameField "TempHvParams" .
  defaultField [| toJSObject [] |] $
  simpleField "hvparams" [t| UncheckedDict |]

-- | Temporary backend parameters.
pTempBeParams :: Field
pTempBeParams =
  renameField "TempBeParams" .
  defaultField [| toJSObject [] |] $
  simpleField "beparams" [t| UncheckedDict |]

Iustin Pop's avatar
Iustin Pop committed
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
-- | Candidate pool size.
pCandidatePoolSize :: Field
pCandidatePoolSize =
  optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]

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

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

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

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

875
876
877
878
-- | Whether to modify and keep in sync the @/etc/hosts@ files of nodes.
pModifyEtcHosts :: Field
pModifyEtcHosts = optionalField $ booleanField "modify_etc_hosts"

Iustin Pop's avatar
Iustin Pop committed
879
880
881
882
883
884
885
886
-- | Whether to wipe disks before allocating them to instances.
pPreallocWipeDisks :: Field
pPreallocWipeDisks = optionalField $ booleanField "prealloc_wipe_disks"

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

887
888
889
890
-- | Instance NIC definitions.
pInstNics :: Field
pInstNics = simpleField "nics" [t| [INicParams] |]

Iustin Pop's avatar
Iustin Pop committed
891
892
893
894
-- | Cluster-wide node parameter defaults.
pNdParams :: Field
pNdParams = optionalField $ simpleField "ndparams" [t| UncheckedDict |]

Iustin Pop's avatar
Iustin Pop committed
895
-- | Cluster-wide ipolicy specs.
Iustin Pop's avatar
Iustin Pop committed
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
pIpolicy :: Field
pIpolicy = optionalField $ simpleField "ipolicy" [t| UncheckedDict |]

-- | DRBD helper program.
pDrbdHelper :: Field
pDrbdHelper = optionalStringField "drbd_helper"

-- | Default iallocator for cluster.
pDefaultIAllocator :: Field
pDefaultIAllocator = optionalStringField "default_iallocator"

-- | Master network device.
pMasterNetdev :: Field
pMasterNetdev = optionalStringField "master_netdev"

-- | Netmask of the master IP.
pMasterNetmask :: Field
913
914
pMasterNetmask =
  optionalField $ simpleField "master_netmask" [t| NonNegative Int |]
Iustin Pop's avatar
Iustin Pop committed
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998

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

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

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

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

-- | Requested fields.
pQueryFields :: Field
pQueryFields = simpleField "fields" [t| [NonEmptyString] |]

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

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

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

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

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

-- | Primary IP address.
pPrimaryIp :: Field
pPrimaryIp = optionalStringField "primary_ip"

-- | Secondary IP address.
pSecondaryIp :: Field
pSecondaryIp = optionalNEStringField "secondary_ip"

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

-- | Initial node group.
pNodeGroup :: Field
pNodeGroup = optionalNEStringField "group"

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

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

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

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

Iustin Pop's avatar
Iustin Pop committed
999
1000
1001
1002
1003
-- | Required list of node names.
pRequiredNodes :: Field
pRequiredNodes =
  renameField "ReqNodes " $ simpleField "nodes" [t| [NonEmptyString] |]

Iustin Pop's avatar
Iustin Pop committed
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
-- | Storage type.
pStorageType :: Field
pStorageType = simpleField "storage_type" [t| StorageType |]

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

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

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

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

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

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

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

-- | New secondary node.
pRemoteNode :: Field
pRemoteNode = optionalNEStringField "remote_node"

-- | Node evacuation mode.
pEvacMode :: Field
pEvacMode = renameField "EvacMode" $ simpleField "mode" [t| NodeEvacMode |]
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104

-- | Instance creation mode.
pInstCreateMode :: Field
pInstCreateMode =
  renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]

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

-- | OS type for instance installation.
pInstOs :: Field
pInstOs = optionalNEStringField "os_type"

-- | Primary node for an instance.
pPrimaryNode :: Field
pPrimaryNode = optionalNEStringField "pnode"

-- | Secondary node for an instance.
pSecondaryNode :: Field
pSecondaryNode = optionalNEStringField "snode"

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

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

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

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

-- | Source node for import.
pSrcNode :: Field
pSrcNode = optionalNEStringField "src_node"

-- | Source directory for import.
pSrcPath :: Field
pSrcPath = optionalNEStringField "src_path"

-- | Whether to start instance after creation.
pStartInstance :: Field
pStartInstance = defaultTrue "start"

-- | Instance tags. FIXME: unify/simplify with pTags, once that
-- migrates to NonEmpty String.
pInstTags :: Field
pInstTags =
  renameField "InstTags" .
  defaultField [| [] |] $
  simpleField "tags" [t| [NonEmptyString] |]
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182

-- | Unchecked list of OpInstanceCreate, used in OpInstanceMultiAlloc.
pMultiAllocInstances :: Field
pMultiAllocInstances =
  renameField "InstMultiAlloc" .
  defaultField [| [] |] $
  simpleField "instances"[t| UncheckedList |]

-- | Ignore failures parameter.
pIgnoreFailures :: Field
pIgnoreFailures = defaultFalse "ignore_failures"

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

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

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

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

-- | Disk list for recreate disks.
pRecreateDisksInfo :: Field
pRecreateDisksInfo =
  renameField "RecreateDisksInfo" .
  defaultField [| RecreateDisksAll |] $
  simpleField "disks" [t| RecreateDisksInfo |]

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

-- | InstanceSetParams NIC changes.
pInstParamsNicChanges :: Field
pInstParamsNicChanges =
  renameField "InstNicChanges" .
  defaultField [| SetParamsEmpty |] $
  simpleField "nics" [t| SetParamsMods INicParams |]

-- | InstanceSetParams Disk changes.
pInstParamsDiskChanges :: Field
pInstParamsDiskChanges =
  renameField "InstDiskChanges" .
  defaultField [| SetParamsEmpty |] $
  simpleField "disks" [t| SetParamsMods IDiskParams |]

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

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

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

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

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

-- | Destination group names or UUIDs (defaults to \"all but current group\".
pTargetGroups :: Field
pTargetGroups =
  optionalField $ simpleField "target_groups" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209

-- | Export mode field.
pExportMode :: Field
pExportMode =
  renameField "ExportMode" $ simpleField "mode" [t| ExportMode |]

-- | Export target_node field, depends on mode.
pExportTargetNode :: Field
pExportTargetNode =
  renameField "ExportTarget" $
  simpleField "target_node" [t| ExportTarget |]

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

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

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

-- | Destination X509 CA (remote export only).
pX509DestCA :: Field
pX509DestCA = optionalNEStringField "destination_x509_ca"
1210
1211
1212
1213
1214
1215
1216

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

Iustin Pop's avatar
Iustin Pop committed
1217
1218
1219
1220
1221
1222
-- | Restricted command name.
pRestrictedCommand :: Field
pRestrictedCommand =
  renameField "RestrictedCommand" $
  simpleField "command" [t| NonEmptyString |]

1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
-- | Replace disks mode.
pReplaceDisksMode :: Field
pReplaceDisksMode =
  renameField "ReplaceDisksMode" $ simpleField "mode" [t| ReplaceDisksMode |]

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

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

Iustin Pop's avatar
Iustin Pop committed
1237
1238
-- * Test opcode parameters

1239
1240
1241
-- | Duration parameter for 'OpTestDelay'.
pDelayDuration :: Field
pDelayDuration =
1242
  renameField "DelayDuration" $ simpleField "duration" [t| Double |]
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254

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

-- | on_nodes field for 'OpTestDelay'.
pDelayOnNodes :: Field
pDelayOnNodes =
  renameField "DelayOnNodes" .
  defaultField [| [] |] $
  simpleField "on_nodes" [t| [NonEmptyString] |]

1255
1256
1257
1258
1259
1260
-- | Repeat parameter for OpTestDelay.
pDelayRepeat :: Field
pDelayRepeat =
  renameField "DelayRepeat" .
  defaultField [| forceNonNeg (0::Int) |] $
  simpleField "repeat" [t| NonNegative Int |]
Iustin Pop's avatar
Iustin Pop committed
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373

-- | IAllocator test direction.
pIAllocatorDirection :: Field
pIAllocatorDirection =
  renameField "IAllocatorDirection" $
  simpleField "direction" [t| IAllocatorTestDir |]

-- | IAllocator test mode.
pIAllocatorMode :: Field
pIAllocatorMode =
  renameField "IAllocatorMode" $
  simpleField "mode" [t| IAllocatorMode |]

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

-- | Custom OpTestIAllocator nics.
pIAllocatorNics :: Field
pIAllocatorNics =
  renameField "IAllocatorNics" $ simpleField "nics" [t| [UncheckedDict] |]

-- | Custom OpTestAllocator disks.
pIAllocatorDisks :: Field
pIAllocatorDisks =
  renameField "IAllocatorDisks" $ simpleField "disks" [t| UncheckedList |]

-- | IAllocator memory field.
pIAllocatorMemory :: Field
pIAllocatorMemory =
  renameField "IAllocatorMem" .
  optionalField $
  simpleField "memory" [t| NonNegative Int |]

-- | IAllocator vcpus field.
pIAllocatorVCpus :: Field
pIAllocatorVCpus =
  renameField "IAllocatorVCpus" .
  optionalField $
  simpleField "vcpus" [t| NonNegative Int |]

-- | IAllocator os field.
pIAllocatorOs :: Field
pIAllocatorOs = renameField "IAllocatorOs" $ optionalNEStringField "os"

-- | IAllocator instances field.
pIAllocatorInstances :: Field
pIAllocatorInstances =
  renameField "IAllocatorInstances " .
  optionalField $
  simpleField "instances" [t| [NonEmptyString] |]

-- | IAllocator evac mode.
pIAllocatorEvacMode :: Field
pIAllocatorEvacMode =
  renameField "IAllocatorEvacMode" .
  optionalField $
  simpleField "evac_mode" [t| NodeEvacMode |]

-- | IAllocator spindle use.
pIAllocatorSpindleUse :: Field
pIAllocatorSpindleUse =
  renameField "IAllocatorSpindleUse" .
  defaultField [| forceNonNeg (1::Int) |] $
  simpleField "spindle_use" [t| NonNegative Int |]

-- | IAllocator count field.
pIAllocatorCount :: Field
pIAllocatorCount =
  renameField "IAllocatorCount" .
  defaultField [| forceNonNeg (1::Int) |] $
  simpleField "count" [t| NonNegative Int |]

-- | 'OpTestJqueue' notify_waitlock.
pJQueueNotifyWaitLock :: Field
pJQueueNotifyWaitLock = defaultFalse "notify_waitlock"

-- | 'OpTestJQueue' notify_exec.
pJQueueNotifyExec :: Field
pJQueueNotifyExec = defaultFalse "notify_exec"

-- | 'OpTestJQueue' log_messages.
pJQueueLogMessages :: Field
pJQueueLogMessages =
  defaultField [| [] |] $ simpleField "log_messages" [t| [String] |]

-- | 'OpTestJQueue' fail attribute.
pJQueueFail :: Field
pJQueueFail =
  renameField "JQueueFail" $ defaultFalse "fail"

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

-- | 'OpTestDummy' messages field.
pTestDummyMessages :: Field
pTestDummyMessages =
  renameField "TestDummyMessages" $
  simpleField "messages" [t| UncheckedValue |]

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

-- | 'OpTestDummy' submit_jobs field.
pTestDummySubmitJobs :: Field
pTestDummySubmitJobs =
  renameField "TestDummySubmitJobs" $
  simpleField "submit_jobs" [t| UncheckedValue |]
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431

-- * Network parameters

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

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

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

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

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

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

-- | Network add reserved IPs.
pNetworkAddRsvdIps :: Field
pNetworkAddRsvdIps =
  renameField "NetworkAddRsvdIps" .
  optionalField $
  simpleField "add_reserved_ips" [t| [NonEmptyString] |]

-- | Network remove reserved IPs.
pNetworkRemoveRsvdIps :: Field
pNetworkRemoveRsvdIps =
  renameField "NetworkRemoveRsvdIps" .
  optionalField $
  simpleField "remove_reserved_ips" [t| [NonEmptyString] |]

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

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

1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
-- * Common opcode parameters

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

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

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

-- | Job dependencies.
pDependencies :: Field
1452
1453
pDependencies =
  optionalNullSerField $ simpleField "depends" [t| [JobDependency] |]
1454
1455
1456

-- | Comment field.
pComment :: Field
1457
pComment = optionalNullSerField $ stringField "comment"
1458

1459
1460
1461
1462
-- | Reason trail field.
pReason :: Field
pReason = simpleField C.opcodeReason [t| ReasonTrail |]

1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
-- * Entire opcode parameter list

-- | Old-style query opcode, with locking.
dOldQuery :: [Field]
dOldQuery =
  [ pOutputFields
  , pNames
  , pUseLocking
  ]

-- | Old-style query opcode, without locking.
dOldQueryNoLocking :: [Field]
dOldQueryNoLocking =
  [ pOutputFields
  , pNames
  ]