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

{-| Implementation of opcodes parameters.

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

-}

{-

Copyright (C) 2012 Google Inc.

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

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

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

-}

module Ganeti.OpParams
  ( TagType(..)
  , TagObject(..)
  , tagObjectFrom
Iustin Pop's avatar
Iustin Pop committed
38
  , tagNameOf
39 40 41 42 43 44
  , decodeTagObject
  , encodeTagObject
  , ReplaceDisksMode(..)
  , DiskIndex
  , mkDiskIndex
  , unDiskIndex
45
  , DiskAccess(..)
Iustin Pop's avatar
Iustin Pop committed
46 47
  , INicParams(..)
  , IDiskParams(..)
48 49 50
  , RecreateDisksInfo(..)
  , DdmOldChanges(..)
  , SetParamsMods(..)
Iustin Pop's avatar
Iustin Pop committed
51
  , ExportTarget(..)
52
  , pInstanceName
53
  , pInstanceUuid
Iustin Pop's avatar
Iustin Pop committed
54 55
  , pInstances
  , pName
56 57
  , pTagsList
  , pTagsObject
Jose A. Lopes's avatar
Jose A. Lopes committed
58
  , pTagsName
Iustin Pop's avatar
Iustin Pop committed
59 60
  , pOutputFields
  , pShutdownTimeout
61
  , pShutdownInstance
Iustin Pop's avatar
Iustin Pop committed
62 63 64
  , pForce
  , pIgnoreOfflineNodes
  , pNodeName
Thomas Thrainer's avatar
Thomas Thrainer committed
65
  , pNodeUuid
Iustin Pop's avatar
Iustin Pop committed
66
  , pNodeNames
Thomas Thrainer's avatar
Thomas Thrainer committed
67
  , pNodeUuids
Iustin Pop's avatar
Iustin Pop committed
68 69 70
  , pGroupName
  , pMigrationMode
  , pMigrationLive
71
  , pMigrationCleanup
Iustin Pop's avatar
Iustin Pop committed
72 73 74 75 76 77
  , pForceVariant
  , pWaitForSync
  , pWaitForSyncFalse
  , pIgnoreConsistency
  , pStorageName
  , pUseLocking
78
  , pOpportunisticLocking
Iustin Pop's avatar
Iustin Pop committed
79 80 81 82 83
  , pNameCheck
  , pNodeGroupAllocPolicy
  , pGroupNodeParams
  , pQueryWhat
  , pEarlyRelease
84 85
  , pIpCheck
  , pIpConflictsCheck
Iustin Pop's avatar
Iustin Pop committed
86 87
  , pNoRemember
  , pMigrationTargetNode
Thomas Thrainer's avatar
Thomas Thrainer committed
88
  , pMigrationTargetNodeUuid
89
  , pMoveTargetNode
Thomas Thrainer's avatar
Thomas Thrainer committed
90
  , pMoveTargetNodeUuid
Iustin Pop's avatar
Iustin Pop committed
91 92 93 94 95 96 97 98 99 100 101 102
  , pStartupPaused
  , pVerbose
  , pDebugSimulateErrors
  , pErrorCodes
  , pSkipChecks
  , pIgnoreErrors
  , pOptGroupName
  , pDiskParams
  , pHvState
  , pDiskState
  , pIgnoreIpolicy
  , pAllowRuntimeChgs
103 104
  , pInstDisks
  , pDiskTemplate
105
  , pOptDiskTemplate
106 107
  , pFileDriver
  , pFileStorageDir
108
  , pGlobalFileStorageDir
Iustin Pop's avatar
Iustin Pop committed
109 110
  , pVgName
  , pEnabledHypervisors
111
  , pHypervisor
Iustin Pop's avatar
Iustin Pop committed
112
  , pClusterHvParams
113
  , pInstHvParams
Iustin Pop's avatar
Iustin Pop committed
114
  , pClusterBeParams
115 116
  , pInstBeParams
  , pResetDefaults
Iustin Pop's avatar
Iustin Pop committed
117
  , pOsHvp
118 119
  , pClusterOsParams
  , pInstOsParams
Iustin Pop's avatar
Iustin Pop committed
120 121 122 123 124
  , pCandidatePoolSize
  , pUidPool
  , pAddUids
  , pRemoveUids
  , pMaintainNodeHealth
125
  , pModifyEtcHosts
Iustin Pop's avatar
Iustin Pop committed
126 127
  , pPreallocWipeDisks
  , pNicParams
128
  , pInstNics
Iustin Pop's avatar
Iustin Pop committed
129 130 131 132 133 134 135 136 137 138 139 140
  , pNdParams
  , pIpolicy
  , pDrbdHelper
  , pDefaultIAllocator
  , pMasterNetdev
  , pMasterNetmask
  , pReservedLvs
  , pHiddenOs
  , pBlacklistedOs
  , pUseExternalMipScript
  , pQueryFields
  , pQueryFilter
Jose A. Lopes's avatar
Jose A. Lopes committed
141
  , pQueryFieldsFields
Iustin Pop's avatar
Iustin Pop committed
142 143 144 145 146 147 148 149 150 151 152 153
  , pOobCommand
  , pOobTimeout
  , pIgnoreStatus
  , pPowerDelay
  , pPrimaryIp
  , pSecondaryIp
  , pReadd
  , pNodeGroup
  , pMasterCapable
  , pVmCapable
  , pNames
  , pNodes
Iustin Pop's avatar
Iustin Pop committed
154
  , pRequiredNodes
Thomas Thrainer's avatar
Thomas Thrainer committed
155
  , pRequiredNodeUuids
Iustin Pop's avatar
Iustin Pop committed
156 157 158 159 160 161 162 163 164
  , pStorageType
  , pStorageChanges
  , pMasterCandidate
  , pOffline
  , pDrained
  , pAutoPromote
  , pPowered
  , pIallocator
  , pRemoteNode
Thomas Thrainer's avatar
Thomas Thrainer committed
165
  , pRemoteNodeUuid
Iustin Pop's avatar
Iustin Pop committed
166
  , pEvacMode
167 168 169 170
  , pInstCreateMode
  , pNoInstall
  , pInstOs
  , pPrimaryNode
Thomas Thrainer's avatar
Thomas Thrainer committed
171
  , pPrimaryNodeUuid
172
  , pSecondaryNode
Thomas Thrainer's avatar
Thomas Thrainer committed
173
  , pSecondaryNodeUuid
174 175 176 177 178
  , pSourceHandshake
  , pSourceInstance
  , pSourceShutdownTimeout
  , pSourceX509Ca
  , pSrcNode
Thomas Thrainer's avatar
Thomas Thrainer committed
179
  , pSrcNodeUuid
180 181 182
  , pSrcPath
  , pStartInstance
  , pInstTags
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
  , 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
202 203
  , pExportMode
  , pExportTargetNode
Thomas Thrainer's avatar
Thomas Thrainer committed
204
  , pExportTargetNodeUuid
Iustin Pop's avatar
Iustin Pop committed
205 206 207 208
  , pRemoveInstance
  , pIgnoreRemoveFailures
  , pX509KeyName
  , pX509DestCA
209
  , pTagSearchPattern
Iustin Pop's avatar
Iustin Pop committed
210
  , pRestrictedCommand
211 212 213 214 215 216
  , pReplaceDisksMode
  , pReplaceDisksList
  , pAllowFailover
  , 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
  , pEnabledDiskTemplates
256 257
  ) where

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

266
import Ganeti.BasicTypes
267 268 269
import qualified Ganeti.Constants as C
import Ganeti.THH
import Ganeti.JSON
Iustin Pop's avatar
Iustin Pop committed
270 271
import Ganeti.Types
import qualified Ganeti.Query.Language as Qlang
272 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 314 315 316 317 318 319 320 321 322 323 324
-- ** Tags

-- | Data type representing what items do the tag operations apply to.
$(declareSADT "TagType"
  [ ("TagTypeInstance", 'C.tagInstance)
  , ("TagTypeNode",     'C.tagNode)
  , ("TagTypeGroup",    'C.tagNodegroup)
  , ("TagTypeCluster",  'C.tagCluster)
  ])
$(makeJSONInstance ''TagType)

-- | Data type holding a tag object (type and object name).
data TagObject = TagInstance String
               | TagNode     String
               | TagGroup    String
               | TagCluster
325
               deriving (Show, Eq)
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381

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

-- | Gets the potential tag object name.
tagNameOf :: TagObject -> Maybe String
tagNameOf (TagInstance s) = Just s
tagNameOf (TagNode     s) = Just s
tagNameOf (TagGroup    s) = Just s
tagNameOf  TagCluster     = Nothing

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

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

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

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

-- ** Disks

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

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

-- | 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
395 396 397 398 399 400 401 402 403 404 405
-- ** 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
406 407 408 409 410 411 412
  [ 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
413 414
  ])

415
-- | Disk modification definition. FIXME: disksize should be VTYPE_UNIT.
Iustin Pop's avatar
Iustin Pop committed
416
$(buildObject "IDiskParams" "idisk"
417 418 419 420 421
  [ 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 |]
422
  , optionalField $ simpleField C.idiskName   [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
423 424
  ])

425 426 427 428 429 430 431 432 433
-- | 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))
434
    deriving (Eq, Show)
435 436 437 438 439 440 441 442 443

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"
444
                ++ " indices or list of disk parameters; value received:"
445 446 447 448 449 450 451 452 453 454 455
                ++ 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
456
                     deriving (Eq, Show)
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476

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))
477
    deriving (Eq, Show)
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492

-- | 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
493
-- | Custom type for target_node parameter of OpBackupExport, which
Jose A. Lopes's avatar
Jose A. Lopes committed
494
-- varies depending on mode. FIXME: this uses an [JSValue] since
Iustin Pop's avatar
Iustin Pop committed
495 496 497
-- 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
498
                  | ExportTargetRemote [JSValue]
499
                    deriving (Eq, Show)
Iustin Pop's avatar
Iustin Pop committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513

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

Iustin Pop's avatar
Iustin Pop committed
514

Jose A. Lopes's avatar
Jose A. Lopes committed
515
-- * Common opcode parameters
Iustin Pop's avatar
Iustin Pop committed
516

Jose A. Lopes's avatar
Jose A. Lopes committed
517 518 519 520
pDryRun :: Field
pDryRun =
  withDoc "Run checks only, don't execute" .
  optionalField $ booleanField "dry_run"
Iustin Pop's avatar
Iustin Pop committed
521

Jose A. Lopes's avatar
Jose A. Lopes committed
522 523 524 525
pDebugLevel :: Field
pDebugLevel =
  withDoc "Debug level" .
  optionalField $ simpleField "debug_level" [t| NonNegative Int |]
Iustin Pop's avatar
Iustin Pop committed
526

Jose A. Lopes's avatar
Jose A. Lopes committed
527 528 529 530 531 532
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
533

Jose A. Lopes's avatar
Jose A. Lopes committed
534 535 536 537
pDependencies :: Field
pDependencies =
  withDoc "Job dependencies" .
  optionalNullSerField $ simpleField "depends" [t| [JobDependency] |]
538

Jose A. Lopes's avatar
Jose A. Lopes committed
539 540 541 542
pComment :: Field
pComment =
  withDoc "Comment field" .
  optionalNullSerField $ stringField "comment"
Thomas Thrainer's avatar
Thomas Thrainer committed
543

Jose A. Lopes's avatar
Jose A. Lopes committed
544 545 546 547
pReason :: Field
pReason =
  withDoc "Reason trail field" $
  simpleField C.opcodeReason [t| ReasonTrail |]
Iustin Pop's avatar
Iustin Pop committed
548 549


Jose A. Lopes's avatar
Jose A. Lopes committed
550
-- * Parameters
Iustin Pop's avatar
Iustin Pop committed
551 552

pDebugSimulateErrors :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
553 554 555
pDebugSimulateErrors =
  withDoc "Whether to simulate errors (useful for debugging)" $
  defaultFalse "debug_simulate_errors"
Iustin Pop's avatar
Iustin Pop committed
556 557

pErrorCodes :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
558 559 560
pErrorCodes = 
  withDoc "Error codes" $
  defaultFalse "error_codes"
Iustin Pop's avatar
Iustin Pop committed
561 562

pSkipChecks :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
563 564 565 566
pSkipChecks = 
  withDoc "Which checks to skip" .
  defaultField [| Set.empty |] $
  simpleField "skip_checks" [t| Set VerifyOptionalChecks |]
Iustin Pop's avatar
Iustin Pop committed
567 568

pIgnoreErrors :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
569 570 571 572
pIgnoreErrors =
  withDoc "List of error codes that should be treated as warnings" .
  defaultField [| Set.empty |] $
  simpleField "ignore_errors" [t| Set CVErrorCode |]
Iustin Pop's avatar
Iustin Pop committed
573

Jose A. Lopes's avatar
Jose A. Lopes committed
574 575 576 577
pVerbose :: Field
pVerbose =
  withDoc "Verbose mode" $
  defaultFalse "verbose"
Iustin Pop's avatar
Iustin Pop committed
578

Jose A. Lopes's avatar
Jose A. Lopes committed
579 580 581 582 583
pOptGroupName :: Field
pOptGroupName =
  withDoc "Optional group name" .
  renameField "OptGroupName" .
  optionalField $ simpleField "group_name" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
584

Jose A. Lopes's avatar
Jose A. Lopes committed
585 586 587 588
pGroupName :: Field
pGroupName =
  withDoc "Group name" $
  simpleField "group_name" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
589

Jose A. Lopes's avatar
Jose A. Lopes committed
590 591 592 593 594
pInstances :: Field
pInstances =
  withDoc "List of instances" .
  defaultField [| [] |] $
  simpleField "instances" [t| [NonEmptyString] |]
595

Jose A. Lopes's avatar
Jose A. Lopes committed
596 597 598 599
pOutputFields :: Field
pOutputFields =
  withDoc "Selected output fields" $
  simpleField "output_fields" [t| [NonEmptyString] |]
600

Jose A. Lopes's avatar
Jose A. Lopes committed
601 602 603 604
pName :: Field
pName =
  withDoc "A generic name" $
  simpleField "name" [t| NonEmptyString |]
605

Jose A. Lopes's avatar
Jose A. Lopes committed
606 607 608 609
pForce :: Field
pForce =
  withDoc "Whether to force the operation" $
  defaultFalse "force"
610

Jose A. Lopes's avatar
Jose A. Lopes committed
611 612 613 614
pHvState :: Field
pHvState =
  withDoc "Set hypervisor states" .
  optionalField $ simpleField "hv_state" [t| JSObject JSValue |]
615

Jose A. Lopes's avatar
Jose A. Lopes committed
616 617 618 619
pDiskState :: Field
pDiskState =
  withDoc "Set disk states" .
  optionalField $ simpleField "disk_state" [t| JSObject JSValue |]
Iustin Pop's avatar
Iustin Pop committed
620

621 622 623 624
-- | Global directory for storing file-backed disks.
pGlobalFileStorageDir :: Field
pGlobalFileStorageDir = optionalNEStringField "file_storage_dir"

Iustin Pop's avatar
Iustin Pop committed
625 626
-- | Volume group name.
pVgName :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
627 628 629
pVgName =
  withDoc "Volume group name" $
  optionalStringField "vg_name"
Iustin Pop's avatar
Iustin Pop committed
630 631 632

pEnabledHypervisors :: Field
pEnabledHypervisors =
Jose A. Lopes's avatar
Jose A. Lopes committed
633
  withDoc "List of enabled hypervisors" .
Iustin Pop's avatar
Iustin Pop committed
634
  optionalField $
Jose A. Lopes's avatar
Jose A. Lopes committed
635
  simpleField "enabled_hypervisors" [t| Hypervisor |]
636

Iustin Pop's avatar
Iustin Pop committed
637 638
pClusterHvParams :: Field
pClusterHvParams =
Jose A. Lopes's avatar
Jose A. Lopes committed
639
  withDoc "Cluster-wide hypervisor parameters, hypervisor-dependent" .
640
  renameField "ClusterHvParams" .
Iustin Pop's avatar
Iustin Pop committed
641
  optionalField $
Jose A. Lopes's avatar
Jose A. Lopes committed
642
  simpleField "hvparams" [t| GenericContainer String (JSObject JSValue) |]
643

Iustin Pop's avatar
Iustin Pop committed
644
pClusterBeParams :: Field
645
pClusterBeParams =
Jose A. Lopes's avatar
Jose A. Lopes committed
646
  withDoc "Cluster-wide backend parameter defaults" .
647
  renameField "ClusterBeParams" .
Jose A. Lopes's avatar
Jose A. Lopes committed
648
  optionalField $ simpleField "beparams" [t| JSObject JSValue |]
649

Iustin Pop's avatar
Iustin Pop committed
650
pOsHvp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
651 652 653 654
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
655

656 657
pClusterOsParams :: Field
pClusterOsParams =
Jose A. Lopes's avatar
Jose A. Lopes committed
658
  withDoc "Cluster-wide OS parameter defaults" .
659
  renameField "ClusterOsParams" .
Jose A. Lopes's avatar
Jose A. Lopes committed
660 661
  optionalField $
  simpleField "osparams" [t| GenericContainer String (JSObject JSValue) |]
662

Jose A. Lopes's avatar
Jose A. Lopes committed
663 664 665 666 667 668
pDiskParams :: Field
pDiskParams =
  withDoc "Disk templates' parameter defaults" .
  optionalField $
  simpleField "diskparams"
              [t| GenericContainer DiskTemplate (JSObject JSValue) |]
669

Iustin Pop's avatar
Iustin Pop committed
670 671
pCandidatePoolSize :: Field
pCandidatePoolSize =
Jose A. Lopes's avatar
Jose A. Lopes committed
672
  withDoc "Master candidate pool size" .
Iustin Pop's avatar
Iustin Pop committed
673 674 675
  optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]

pUidPool :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
676 677 678 679
pUidPool =
  withDoc "Set UID pool, must be list of lists describing UID ranges\
          \ (two items, start and end inclusive)" .
  optionalField $ simpleField "uid_pool" [t| [[(Int, Int)]] |]
Iustin Pop's avatar
Iustin Pop committed
680 681

pAddUids :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
682 683 684 685
pAddUids =
  withDoc "Extend UID pool, must be list of lists describing UID\
          \ ranges (two items, start and end inclusive)" .
  optionalField $ simpleField "add_uids" [t| [[(Int, Int)]] |]
Iustin Pop's avatar
Iustin Pop committed
686 687

pRemoveUids :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
688 689 690 691
pRemoveUids =
  withDoc "Shrink UID pool, must be list of lists describing UID\
          \ ranges (two items, start and end inclusive) to be removed" .
  optionalField $ simpleField "remove_uids" [t| [[(Int, Int)]] |]
Iustin Pop's avatar
Iustin Pop committed
692 693

pMaintainNodeHealth :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
694 695 696
pMaintainNodeHealth =
  withDoc "Whether to automatically maintain node health" .
  optionalField $ booleanField "maintain_node_health"
Iustin Pop's avatar
Iustin Pop committed
697

698 699 700 701
-- | 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
702 703
-- | Whether to wipe disks before allocating them to instances.
pPreallocWipeDisks :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
704 705 706
pPreallocWipeDisks =
  withDoc "Whether to wipe disks before allocating them to instances" .
  optionalField $ booleanField "prealloc_wipe_disks"
Iustin Pop's avatar
Iustin Pop committed
707 708

pNicParams :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
709 710 711
pNicParams =
  withDoc "Cluster-wide NIC parameter defaults" .
  optionalField $ simpleField "nicparams" [t| INicParams |]
Iustin Pop's avatar
Iustin Pop committed
712 713

pIpolicy :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
714 715 716
pIpolicy =
  withDoc "Ipolicy specs" .
  optionalField $ simpleField "ipolicy" [t| JSObject JSValue |]
Iustin Pop's avatar
Iustin Pop committed
717 718

pDrbdHelper :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
719 720 721
pDrbdHelper =
  withDoc "DRBD helper program" $
  optionalStringField "drbd_helper"
Iustin Pop's avatar
Iustin Pop committed
722 723

pDefaultIAllocator :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
724 725 726
pDefaultIAllocator =
  withDoc "Default iallocator for cluster" $
  optionalStringField "default_iallocator"
Iustin Pop's avatar
Iustin Pop committed
727 728

pMasterNetdev :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
729 730 731
pMasterNetdev =
  withDoc "Master network device" $
  optionalStringField "master_netdev"
Iustin Pop's avatar
Iustin Pop committed
732 733

pMasterNetmask :: Field
734
pMasterNetmask =
Jose A. Lopes's avatar
Jose A. Lopes committed
735
  withDoc "Netmask of the master IP" .
736
  optionalField $ simpleField "master_netmask" [t| NonNegative Int |]
Iustin Pop's avatar
Iustin Pop committed
737 738 739

pReservedLvs :: Field
pReservedLvs =
Jose A. Lopes's avatar
Jose A. Lopes committed
740
  withDoc "List of reserved LVs" .
Iustin Pop's avatar
Iustin Pop committed
741 742 743
  optionalField $ simpleField "reserved_lvs" [t| [NonEmptyString] |]

pHiddenOs :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
744 745 746 747 748
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
749 750 751

pBlacklistedOs :: Field
pBlacklistedOs =
Jose A. Lopes's avatar
Jose A. Lopes committed
752 753 754 755 756
  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
757 758

pUseExternalMipScript :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
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 $
  simpleField "enabled_disk_templates" [t| DiskTemplate |]

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

pQueryFields :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
780 781 782
pQueryFields =
  withDoc "Requested fields" $
  simpleField "fields" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
783 784

pQueryFilter :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
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
804 805

pOobCommand :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
806 807 808
pOobCommand =
  withDoc "OOB command to run" $
  simpleField "command" [t| OobCommand |]
Iustin Pop's avatar
Iustin Pop committed
809 810 811

pOobTimeout :: Field
pOobTimeout =
Jose A. Lopes's avatar
Jose A. Lopes committed
812 813 814
  withDoc "Timeout before the OOB helper will be terminated" .
  defaultField [| C.oobTimeout |] $
  simpleField "timeout" [t| Int |]
Iustin Pop's avatar
Iustin Pop committed
815 816

pIgnoreStatus :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
817 818 819
pIgnoreStatus =
  withDoc "Ignores the node offline status for power off" $
  defaultFalse "ignore_status"
Iustin Pop's avatar
Iustin Pop committed
820 821 822 823 824

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
825 826
  -- 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
827 828 829
  defaultField [| C.oobPowerDelay |] $
  simpleField "power_delay" [t| Double |]

Jose A. Lopes's avatar
Jose A. Lopes committed
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
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
857
pPrimaryIp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
858 859 860
pPrimaryIp =
  withDoc "Primary IP address" $
  simpleField "primary_ip" [t| NonEmptyString |]
Iustin Pop's avatar
Iustin Pop committed
861 862

pSecondaryIp :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
863 864 865
pSecondaryIp =
  withDoc "Secondary IP address" $
  optionalNEStringField "secondary_ip"
Iustin Pop's avatar
Iustin Pop committed
866 867

pReadd :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
868 869 870
pReadd =
  withDoc "Whether node is re-added to cluster" $
  defaultFalse "readd"
Iustin Pop's avatar
Iustin Pop committed
871 872

pNodeGroup :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
873 874 875
pNodeGroup =
  withDoc "Initial node group" $
  optionalNEStringField "group"
Iustin Pop's avatar
Iustin Pop committed
876 877

pMasterCapable :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
878 879 880
pMasterCapable =
  withDoc "Whether node can become master or master candidate" .
  optionalField $ booleanField "master_capable"
Iustin Pop's avatar
Iustin Pop committed
881 882

pVmCapable :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
883 884 885
pVmCapable =
  withDoc "Whether node can host instances" .
  optionalField $ booleanField "vm_capable"
Iustin Pop's avatar
Iustin Pop committed
886

Jose A. Lopes's avatar
Jose A. Lopes committed
887 888 889 890 891 892
pNdParams :: Field
pNdParams =
  withDoc "Node parameters" .
  renameField "genericNdParams" .
  optionalField $ simpleField "ndparams" [t| JSObject JSValue |]
  
Iustin Pop's avatar
Iustin Pop committed
893
pNames :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
894 895 896
pNames =
  withDoc "List of names" .
  defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
897 898

pNodes :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
899 900 901
pNodes =
  withDoc "List of nodes" .
  defaultField [| [] |] $ simpleField "nodes" [t| [NonEmptyString] |]
Iustin Pop's avatar
Iustin Pop committed
902 903

pStorageType :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
904 905 906 907 908 909 910 911 912
pStorageType =
  withDoc "Storage type" $
  simpleField "storage_type" [t| StorageType |]

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

pStorageChanges :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
915 916 917 918 919 920 921 922
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
923 924

pMasterCandidate :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
925 926 927
pMasterCandidate =
  withDoc "Whether the node should become a master candidate" .
  optionalField $ booleanField "master_candidate"
Iustin Pop's avatar
Iustin Pop committed
928 929

pOffline :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
930 931 932
pOffline =
  withDoc "Whether to mark the node or instance offline" .
  optionalField $ booleanField "offline"
Iustin Pop's avatar
Iustin Pop committed
933 934

pDrained ::Field
Jose A. Lopes's avatar
Jose A. Lopes committed
935 936 937
pDrained =
  withDoc "Whether to mark the node as drained" .
  optionalField $ booleanField "drained"
Iustin Pop's avatar
Iustin Pop committed
938 939

pAutoPromote :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
940 941 942 943
pAutoPromote =
  withDoc "Whether node(s) should be promoted to master candidate if\
          \ necessary" $
  defaultFalse "auto_promote"
Iustin Pop's avatar
Iustin Pop committed
944 945

pPowered :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
946 947 948
pPowered =
  withDoc "Whether the node should be marked as powered" .
  optionalField $ booleanField "powered"
Iustin Pop's avatar
Iustin Pop committed
949

Jose A. Lopes's avatar
Jose A. Lopes committed
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
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
982
pIallocator :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
983 984 985 986 987 988 989 990 991
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
992 993

pRemoteNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
994 995 996
pRemoteNode =
  withDoc "New secondary node" $
  optionalNEStringField "remote_node"
Iustin Pop's avatar
Iustin Pop committed
997

Thomas Thrainer's avatar
Thomas Thrainer committed
998
pRemoteNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
999 1000 1001
pRemoteNodeUuid =
  withDoc "New secondary node UUID" $
  optionalNEStringField "remote_node_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
1002

Iustin Pop's avatar
Iustin Pop committed
1003
pEvacMode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
pEvacMode =
  withDoc "Node evacuation mode" .
  renameField "EvacMode" $ simpleField "mode" [t| NodeEvacMode |]

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 =
  withDoc "List of instance disks" $
  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"
1082 1083 1084

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

Jose A. Lopes's avatar
Jose A. Lopes committed
1088 1089 1090 1091 1092
pInstNics :: Field
pInstNics =
  withDoc "List of NIC (network interface) definitions" $
  simpleField "nics" [t| [INicParams] |]

1093
pNoInstall :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1094 1095 1096
pNoInstall =
  withDoc "Do not install the OS (will disable automatic start)" .
  optionalField $ booleanField "no_install"
1097 1098

pInstOs :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
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 |]
1109 1110

pPrimaryNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1111 1112 1113
pPrimaryNode =
  withDoc "Primary node for an instance" $
  optionalNEStringField "pnode"
1114

Thomas Thrainer's avatar
Thomas Thrainer committed
1115
pPrimaryNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1116 1117 1118
pPrimaryNodeUuid =
  withDoc "Primary node UUID for an instance" $
  optionalNEStringField "pnode_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
1119

1120
pSecondaryNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1121 1122 1123
pSecondaryNode =
  withDoc "Secondary node for an instance" $
  optionalNEStringField "snode"
1124

Thomas Thrainer's avatar
Thomas Thrainer committed
1125
pSecondaryNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1126 1127 1128
pSecondaryNodeUuid =
  withDoc "Secondary node UUID for an instance" $
  optionalNEStringField "snode_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
1129

1130 1131
pSourceHandshake :: Field
pSourceHandshake =
Jose A. Lopes's avatar
Jose A. Lopes committed
1132 1133
  withDoc "Signed handshake from source (remote import only)" .
  optionalField $ simpleField "source_handshake" [t| [JSValue] |]
1134 1135

pSourceInstance :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1136 1137 1138
pSourceInstance =
  withDoc "Source instance name (remote import only)" $
  optionalNEStringField "source_instance_name"
1139 1140 1141 1142

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

pSourceX509Ca :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1149 1150 1151
pSourceX509Ca =
  withDoc "Source X509 CA in PEM format (remote import only)" $
  optionalNEStringField "source_x509_ca"
1152 1153

pSrcNode :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1154 1155 1156
pSrcNode =
  withDoc "Source node for import" $
  optionalNEStringField "src_node"
1157

Thomas Thrainer's avatar
Thomas Thrainer committed
1158
pSrcNodeUuid :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1159 1160 1161
pSrcNodeUuid =
  withDoc "Source node UUID for import" $
  optionalNEStringField "src_node_uuid"
Thomas Thrainer's avatar
Thomas Thrainer committed
1162

1163
pSrcPath :: Field
Jose A. Lopes's avatar
Jose A. Lopes committed
1164 1165 1166
pSrcPath =
  withDoc "Source directory for import" $
  optionalNEStringField "src_path"
1167 1168

pStartInstance :: Field