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

261
import Control.Monad (liftM)
Jose A. Lopes's avatar
Jose A. Lopes committed
262 263
import Text.JSON (JSON, JSValue(..), JSObject (..), readJSON, showJSON,
                  fromJSString, toJSObject)
264
import qualified Text.JSON
265 266
import Text.JSON.Pretty (pp_value)

267
import Ganeti.BasicTypes
268 269 270
import qualified Ganeti.Constants as C
import Ganeti.THH
import Ganeti.JSON
Iustin Pop's avatar
Iustin Pop committed
271 272
import Ganeti.Types
import qualified Ganeti.Query.Language as Qlang
273

Jose A. Lopes's avatar
Jose A. Lopes committed
274
-- * Helper functions and types
Iustin Pop's avatar
Iustin Pop committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299

-- | 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 |]

300 301 302 303 304 305 306 307 308
-- | 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

309 310 311 312 313
-- ** Disks

-- | Disk index type (embedding constraints on the index value via a
-- smart constructor).
newtype DiskIndex = DiskIndex { unDiskIndex :: Int }
314
  deriving (Show, Eq, Ord)
315 316 317 318 319 320 321 322 323 324 325 326

-- | 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
327 328 329 330 331 332 333 334 335 336 337
-- ** I* param types

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

-- | NIC modification definition.
$(buildObject "INicParams" "inic"
Jose A. Lopes's avatar
Jose A. Lopes committed
338 339 340 341 342 343 344
  [ optionalField $ simpleField C.inicMac    [t| NonEmptyString |]
  , optionalField $ simpleField C.inicIp     [t| String         |]
  , optionalField $ simpleField C.inicMode   [t| NonEmptyString |]
  , optionalField $ simpleField C.inicLink   [t| NonEmptyString |]
  , optionalField $ simpleField C.inicName   [t| NonEmptyString |]
  , optionalField $ simpleField C.inicVlan   [t| NonEmptyString |]
  , optionalField $ simpleField C.inicBridge [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
345 346
  ])

347
-- | Disk modification definition. FIXME: disksize should be VTYPE_UNIT.
Iustin Pop's avatar
Iustin Pop committed
348
$(buildObject "IDiskParams" "idisk"
349 350 351 352 353
  [ 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 |]
354
  , optionalField $ simpleField C.idiskName   [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
355 356
  ])

357 358 359 360 361 362 363 364 365
-- | 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))
366
    deriving (Eq, Show)
367 368 369 370 371 372 373 374 375

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"
376
                ++ " indices or list of disk parameters; value received:"
377 378 379 380 381 382 383 384 385 386 387
                ++ 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
388
                     deriving (Eq, Show)
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408

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))
409
    deriving (Eq, Show)
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424

-- | 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
425
-- | Custom type for target_node parameter of OpBackupExport, which
Jose A. Lopes's avatar
Jose A. Lopes committed
426
-- varies depending on mode. FIXME: this uses an [JSValue] since
Iustin Pop's avatar
Iustin Pop committed
427 428 429
-- 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
Jose A. Lopes's avatar
Jose A. Lopes committed
430
                  | ExportTargetRemote [JSValue]
431
                    deriving (Eq, Show)
Iustin Pop's avatar
Iustin Pop committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445

-- | 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

Jose A. Lopes's avatar
Jose A. Lopes committed
446
-- * Common opcode parameters
Iustin Pop's avatar
Iustin Pop committed
447

Jose A. Lopes's avatar
Jose A. Lopes committed
448 449 450 451
pDryRun :: Field
pDryRun =
  withDoc "Run checks only, don't execute" .
  optionalField $ booleanField "dry_run"
Iustin Pop's avatar
Iustin Pop committed
452

Jose A. Lopes's avatar
Jose A. Lopes committed
453 454 455 456
pDebugLevel :: Field
pDebugLevel =
  withDoc "Debug level" .
  optionalField $ simpleField "debug_level" [t| NonNegative Int |]
Iustin Pop's avatar
Iustin Pop committed
457

Jose A. Lopes's avatar
Jose A. Lopes committed
458 459 460 461 462 463
pOpPriority :: Field
pOpPriority =
  withDoc "Opcode priority. Note: python uses a separate constant,\
          \ we're using the actual value we know it's the default" .
  defaultField [| OpPrioNormal |] $
  simpleField "priority" [t| OpSubmitPriority |]
Thomas Thrainer's avatar
Thomas Thrainer committed
464

Jose A. Lopes's avatar
Jose A. Lopes committed
465 466 467 468
pDependencies :: Field
pDependencies =
  withDoc "Job dependencies" .
  optionalNullSerField $ simpleField "depends" [t| [JobDependency] |]
469

Jose A. Lopes's avatar
Jose A. Lopes committed
470 471 472 473
pComment :: Field
pComment =
  withDoc "Comment field" .
  optionalNullSerField $ stringField "comment"
Thomas Thrainer's avatar
Thomas Thrainer committed
474

Jose A. Lopes's avatar
Jose A. Lopes committed
475 476 477 478
pReason :: Field
pReason =
  withDoc "Reason trail field" $
  simpleField C.opcodeReason [t| ReasonTrail |]
Iustin Pop's avatar
Iustin Pop committed
479

480 481 482 483 484
pSequential :: Field
pSequential =
  withDoc "Sequential job execution" $
  defaultFalse C.opcodeSequential

Jose A. Lopes's avatar
Jose A. Lopes committed
485
-- * Parameters
Iustin Pop's avatar
Iustin Pop committed
486 487

pDebugSimulateErrors :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
488 489 490
pDebugSimulateErrors =
  withDoc "Whether to simulate errors (useful for debugging)" $
  defaultFalse "debug_simulate_errors"
Iustin Pop's avatar
Iustin Pop committed
491 492

pErrorCodes :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
493 494 495
pErrorCodes = 
  withDoc "Error codes" $
  defaultFalse "error_codes"
Iustin Pop's avatar
Iustin Pop committed
496 497

pSkipChecks :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
498 499
pSkipChecks = 
  withDoc "Which checks to skip" .
500 501
  defaultField [| emptyListSet |] $
  simpleField "skip_checks" [t| ListSet VerifyOptionalChecks |]
Iustin Pop's avatar
Iustin Pop committed
502 503

pIgnoreErrors :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
504 505
pIgnoreErrors =
  withDoc "List of error codes that should be treated as warnings" .
506 507
  defaultField [| emptyListSet |] $
  simpleField "ignore_errors" [t| ListSet CVErrorCode |]
Iustin Pop's avatar
Iustin Pop committed
508

Jose A. Lopes's avatar
Jose A. Lopes committed
509 510 511 512
pVerbose :: Field
pVerbose =
  withDoc "Verbose mode" $
  defaultFalse "verbose"
Iustin Pop's avatar
Iustin Pop committed
513

Jose A. Lopes's avatar
Jose A. Lopes committed
514 515 516 517 518
pOptGroupName :: Field
pOptGroupName =
  withDoc "Optional group name" .
  renameField "OptGroupName" .
  optionalField $ simpleField "group_name" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
519

Jose A. Lopes's avatar
Jose A. Lopes committed
520 521 522 523
pGroupName :: Field
pGroupName =
  withDoc "Group name" $
  simpleField "group_name" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
524

Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
525 526 527 528
-- | Whether to hotplug device.
pHotplug :: Field
pHotplug = defaultFalse "hotplug"

529 530 531
pHotplugIfPossible :: Field
pHotplugIfPossible = defaultFalse "hotplug_if_possible"

Jose A. Lopes's avatar
Jose A. Lopes committed
532 533 534 535 536
pInstances :: Field
pInstances =
  withDoc "List of instances" .
  defaultField [| [] |] $
  simpleField "instances" [t| [NonEmptyString] |]
537

Jose A. Lopes's avatar
Jose A. Lopes committed
538 539 540 541
pOutputFields :: Field
pOutputFields =
  withDoc "Selected output fields" $
  simpleField "output_fields" [t| [NonEmptyString] |]
542

Jose A. Lopes's avatar
Jose A. Lopes committed
543 544 545 546
pName :: Field
pName =
  withDoc "A generic name" $
  simpleField "name" [t| NonEmptyString |]
547

Jose A. Lopes's avatar
Jose A. Lopes committed
548 549 550 551
pForce :: Field
pForce =
  withDoc "Whether to force the operation" $
  defaultFalse "force"
552

Jose A. Lopes's avatar
Jose A. Lopes committed
553 554 555 556
pHvState :: Field
pHvState =
  withDoc "Set hypervisor states" .
  optionalField $ simpleField "hv_state" [t| JSObject JSValue |]
557

Jose A. Lopes's avatar
Jose A. Lopes committed
558 559 560 561
pDiskState :: Field
pDiskState =
  withDoc "Set disk states" .
  optionalField $ simpleField "disk_state" [t| JSObject JSValue |]
Iustin Pop's avatar
Iustin Pop committed
562

563 564 565 566 567 568 569 570 571 572 573
-- | Cluster-wide default directory for storing file-backed disks.
pClusterFileStorageDir :: Field
pClusterFileStorageDir =
  renameField "ClusterFileStorageDir" $
  optionalStringField "file_storage_dir"

-- | Cluster-wide default directory for storing shared-file-backed disks.
pClusterSharedFileStorageDir :: Field
pClusterSharedFileStorageDir =
  renameField "ClusterSharedFileStorageDir" $
  optionalStringField "shared_file_storage_dir"
574

Iustin Pop's avatar
Iustin Pop committed
575 576
-- | Volume group name.
pVgName :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
577 578 579
pVgName =
  withDoc "Volume group name" $
  optionalStringField "vg_name"
Iustin Pop's avatar
Iustin Pop committed
580 581 582

pEnabledHypervisors :: Field
pEnabledHypervisors =
Jose A. Lopes's avatar
Jose A. Lopes committed
583
  withDoc "List of enabled hypervisors" .
Iustin Pop's avatar
Iustin Pop committed
584
  optionalField $
Jose A. Lopes's avatar
Jose A. Lopes committed
585
  simpleField "enabled_hypervisors" [t| [Hypervisor] |]
586

Iustin Pop's avatar
Iustin Pop committed
587 588
pClusterHvParams :: Field
pClusterHvParams =
Jose A. Lopes's avatar
Jose A. Lopes committed
589
  withDoc "Cluster-wide hypervisor parameters, hypervisor-dependent" .
590
  renameField "ClusterHvParams" .
Iustin Pop's avatar
Iustin Pop committed
591
  optionalField $
Jose A. Lopes's avatar
Jose A. Lopes committed
592
  simpleField "hvparams" [t| GenericContainer String (JSObject JSValue) |]
593

Iustin Pop's avatar
Iustin Pop committed
594
pClusterBeParams :: Field
595
pClusterBeParams =
Jose A. Lopes's avatar
Jose A. Lopes committed
596
  withDoc "Cluster-wide backend parameter defaults" .
597
  renameField "ClusterBeParams" .
Jose A. Lopes's avatar
Jose A. Lopes committed
598
  optionalField $ simpleField "beparams" [t| JSObject JSValue |]
599

Iustin Pop's avatar
Iustin Pop committed
600
pOsHvp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
601 602 603 604
pOsHvp =
  withDoc "Cluster-wide per-OS hypervisor parameter defaults" .
  optionalField $
  simpleField "os_hvp" [t| GenericContainer String (JSObject JSValue) |]
Iustin Pop's avatar
Iustin Pop committed
605

606 607
pClusterOsParams :: Field
pClusterOsParams =
Jose A. Lopes's avatar
Jose A. Lopes committed
608
  withDoc "Cluster-wide OS parameter defaults" .
609
  renameField "ClusterOsParams" .
Jose A. Lopes's avatar
Jose A. Lopes committed
610 611
  optionalField $
  simpleField "osparams" [t| GenericContainer String (JSObject JSValue) |]
612

Jose A. Lopes's avatar
Jose A. Lopes committed
613 614 615 616 617 618
pDiskParams :: Field
pDiskParams =
  withDoc "Disk templates' parameter defaults" .
  optionalField $
  simpleField "diskparams"
              [t| GenericContainer DiskTemplate (JSObject JSValue) |]
619

Iustin Pop's avatar
Iustin Pop committed
620 621
pCandidatePoolSize :: Field
pCandidatePoolSize =
Jose A. Lopes's avatar
Jose A. Lopes committed
622
  withDoc "Master candidate pool size" .
Iustin Pop's avatar
Iustin Pop committed
623 624 625
  optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]

pUidPool :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
626 627 628
pUidPool =
  withDoc "Set UID pool, must be list of lists describing UID ranges\
          \ (two items, start and end inclusive)" .
Jose A. Lopes's avatar
Jose A. Lopes committed
629
  optionalField $ simpleField "uid_pool" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
630 631

pAddUids :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
632 633 634
pAddUids =
  withDoc "Extend UID pool, must be list of lists describing UID\
          \ ranges (two items, start and end inclusive)" .
Jose A. Lopes's avatar
Jose A. Lopes committed
635
  optionalField $ simpleField "add_uids" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
636 637

pRemoveUids :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
638 639 640
pRemoveUids =
  withDoc "Shrink UID pool, must be list of lists describing UID\
          \ ranges (two items, start and end inclusive) to be removed" .
Jose A. Lopes's avatar
Jose A. Lopes committed
641
  optionalField $ simpleField "remove_uids" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
642 643

pMaintainNodeHealth :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
644 645 646
pMaintainNodeHealth =
  withDoc "Whether to automatically maintain node health" .
  optionalField $ booleanField "maintain_node_health"
Iustin Pop's avatar
Iustin Pop committed
647

648 649 650 651
-- | 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
652 653
-- | Whether to wipe disks before allocating them to instances.
pPreallocWipeDisks :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
654 655 656
pPreallocWipeDisks =
  withDoc "Whether to wipe disks before allocating them to instances" .
  optionalField $ booleanField "prealloc_wipe_disks"
Iustin Pop's avatar
Iustin Pop committed
657 658

pNicParams :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
659 660 661
pNicParams =
  withDoc "Cluster-wide NIC parameter defaults" .
  optionalField $ simpleField "nicparams" [t| INicParams |]
Iustin Pop's avatar
Iustin Pop committed
662 663

pIpolicy :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
664 665 666
pIpolicy =
  withDoc "Ipolicy specs" .
  optionalField $ simpleField "ipolicy" [t| JSObject JSValue |]
Iustin Pop's avatar
Iustin Pop committed
667 668

pDrbdHelper :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
669 670 671
pDrbdHelper =
  withDoc "DRBD helper program" $
  optionalStringField "drbd_helper"
Iustin Pop's avatar
Iustin Pop committed
672 673

pDefaultIAllocator :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
674 675 676
pDefaultIAllocator =
  withDoc "Default iallocator for cluster" $
  optionalStringField "default_iallocator"
Iustin Pop's avatar
Iustin Pop committed
677 678

pMasterNetdev :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
679 680 681
pMasterNetdev =
  withDoc "Master network device" $
  optionalStringField "master_netdev"
Iustin Pop's avatar
Iustin Pop committed
682 683

pMasterNetmask :: Field
684
pMasterNetmask =
Jose A. Lopes's avatar
Jose A. Lopes committed
685
  withDoc "Netmask of the master IP" .
686
  optionalField $ simpleField "master_netmask" [t| NonNegative Int |]
Iustin Pop's avatar
Iustin Pop committed
687 688 689

pReservedLvs :: Field
pReservedLvs =
Jose A. Lopes's avatar
Jose A. Lopes committed
690
  withDoc "List of reserved LVs" .
Iustin Pop's avatar
Iustin Pop committed
691 692 693
  optionalField $ simpleField "reserved_lvs" [t| [NonEmptyString] |]

pHiddenOs :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
694 695 696 697 698
pHiddenOs =
  withDoc "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" .
  optionalField $ simpleField "hidden_os" [t| [(DdmSimple, NonEmptyString)] |]
Iustin Pop's avatar
Iustin Pop committed
699 700 701

pBlacklistedOs :: Field
pBlacklistedOs =
Jose A. Lopes's avatar
Jose A. Lopes committed
702 703 704 705 706
  withDoc "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" .
  optionalField $
  simpleField "blacklisted_os" [t| [(DdmSimple, NonEmptyString)] |]
Iustin Pop's avatar
Iustin Pop committed
707 708

pUseExternalMipScript :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
709 710 711 712 713 714 715 716
pUseExternalMipScript =
  withDoc "Whether to use an external master IP address setup script" .
  optionalField $ booleanField "use_external_mip_script"

pEnabledDiskTemplates :: Field
pEnabledDiskTemplates =
  withDoc "List of enabled disk templates" .
  optionalField $
Jose A. Lopes's avatar
Jose A. Lopes committed
717
  simpleField "enabled_disk_templates" [t| [DiskTemplate] |]
Jose A. Lopes's avatar
Jose A. Lopes committed
718 719 720 721 722 723 724 725 726 727

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

pUseLocking :: Field
pUseLocking =
  withDoc "Whether to use synchronization" $
  defaultFalse "use_locking"
Iustin Pop's avatar
Iustin Pop committed
728 729

pQueryFields :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
730 731 732
pQueryFields =
  withDoc "Requested fields" $
  simpleField "fields" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
733 734

pQueryFilter :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
pQueryFilter =
  withDoc "Query filter" .
  optionalField $ simpleField "qfilter" [t| [JSValue] |]

pQueryFieldsFields :: Field
pQueryFieldsFields =
  withDoc "Requested fields; if not given, all are returned" .
  renameField "QueryFieldsFields" $
  optionalField pQueryFields

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

pNodeUuids :: Field
pNodeUuids =
  withDoc "List of node UUIDs" .
  optionalField $ simpleField "node_uuids" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
754 755

pOobCommand :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
756 757 758
pOobCommand =
  withDoc "OOB command to run" $
  simpleField "command" [t| OobCommand |]
Iustin Pop's avatar
Iustin Pop committed
759 760 761

pOobTimeout :: Field
pOobTimeout =
Jose A. Lopes's avatar
Jose A. Lopes committed
762 763 764
  withDoc "Timeout before the OOB helper will be terminated" .
  defaultField [| C.oobTimeout |] $
  simpleField "timeout" [t| Int |]
Iustin Pop's avatar
Iustin Pop committed
765 766

pIgnoreStatus :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
767 768 769
pIgnoreStatus =
  withDoc "Ignores the node offline status for power off" $
  defaultFalse "ignore_status"
Iustin Pop's avatar
Iustin Pop committed
770 771 772 773 774

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.
Jose A. Lopes's avatar
Jose A. Lopes committed
775 776
  -- And trying to fix the constant introduces a cyclic import.
  withDoc "Time in seconds to wait between powering on nodes" .
Iustin Pop's avatar
Iustin Pop committed
777 778 779
  defaultField [| C.oobPowerDelay |] $
  simpleField "power_delay" [t| Double |]

Jose A. Lopes's avatar
Jose A. Lopes committed
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
pRequiredNodes :: Field
pRequiredNodes =
  withDoc "Required list of node names" .
  renameField "ReqNodes " $ simpleField "nodes" [t| [NonEmptyString] |]

pRequiredNodeUuids :: Field
pRequiredNodeUuids =
  withDoc "Required list of node UUIDs" .
  renameField "ReqNodeUuids " . optionalField $
  simpleField "node_uuids" [t| [NonEmptyString] |]

pRestrictedCommand :: Field
pRestrictedCommand =
  withDoc "Restricted command name" .
  renameField "RestrictedCommand" $
  simpleField "command" [t| NonEmptyString |]

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

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

Iustin Pop's avatar
Iustin Pop committed
807
pPrimaryIp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
808
pPrimaryIp =
Jose A. Lopes's avatar
Jose A. Lopes committed
809 810
  withDoc "Primary IP address" .
  optionalField $
Jose A. Lopes's avatar
Jose A. Lopes committed
811
  simpleField "primary_ip" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
812 813

pSecondaryIp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
814 815 816
pSecondaryIp =
  withDoc "Secondary IP address" $
  optionalNEStringField "secondary_ip"
Iustin Pop's avatar
Iustin Pop committed
817 818

pReadd :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
819 820 821
pReadd =
  withDoc "Whether node is re-added to cluster" $
  defaultFalse "readd"
Iustin Pop's avatar
Iustin Pop committed
822 823

pNodeGroup :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
824 825 826
pNodeGroup =
  withDoc "Initial node group" $
  optionalNEStringField "group"
Iustin Pop's avatar
Iustin Pop committed
827 828

pMasterCapable :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
829 830 831
pMasterCapable =
  withDoc "Whether node can become master or master candidate" .
  optionalField $ booleanField "master_capable"
Iustin Pop's avatar
Iustin Pop committed
832 833

pVmCapable :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
834 835 836
pVmCapable =
  withDoc "Whether node can host instances" .
  optionalField $ booleanField "vm_capable"
Iustin Pop's avatar
Iustin Pop committed
837

Jose A. Lopes's avatar
Jose A. Lopes committed
838 839 840 841 842 843
pNdParams :: Field
pNdParams =
  withDoc "Node parameters" .
  renameField "genericNdParams" .
  optionalField $ simpleField "ndparams" [t| JSObject JSValue |]
  
Iustin Pop's avatar
Iustin Pop committed
844
pNames :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
845 846 847
pNames =
  withDoc "List of names" .
  defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
848 849

pNodes :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
850 851 852
pNodes =
  withDoc "List of nodes" .
  defaultField [| [] |] $ simpleField "nodes" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
853 854

pStorageType :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
855
pStorageType =
856 857 858 859 860 861 862
  withDoc "Storage type" $ simpleField "storage_type" [t| StorageType |]

pStorageTypeOptional :: Field
pStorageTypeOptional =
  withDoc "Storage type" .
  renameField "StorageTypeOptional" .
  optionalField $ simpleField "storage_type" [t| StorageType |]
Jose A. Lopes's avatar
Jose A. Lopes committed
863 864 865 866 867 868

pStorageName :: Field
pStorageName =
  withDoc "Storage name" .
  renameField "StorageName" .
  optionalField $ simpleField "name" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
869 870

pStorageChanges :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
871 872 873 874 875 876 877 878
pStorageChanges =
  withDoc "Requested storage changes" $
  simpleField "changes" [t| JSObject JSValue |]

pIgnoreConsistency :: Field
pIgnoreConsistency =
  withDoc "Whether to ignore disk consistency" $
  defaultFalse "ignore_consistency"
Iustin Pop's avatar
Iustin Pop committed
879 880

pMasterCandidate :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
881 882 883
pMasterCandidate =
  withDoc "Whether the node should become a master candidate" .
  optionalField $ booleanField "master_candidate"
Iustin Pop's avatar
Iustin Pop committed
884 885

pOffline :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
886 887 888
pOffline =
  withDoc "Whether to mark the node or instance offline" .
  optionalField $ booleanField "offline"
Iustin Pop's avatar
Iustin Pop committed
889 890

pDrained ::Field
Jose A. Lopes's avatar
Jose A. Lopes committed
891 892 893
pDrained =
  withDoc "Whether to mark the node as drained" .
  optionalField $ booleanField "drained"
Iustin Pop's avatar
Iustin Pop committed
894 895

pAutoPromote :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
896 897 898 899
pAutoPromote =
  withDoc "Whether node(s) should be promoted to master candidate if\
          \ necessary" $
  defaultFalse "auto_promote"
Iustin Pop's avatar
Iustin Pop committed
900 901

pPowered :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
902 903 904
pPowered =
  withDoc "Whether the node should be marked as powered" .
  optionalField $ booleanField "powered"
Iustin Pop's avatar
Iustin Pop committed
905

Jose A. Lopes's avatar
Jose A. Lopes committed
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937
pMigrationMode :: Field
pMigrationMode =
  withDoc "Migration type (live/non-live)" .
  renameField "MigrationMode" .
  optionalField $
  simpleField "mode" [t| MigrationMode |]

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

pMigrationTargetNode :: Field
pMigrationTargetNode =
  withDoc "Target node for instance migration/failover" $
  optionalNEStringField "target_node"

pMigrationTargetNodeUuid :: Field
pMigrationTargetNodeUuid =
  withDoc "Target node UUID for instance migration/failover" $
  optionalNEStringField "target_node_uuid"

pAllowRuntimeChgs :: Field
pAllowRuntimeChgs =
  withDoc "Whether to allow runtime changes while migrating" $
  defaultTrue "allow_runtime_changes"

pIgnoreIpolicy :: Field
pIgnoreIpolicy =
  withDoc "Whether to ignore ipolicy violations" $
  defaultFalse "ignore_ipolicy"
  
Iustin Pop's avatar
Iustin Pop committed
938
pIallocator :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
939 940 941 942 943 944 945 946 947
pIallocator =
  withDoc "Iallocator for deciding the target node for shared-storage\
          \ instances" $
  optionalNEStringField "iallocator"

pEarlyRelease :: Field
pEarlyRelease =
  withDoc "Whether to release locks as soon as possible" $
  defaultFalse "early_release"
Iustin Pop's avatar
Iustin Pop committed
948 949

pRemoteNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
950 951 952
pRemoteNode =
  withDoc "New secondary node" $
  optionalNEStringField "remote_node"
Iustin Pop's avatar
Iustin Pop committed
953

Thomas Thrainer's avatar
Thomas Thrainer committed
954
pRemoteNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
955 956 957
pRemoteNodeUuid =
  withDoc "New secondary node UUID" $
  optionalNEStringField "remote_node_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
958

Iustin Pop's avatar
Iustin Pop committed
959
pEvacMode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
960 961
pEvacMode =
  withDoc "Node evacuation mode" .
962
  renameField "EvacMode" $ simpleField "mode" [t| EvacMode |]
Jose A. Lopes's avatar
Jose A. Lopes committed
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

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

pForceVariant :: Field
pForceVariant =
  withDoc "Whether to force an unknown OS variant" $
  defaultFalse "force_variant"

pWaitForSync :: Field
pWaitForSync =
  withDoc "Whether to wait for the disk to synchronize" $
  defaultTrue "wait_for_sync"

pNameCheck :: Field
pNameCheck =
  withDoc "Whether to check name" $
  defaultTrue "name_check"

pInstBeParams :: Field
pInstBeParams =
  withDoc "Backend parameters for instance" .
  renameField "InstBeParams" .
  defaultField [| toJSObject [] |] $
  simpleField "beparams" [t| JSObject JSValue |]

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

pDiskTemplate :: Field
pDiskTemplate =
Jose A. Lopes's avatar
Jose A. Lopes committed
998
  withDoc "Disk template" $
Jose A. Lopes's avatar
Jose A. Lopes committed
999 1000 1001 1002 1003 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
  simpleField "disk_template" [t| DiskTemplate |]

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

pFileStorageDir :: Field
pFileStorageDir =
  withDoc "Directory for storing file-backed disks" $
  optionalNEStringField "file_storage_dir"

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

pHypervisor :: Field
pHypervisor =
  withDoc "Selected hypervisor for an instance" .
  optionalField $
  simpleField "hypervisor" [t| Hypervisor |]

pResetDefaults :: Field
pResetDefaults =
  withDoc "Reset instance parameters to default if equal" $
  defaultFalse "identify_defaults"

pIpCheck :: Field
pIpCheck =
  withDoc "Whether to ensure instance's IP address is inactive" $
  defaultTrue "ip_check"

pIpConflictsCheck :: Field
pIpConflictsCheck =
  withDoc "Whether to check for conflicting IP addresses" $
  defaultTrue "conflicts_check"
1038 1039 1040

pInstCreateMode :: Field
pInstCreateMode =
Jose A. Lopes's avatar
Jose A. Lopes committed
1041
  withDoc "Instance creation mode" .
1042 1043
  renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]

Jose A. Lopes's avatar
Jose A. Lopes committed
1044 1045 1046 1047 1048
pInstNics :: Field
pInstNics =
  withDoc "List of NIC (network interface) definitions" $
  simpleField "nics" [t| [INicParams] |]

1049
pNoInstall :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1050 1051 1052
pNoInstall =
  withDoc "Do not install the OS (will disable automatic start)" .
  optionalField $ booleanField "no_install"
1053 1054

pInstOs :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
pInstOs =
  withDoc "OS type for instance installation" $
  optionalNEStringField "os_type"

pInstOsParams :: Field
pInstOsParams =
  withDoc "OS parameters for instance" .
  renameField "InstOsParams" .
  defaultField [| toJSObject [] |] $
  simpleField "osparams" [t| JSObject JSValue |]
1065 1066

pPrimaryNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1067 1068 1069
pPrimaryNode =
  withDoc "Primary node for an instance" $
  optionalNEStringField "pnode"
1070

Thomas Thrainer's avatar
Thomas Thrainer committed
1071
pPrimaryNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1072 1073 1074
pPrimaryNodeUuid =
  withDoc "Primary node UUID for an instance" $
  optionalNEStringField "pnode_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
1075

1076
pSecondaryNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1077 1078 1079
pSecondaryNode =
  withDoc "Secondary node for an instance" $
  optionalNEStringField "snode"
1080

Thomas Thrainer's avatar
Thomas Thrainer committed
1081
pSecondaryNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1082 1083 1084
pSecondaryNodeUuid =
  withDoc "Secondary node UUID for an instance" $
  optionalNEStringField "snode_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
1085

1086 1087
pSourceHandshake :: Field
pSourceHandshake =
Jose A. Lopes's avatar
Jose A. Lopes committed
1088 1089
  withDoc "Signed handshake from source (remote import only)" .
  optionalField $ simpleField "source_handshake" [t| [JSValue] |]
1090 1091

pSourceInstance :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1092 1093 1094
pSourceInstance =
  withDoc "Source instance name (remote import only)" $
  optionalNEStringField "source_instance_name"
1095 1096 1097 1098

-- FIXME: non-negative int, whereas the constant is a plain int.
pSourceShutdownTimeout :: Field
pSourceShutdownTimeout =
Jose A. Lopes's avatar
Jose A. Lopes committed
1099 1100
  withDoc "How long source instance was given to shut down (remote import\
          \ only)" .
1101 1102 1103 1104
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
  simpleField "source_shutdown_timeout" [t| NonNegative Int |]

pSourceX509Ca :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1105 1106 1107
pSourceX509Ca =
  withDoc "Source X509 CA in PEM format (remote import only)" $
  optionalNEStringField "source_x509_ca"
1108 1109

pSrcNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1110 1111 1112
pSrcNode =
  withDoc "Source node for import" $
  optionalNEStringField "src_node"
1113

Thomas Thrainer's avatar
Thomas Thrainer committed
1114
pSrcNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1115 1116 1117
pSrcNodeUuid =
  withDoc "Source node UUID for import" $
  optionalNEStringField "src_node_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
1118

1119
pSrcPath :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1120 1121 1122
pSrcPath =
  withDoc "Source directory for import" $
  optionalNEStringField "src_path"
1123 1124

pStartInstance :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1125 1126 1127
pStartInstance =
  withDoc "Whether to start instance after creation" $
  defaultTrue "start"
1128

Jose A. Lopes's avatar
Jose A. Lopes committed
1129
-- FIXME: unify/simplify with pTags, once that migrates to NonEmpty String"
1130 1131
pInstTags :: Field
pInstTags =
Jose A. Lopes's avatar
Jose A. Lopes committed
1132
  withDoc "Instance tags" .
1133 1134 1135
  renameField "InstTags" .
  defaultField [| [] |] $
  simpleField "tags" [t| [NonEmptyString] |]
1136 1137 1138

pMultiAllocInstances :: Field
pMultiAllocInstances =
Jose A. Lopes's avatar
Jose A. Lopes committed
1139 1140
  withDoc "List of instance create opcodes describing the instances to\
          \ allocate" .
1141 1142
  renameField "InstMultiAlloc" .
  defaultField [| [] |] $
Jose A. Lopes's avatar
Jose A. Lopes committed
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
  simpleField "instances"[t| [JSValue] |]

pOpportunisticLocking :: Field
pOpportunisticLocking =
  withDoc "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)" $
  defaultFalse "opportunistic_locking"

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

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

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

Jose A. Lopes's avatar
Jose A. Lopes committed
1170 1171 1172 1173 1174 1175 1176 1177 1178
-- | Another name for the shutdown timeout, because we like to be
-- inconsistent.
pShutdownTimeout' :: Field
pShutdownTimeout' =
  withDoc "How long to wait for instance to shut down" .
  renameField "InstShutdownTimeout" .
  defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
  simpleField "timeout" [t| NonNegative Int |]

1179
pIgnoreFailures :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1180 1181 1182
pIgnoreFailures =
  withDoc "Whether to ignore failures during removal" $
  defaultFalse "ignore_failures"
1183 1184

pNewName :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
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 1210 1211 1212 1213 1214 1215 1216
pNewName =
  withDoc "New group or instance name" $
  simpleField "new_name" [t| NonEmptyString |]
  
pIgnoreOfflineNodes :: Field
pIgnoreOfflineNodes =
  withDoc "Whether to ignore offline nodes" $
  defaultFalse "ignore_offline_nodes"

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

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

pNoRemember :: Field
pNoRemember =
  withDoc "Do not remember instance state changes" $
  defaultFalse "no_remember"

pStartupPaused :: Field
pStartupPaused =
  withDoc "Pause instance at startup" $
  defaultFalse "startup_paused"
1217 1218

pIgnoreSecondaries :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1219 1220 1221
pIgnoreSecondaries =
  withDoc "Whether to start the instance even if secondary disks are failing" $
  defaultFalse "ignore_secondaries"
1222