OpParams.hs 45.4 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
Iustin Pop's avatar
Iustin Pop committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
  , pIAllocatorDirection
  , pIAllocatorMode
  , pIAllocatorReqName
  , pIAllocatorNics
  , pIAllocatorDisks
  , pIAllocatorMemory
  , pIAllocatorVCpus
  , pIAllocatorOs
  , pIAllocatorInstances
  , pIAllocatorEvacMode
  , pIAllocatorSpindleUse
  , pIAllocatorCount
  , pJQueueNotifyWaitLock
  , pJQueueNotifyExec
  , pJQueueLogMessages
  , pJQueueFail
  , pTestDummyResult
  , pTestDummyMessages
  , pTestDummyFail
  , pTestDummySubmitJobs
239 240 241 242 243 244 245 246 247 248
  , pNetworkName
  , pNetworkAddress4
  , pNetworkGateway4
  , pNetworkAddress6
  , pNetworkGateway6
  , pNetworkMacPrefix
  , pNetworkAddRsvdIps
  , pNetworkRemoveRsvdIps
  , pNetworkMode
  , pNetworkLink
249 250 251 252 253
  , pDryRun
  , pDebugLevel
  , pOpPriority
  , pDependencies
  , pComment
254
  , pReason
255
  , pSequential
256
  , pEnabledDiskTemplates
257 258
  ) where

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

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

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

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

298 299 300 301 302 303 304 305 306
-- | 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

307 308 309 310 311
-- ** Disks

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

-- | 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
325 326 327 328 329 330 331 332 333 334 335
-- ** 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
336 337 338 339 340 341 342
  [ 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
343 344
  ])

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

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

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

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

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

-- | 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
444
-- * Common opcode parameters
Iustin Pop's avatar
Iustin Pop committed
445

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

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

Jose A. Lopes's avatar
Jose A. Lopes committed
456 457 458 459 460 461
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
462

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

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

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

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

Jose A. Lopes's avatar
Jose A. Lopes committed
483
-- * Parameters
Iustin Pop's avatar
Iustin Pop committed
484 485

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

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

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

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

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

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

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

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

527 528 529
pHotplugIfPossible :: Field
pHotplugIfPossible = defaultFalse "hotplug_if_possible"

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

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

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

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

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

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

561 562 563 564 565 566 567 568 569 570 571
-- | 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"
572

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

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

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

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

Iustin Pop's avatar
Iustin Pop committed
598
pOsHvp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
599 600 601 602
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
603

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

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

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

pUidPool :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
624 625 626
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
627
  optionalField $ simpleField "uid_pool" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
628 629

pAddUids :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
630 631 632
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
633
  optionalField $ simpleField "add_uids" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
634 635

pRemoveUids :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
636 637 638
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
639
  optionalField $ simpleField "remove_uids" [t| [(Int, Int)] |]
Iustin Pop's avatar
Iustin Pop committed
640 641

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

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

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

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

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

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

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

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

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

pHiddenOs :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
692 693 694 695 696
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
697 698 699

pBlacklistedOs :: Field
pBlacklistedOs =
Jose A. Lopes's avatar
Jose A. Lopes committed
700 701 702 703 704
  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
705 706

pUseExternalMipScript :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
707 708 709 710 711 712 713 714
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
715
  simpleField "enabled_disk_templates" [t| [DiskTemplate] |]
Jose A. Lopes's avatar
Jose A. Lopes committed
716 717 718 719 720 721 722 723 724 725

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

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

pQueryFilter :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
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
752 753

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

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

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

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
773 774
  -- 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
775 776 777
  defaultField [| C.oobPowerDelay |] $
  simpleField "power_delay" [t| Double |]

Jose A. Lopes's avatar
Jose A. Lopes committed
778 779 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
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
805
pPrimaryIp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
806
pPrimaryIp =
Jose A. Lopes's avatar
Jose A. Lopes committed
807 808
  withDoc "Primary IP address" .
  optionalField $
Jose A. Lopes's avatar
Jose A. Lopes committed
809
  simpleField "primary_ip" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
810 811

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

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

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

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

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

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

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

pStorageType :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
853
pStorageType =
854 855 856 857 858 859 860
  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
861 862 863 864 865 866

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

pStorageChanges :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
869 870 871 872 873 874 875 876
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
877 878

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

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

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

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

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

Jose A. Lopes's avatar
Jose A. Lopes committed
904 905 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
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
936
pIallocator :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
937 938 939 940 941 942 943 944 945
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
946 947

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

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

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

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
996
  withDoc "Disk template" $
Jose A. Lopes's avatar
Jose A. Lopes committed
997 998 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
  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"
1036 1037 1038

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

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

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

pInstOs :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
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 |]
1063 1064

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

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

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

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

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

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

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

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

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

Thomas Thrainer's avatar
Thomas Thrainer committed
1112
pSrcNodeUuid :: Field