1 {-# LANGUAGE TemplateHaskell #-}
3 {-| Implementation of opcodes parameters.
5 These are defined in a separate module only due to TemplateHaskell
6 stage restrictions - expressions defined in the current module can't
7 be passed to splices. So we have to either parameters/repeat each
8 parameter definition multiple times, or separate them into this
15 Copyright (C) 2012 Google Inc.
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
22 This program is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34 module Ganeti.OpParams
41 , ReplaceDisksMode(..)
48 , RecreateDisksInfo(..)
75 , pOpportunisticLocking
77 , pNodeGroupAllocPolicy
84 , pMigrationTargetNode
88 , pDebugSimulateErrors
105 , pEnabledHypervisors
119 , pMaintainNodeHealth
133 , pUseExternalMipScript
166 , pSourceShutdownTimeout
172 , pMultiAllocInstances
183 , pInstParamsNicChanges
184 , pInstParamsDiskChanges
194 , pIgnoreRemoveFailures
206 , pIAllocatorDirection
214 , pIAllocatorInstances
215 , pIAllocatorEvacMode
216 , pIAllocatorSpindleUse
218 , pJQueueNotifyWaitLock
225 , pTestDummySubmitJobs
233 , pNetworkRemoveRsvdIps
242 , pEnabledDiskTemplates
247 import Control.Monad (liftM)
248 import qualified Data.Set as Set
249 import Text.JSON (readJSON, showJSON, JSON, JSValue(..), fromJSString,
250 JSObject, toJSObject)
251 import qualified Text.JSON
252 import Text.JSON.Pretty (pp_value)
254 import Ganeti.BasicTypes
255 import qualified Ganeti.Constants as C
259 import qualified Ganeti.Query.Language as Qlang
261 -- * Helper functions and types
265 -- | Build a boolean field.
266 booleanField :: String -> Field
267 booleanField = flip simpleField [t| Bool |]
269 -- | Default a field to 'False'.
270 defaultFalse :: String -> Field
271 defaultFalse = defaultField [| False |] . booleanField
273 -- | Default a field to 'True'.
274 defaultTrue :: String -> Field
275 defaultTrue = defaultField [| True |] . booleanField
277 -- | An alias for a 'String' field.
278 stringField :: String -> Field
279 stringField = flip simpleField [t| String |]
281 -- | An alias for an optional string field.
282 optionalStringField :: String -> Field
283 optionalStringField = optionalField . stringField
285 -- | An alias for an optional non-empty string field.
286 optionalNEStringField :: String -> Field
287 optionalNEStringField = optionalField . flip simpleField [t| NonEmptyString |]
289 -- | Unchecked value, should be replaced by a better definition.
290 type UncheckedValue = JSValue
292 -- | Unchecked dict, should be replaced by a better definition.
293 type UncheckedDict = JSObject JSValue
295 -- | Unchecked list, shoild be replaced by a better definition.
296 type UncheckedList = [JSValue]
298 -- | Function to force a non-negative value, without returning via a
299 -- monad. This is needed for, and should be used /only/ in the case of
300 -- forcing constants. In case the constant is wrong (< 0), this will
301 -- become a runtime error.
302 forceNonNeg :: (Num a, Ord a, Show a) => a -> NonNegative a
303 forceNonNeg i = case mkNonNegative i of
309 -- | Data type representing what items do the tag operations apply to.
310 $(declareSADT "TagType"
311 [ ("TagTypeInstance", 'C.tagInstance)
312 , ("TagTypeNode", 'C.tagNode)
313 , ("TagTypeGroup", 'C.tagNodegroup)
314 , ("TagTypeCluster", 'C.tagCluster)
316 $(makeJSONInstance ''TagType)
318 -- | Data type holding a tag object (type and object name).
319 data TagObject = TagInstance String
325 -- | Tag type for a given tag object.
326 tagTypeOf :: TagObject -> TagType
327 tagTypeOf (TagInstance {}) = TagTypeInstance
328 tagTypeOf (TagNode {}) = TagTypeNode
329 tagTypeOf (TagGroup {}) = TagTypeGroup
330 tagTypeOf (TagCluster {}) = TagTypeCluster
332 -- | Gets the potential tag object name.
333 tagNameOf :: TagObject -> Maybe String
334 tagNameOf (TagInstance s) = Just s
335 tagNameOf (TagNode s) = Just s
336 tagNameOf (TagGroup s) = Just s
337 tagNameOf TagCluster = Nothing
339 -- | Builds a 'TagObject' from a tag type and name.
340 tagObjectFrom :: (Monad m) => TagType -> JSValue -> m TagObject
341 tagObjectFrom TagTypeInstance (JSString s) =
342 return . TagInstance $ fromJSString s
343 tagObjectFrom TagTypeNode (JSString s) = return . TagNode $ fromJSString s
344 tagObjectFrom TagTypeGroup (JSString s) = return . TagGroup $ fromJSString s
345 tagObjectFrom TagTypeCluster JSNull = return TagCluster
347 fail $ "Invalid tag type/name combination: " ++ show t ++ "/" ++
350 -- | Name of the tag \"name\" field.
351 tagNameField :: String
352 tagNameField = "name"
354 -- | Custom encoder for 'TagObject' as represented in an opcode.
355 encodeTagObject :: TagObject -> (JSValue, [(String, JSValue)])
356 encodeTagObject t = ( showJSON (tagTypeOf t)
357 , [(tagNameField, maybe JSNull showJSON (tagNameOf t))] )
359 -- | Custom decoder for 'TagObject' as represented in an opcode.
360 decodeTagObject :: (Monad m) => [(String, JSValue)] -> JSValue -> m TagObject
361 decodeTagObject obj kind = do
362 ttype <- fromJVal kind
363 tname <- fromObj obj tagNameField
364 tagObjectFrom ttype tname
368 -- | Replace disks type.
369 $(declareSADT "ReplaceDisksMode"
370 [ ("ReplaceOnPrimary", 'C.replaceDiskPri)
371 , ("ReplaceOnSecondary", 'C.replaceDiskSec)
372 , ("ReplaceNewSecondary", 'C.replaceDiskChg)
373 , ("ReplaceAuto", 'C.replaceDiskAuto)
375 $(makeJSONInstance ''ReplaceDisksMode)
377 -- | Disk index type (embedding constraints on the index value via a
378 -- smart constructor).
379 newtype DiskIndex = DiskIndex { unDiskIndex :: Int }
380 deriving (Show, Eq, Ord)
382 -- | Smart constructor for 'DiskIndex'.
383 mkDiskIndex :: (Monad m) => Int -> m DiskIndex
384 mkDiskIndex i | i >= 0 && i < C.maxDisks = return (DiskIndex i)
385 | otherwise = fail $ "Invalid value for disk index '" ++
386 show i ++ "', required between 0 and " ++
389 instance JSON DiskIndex where
390 readJSON v = readJSON v >>= mkDiskIndex
391 showJSON = showJSON . unDiskIndex
395 -- | Type holding disk access modes.
396 $(declareSADT "DiskAccess"
397 [ ("DiskReadOnly", 'C.diskRdonly)
398 , ("DiskReadWrite", 'C.diskRdwr)
400 $(makeJSONInstance ''DiskAccess)
402 -- | NIC modification definition.
403 $(buildObject "INicParams" "inic"
404 [ optionalField $ simpleField C.inicMac [t| NonEmptyString |]
405 , optionalField $ simpleField C.inicIp [t| String |]
406 , optionalField $ simpleField C.inicMode [t| NonEmptyString |]
407 , optionalField $ simpleField C.inicLink [t| NonEmptyString |]
408 , optionalField $ simpleField C.inicName [t| NonEmptyString |]
411 -- | Disk modification definition. FIXME: disksize should be VTYPE_UNIT.
412 $(buildObject "IDiskParams" "idisk"
413 [ optionalField $ simpleField C.idiskSize [t| Int |]
414 , optionalField $ simpleField C.idiskMode [t| DiskAccess |]
415 , optionalField $ simpleField C.idiskAdopt [t| NonEmptyString |]
416 , optionalField $ simpleField C.idiskVg [t| NonEmptyString |]
417 , optionalField $ simpleField C.idiskMetavg [t| NonEmptyString |]
418 , optionalField $ simpleField C.idiskName [t| NonEmptyString |]
421 -- | Disk changes type for OpInstanceRecreateDisks. This is a bit
422 -- strange, because the type in Python is something like Either
423 -- [DiskIndex] [DiskChanges], but we can't represent the type of an
424 -- empty list in JSON, so we have to add a custom case for the empty
426 data RecreateDisksInfo
428 | RecreateDisksIndices (NonEmpty DiskIndex)
429 | RecreateDisksParams (NonEmpty (DiskIndex, IDiskParams))
432 readRecreateDisks :: JSValue -> Text.JSON.Result RecreateDisksInfo
433 readRecreateDisks (JSArray []) = return RecreateDisksAll
434 readRecreateDisks v =
435 case readJSON v::Text.JSON.Result [DiskIndex] of
436 Text.JSON.Ok indices -> liftM RecreateDisksIndices (mkNonEmpty indices)
437 _ -> case readJSON v::Text.JSON.Result [(DiskIndex, IDiskParams)] of
438 Text.JSON.Ok params -> liftM RecreateDisksParams (mkNonEmpty params)
439 _ -> fail $ "Can't parse disk information as either list of disk"
440 ++ " indices or list of disk parameters; value received:"
443 instance JSON RecreateDisksInfo where
444 readJSON = readRecreateDisks
445 showJSON RecreateDisksAll = showJSON ()
446 showJSON (RecreateDisksIndices idx) = showJSON idx
447 showJSON (RecreateDisksParams params) = showJSON params
449 -- | Simple type for old-style ddm changes.
450 data DdmOldChanges = DdmOldIndex (NonNegative Int)
451 | DdmOldMod DdmSimple
454 readDdmOldChanges :: JSValue -> Text.JSON.Result DdmOldChanges
455 readDdmOldChanges v =
456 case readJSON v::Text.JSON.Result (NonNegative Int) of
457 Text.JSON.Ok nn -> return $ DdmOldIndex nn
458 _ -> case readJSON v::Text.JSON.Result DdmSimple of
459 Text.JSON.Ok ddms -> return $ DdmOldMod ddms
460 _ -> fail $ "Can't parse value '" ++ show (pp_value v) ++ "' as"
461 ++ " either index or modification"
463 instance JSON DdmOldChanges where
464 showJSON (DdmOldIndex i) = showJSON i
465 showJSON (DdmOldMod m) = showJSON m
466 readJSON = readDdmOldChanges
468 -- | Instance disk or nic modifications.
471 | SetParamsDeprecated (NonEmpty (DdmOldChanges, a))
472 | SetParamsNew (NonEmpty (DdmFull, Int, a))
475 -- | Custom deserialiser for 'SetParamsMods'.
476 readSetParams :: (JSON a) => JSValue -> Text.JSON.Result (SetParamsMods a)
477 readSetParams (JSArray []) = return SetParamsEmpty
479 case readJSON v::Text.JSON.Result [(DdmOldChanges, JSValue)] of
480 Text.JSON.Ok _ -> liftM SetParamsDeprecated $ readJSON v
481 _ -> liftM SetParamsNew $ readJSON v
483 instance (JSON a) => JSON (SetParamsMods a) where
484 showJSON SetParamsEmpty = showJSON ()
485 showJSON (SetParamsDeprecated v) = showJSON v
486 showJSON (SetParamsNew v) = showJSON v
487 readJSON = readSetParams
489 -- | Custom type for target_node parameter of OpBackupExport, which
490 -- varies depending on mode. FIXME: this uses an UncheckedList since
491 -- we don't care about individual rows (just like the Python code
492 -- tests). But the proper type could be parsed if we wanted.
493 data ExportTarget = ExportTargetLocal NonEmptyString
494 | ExportTargetRemote UncheckedList
497 -- | Custom reader for 'ExportTarget'.
498 readExportTarget :: JSValue -> Text.JSON.Result ExportTarget
499 readExportTarget (JSString s) = liftM ExportTargetLocal $
500 mkNonEmpty (fromJSString s)
501 readExportTarget (JSArray arr) = return $ ExportTargetRemote arr
502 readExportTarget v = fail $ "Invalid value received for 'target_node': " ++
505 instance JSON ExportTarget where
506 showJSON (ExportTargetLocal s) = showJSON s
507 showJSON (ExportTargetRemote l) = showJSON l
508 readJSON = readExportTarget
512 -- | A required instance name (for single-instance LUs).
513 pInstanceName :: Field
514 pInstanceName = simpleField "instance_name" [t| String |]
516 -- | A list of instances.
518 pInstances = defaultField [| [] |] $
519 simpleField "instances" [t| [NonEmptyString] |]
523 pName = simpleField "name" [t| NonEmptyString |]
527 pTagsList = simpleField "tags" [t| [String] |]
532 customField 'decodeTagObject 'encodeTagObject [tagNameField] $
533 simpleField "kind" [t| TagObject |]
535 -- | Selected output fields.
536 pOutputFields :: Field
537 pOutputFields = simpleField "output_fields" [t| [NonEmptyString] |]
539 -- | How long to wait for instance to shut down.
540 pShutdownTimeout :: Field
541 pShutdownTimeout = defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
542 simpleField "shutdown_timeout" [t| NonNegative Int |]
544 -- | Another name for the shutdown timeout, because we like to be
546 pShutdownTimeout' :: Field
548 renameField "InstShutdownTimeout" .
549 defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
550 simpleField "timeout" [t| NonNegative Int |]
552 -- | Whether to shutdown the instance in backup-export.
553 pShutdownInstance :: Field
554 pShutdownInstance = defaultTrue "shutdown"
556 -- | Whether to force the operation.
558 pForce = defaultFalse "force"
560 -- | Whether to ignore offline nodes.
561 pIgnoreOfflineNodes :: Field
562 pIgnoreOfflineNodes = defaultFalse "ignore_offline_nodes"
564 -- | A required node name (for single-node LUs).
566 pNodeName = simpleField "node_name" [t| NonEmptyString |]
571 defaultField [| [] |] $ simpleField "node_names" [t| [NonEmptyString] |]
573 -- | A required node group name (for single-group LUs).
575 pGroupName = simpleField "group_name" [t| NonEmptyString |]
577 -- | Migration type (live\/non-live).
578 pMigrationMode :: Field
580 renameField "MigrationMode" .
582 simpleField "mode" [t| MigrationMode |]
584 -- | Obsolete \'live\' migration mode (boolean).
585 pMigrationLive :: Field
587 renameField "OldLiveMode" . optionalField $ booleanField "live"
589 -- | Migration cleanup parameter.
590 pMigrationCleanup :: Field
591 pMigrationCleanup = renameField "MigrationCleanup" $ defaultFalse "cleanup"
593 -- | Whether to force an unknown OS variant.
594 pForceVariant :: Field
595 pForceVariant = defaultFalse "force_variant"
597 -- | Whether to wait for the disk to synchronize.
598 pWaitForSync :: Field
599 pWaitForSync = defaultTrue "wait_for_sync"
601 -- | Whether to wait for the disk to synchronize (defaults to false).
602 pWaitForSyncFalse :: Field
603 pWaitForSyncFalse = defaultField [| False |] pWaitForSync
605 -- | Whether to ignore disk consistency
606 pIgnoreConsistency :: Field
607 pIgnoreConsistency = defaultFalse "ignore_consistency"
610 pStorageName :: Field
612 renameField "StorageName" $ simpleField "name" [t| NonEmptyString |]
614 -- | Whether to use synchronization.
616 pUseLocking = defaultFalse "use_locking"
618 -- | Whether to employ opportunistic locking for nodes, meaning nodes already
619 -- locked by another opcode won't be considered for instance allocation (only
620 -- when an iallocator is used).
621 pOpportunisticLocking :: Field
622 pOpportunisticLocking = defaultFalse "opportunistic_locking"
624 -- | Whether to check name.
626 pNameCheck = defaultTrue "name_check"
628 -- | Instance allocation policy.
629 pNodeGroupAllocPolicy :: Field
630 pNodeGroupAllocPolicy = optionalField $
631 simpleField "alloc_policy" [t| AllocPolicy |]
633 -- | Default node parameters for group.
634 pGroupNodeParams :: Field
635 pGroupNodeParams = optionalField $ simpleField "ndparams" [t| UncheckedDict |]
637 -- | Resource(s) to query for.
639 pQueryWhat = simpleField "what" [t| Qlang.QueryTypeOp |]
641 -- | Whether to release locks as soon as possible.
642 pEarlyRelease :: Field
643 pEarlyRelease = defaultFalse "early_release"
645 -- | Whether to ensure instance's IP address is inactive.
647 pIpCheck = defaultTrue "ip_check"
649 -- | Check for conflicting IPs.
650 pIpConflictsCheck :: Field
651 pIpConflictsCheck = defaultTrue "conflicts_check"
653 -- | Do not remember instance state changes.
655 pNoRemember = defaultFalse "no_remember"
657 -- | Target node for instance migration/failover.
658 pMigrationTargetNode :: Field
659 pMigrationTargetNode = optionalNEStringField "target_node"
661 -- | Target node for instance move (required).
662 pMoveTargetNode :: Field
664 renameField "MoveTargetNode" $
665 simpleField "target_node" [t| NonEmptyString |]
667 -- | Pause instance at startup.
668 pStartupPaused :: Field
669 pStartupPaused = defaultFalse "startup_paused"
673 pVerbose = defaultFalse "verbose"
675 -- ** Parameters for cluster verification
677 -- | Whether to simulate errors (useful for debugging).
678 pDebugSimulateErrors :: Field
679 pDebugSimulateErrors = defaultFalse "debug_simulate_errors"
683 pErrorCodes = defaultFalse "error_codes"
685 -- | Which checks to skip.
687 pSkipChecks = defaultField [| Set.empty |] $
688 simpleField "skip_checks" [t| Set.Set VerifyOptionalChecks |]
690 -- | List of error codes that should be treated as warnings.
691 pIgnoreErrors :: Field
692 pIgnoreErrors = defaultField [| Set.empty |] $
693 simpleField "ignore_errors" [t| Set.Set CVErrorCode |]
695 -- | Optional group name.
696 pOptGroupName :: Field
697 pOptGroupName = renameField "OptGroupName" .
698 optionalField $ simpleField "group_name" [t| NonEmptyString |]
700 -- | Disk templates' parameter defaults.
702 pDiskParams = optionalField $
703 simpleField "diskparams" [t| GenericContainer DiskTemplate
706 -- | Whether to hotplug device.
708 pHotplug = defaultFalse "hotplug"
710 -- * Parameters for node resource model
712 -- | Set hypervisor states.
714 pHvState = optionalField $ simpleField "hv_state" [t| UncheckedDict |]
716 -- | Set disk states.
718 pDiskState = optionalField $ simpleField "disk_state" [t| UncheckedDict |]
720 -- | Whether to ignore ipolicy violations.
721 pIgnoreIpolicy :: Field
722 pIgnoreIpolicy = defaultFalse "ignore_ipolicy"
724 -- | Allow runtime changes while migrating.
725 pAllowRuntimeChgs :: Field
726 pAllowRuntimeChgs = defaultTrue "allow_runtime_changes"
728 -- | Utility type for OpClusterSetParams.
729 type TestClusterOsListItem = (DdmSimple, NonEmptyString)
731 -- | Utility type of OsList.
732 type TestClusterOsList = [TestClusterOsListItem]
734 -- Utility type for NIC definitions.
735 --type TestNicDef = INicParams
737 -- | List of instance disks.
739 pInstDisks = renameField "instDisks" $ simpleField "disks" [t| [IDiskParams] |]
741 -- | Instance disk template.
742 pDiskTemplate :: Field
743 pDiskTemplate = simpleField "disk_template" [t| DiskTemplate |]
745 -- | Instance disk template.
746 pOptDiskTemplate :: Field
749 renameField "OptDiskTemplate" $
750 simpleField "disk_template" [t| DiskTemplate |]
754 pFileDriver = optionalField $ simpleField "file_driver" [t| FileDriver |]
756 -- | Directory for storing file-backed disks.
757 pFileStorageDir :: Field
758 pFileStorageDir = optionalNEStringField "file_storage_dir"
760 -- | Volume group name.
762 pVgName = optionalStringField "vg_name"
764 -- | List of enabled hypervisors.
765 pEnabledHypervisors :: Field
766 pEnabledHypervisors =
768 simpleField "enabled_hypervisors" [t| NonEmpty Hypervisor |]
770 -- | List of enabled disk templates.
771 pEnabledDiskTemplates :: Field
772 pEnabledDiskTemplates =
774 simpleField "enabled_disk_templates" [t| NonEmpty DiskTemplate |]
776 -- | Selected hypervisor for an instance.
780 simpleField "hypervisor" [t| Hypervisor |]
782 -- | Cluster-wide hypervisor parameters, hypervisor-dependent.
783 pClusterHvParams :: Field
785 renameField "ClusterHvParams" .
787 simpleField "hvparams" [t| Container UncheckedDict |]
789 -- | Instance hypervisor parameters.
790 pInstHvParams :: Field
792 renameField "InstHvParams" .
793 defaultField [| toJSObject [] |] $
794 simpleField "hvparams" [t| UncheckedDict |]
796 -- | Cluster-wide beparams.
797 pClusterBeParams :: Field
799 renameField "ClusterBeParams" .
800 optionalField $ simpleField "beparams" [t| UncheckedDict |]
802 -- | Instance beparams.
803 pInstBeParams :: Field
805 renameField "InstBeParams" .
806 defaultField [| toJSObject [] |] $
807 simpleField "beparams" [t| UncheckedDict |]
809 -- | Reset instance parameters to default if equal.
810 pResetDefaults :: Field
811 pResetDefaults = defaultFalse "identify_defaults"
813 -- | Cluster-wide per-OS hypervisor parameter defaults.
815 pOsHvp = optionalField $ simpleField "os_hvp" [t| Container UncheckedDict |]
817 -- | Cluster-wide OS parameter defaults.
818 pClusterOsParams :: Field
820 renameField "ClusterOsParams" .
821 optionalField $ simpleField "osparams" [t| Container UncheckedDict |]
823 -- | Instance OS parameters.
824 pInstOsParams :: Field
826 renameField "InstOsParams" . defaultField [| toJSObject [] |] $
827 simpleField "osparams" [t| UncheckedDict |]
829 -- | Temporary OS parameters (currently only in reinstall, might be
830 -- added to install as well).
831 pTempOsParams :: Field
833 renameField "TempOsParams" .
834 optionalField $ simpleField "osparams" [t| UncheckedDict |]
836 -- | Temporary hypervisor parameters, hypervisor-dependent.
837 pTempHvParams :: Field
839 renameField "TempHvParams" .
840 defaultField [| toJSObject [] |] $
841 simpleField "hvparams" [t| UncheckedDict |]
843 -- | Temporary backend parameters.
844 pTempBeParams :: Field
846 renameField "TempBeParams" .
847 defaultField [| toJSObject [] |] $
848 simpleField "beparams" [t| UncheckedDict |]
850 -- | Candidate pool size.
851 pCandidatePoolSize :: Field
853 optionalField $ simpleField "candidate_pool_size" [t| Positive Int |]
855 -- | Set UID pool, must be list of lists describing UID ranges (two
856 -- items, start and end inclusive.
858 pUidPool = optionalField $ simpleField "uid_pool" [t| [[(Int, Int)]] |]
860 -- | Extend UID pool, must be list of lists describing UID ranges (two
861 -- items, start and end inclusive.
863 pAddUids = optionalField $ simpleField "add_uids" [t| [[(Int, Int)]] |]
865 -- | Shrink UID pool, must be list of lists describing UID ranges (two
866 -- items, start and end inclusive) to be removed.
868 pRemoveUids = optionalField $ simpleField "remove_uids" [t| [[(Int, Int)]] |]
870 -- | Whether to automatically maintain node health.
871 pMaintainNodeHealth :: Field
872 pMaintainNodeHealth = optionalField $ booleanField "maintain_node_health"
874 -- | Whether to modify and keep in sync the @/etc/hosts@ files of nodes.
875 pModifyEtcHosts :: Field
876 pModifyEtcHosts = optionalField $ booleanField "modify_etc_hosts"
878 -- | Whether to wipe disks before allocating them to instances.
879 pPreallocWipeDisks :: Field
880 pPreallocWipeDisks = optionalField $ booleanField "prealloc_wipe_disks"
882 -- | Cluster-wide NIC parameter defaults.
884 pNicParams = optionalField $ simpleField "nicparams" [t| INicParams |]
886 -- | Instance NIC definitions.
888 pInstNics = simpleField "nics" [t| [INicParams] |]
890 -- | Cluster-wide node parameter defaults.
892 pNdParams = optionalField $ simpleField "ndparams" [t| UncheckedDict |]
894 -- | Cluster-wide ipolicy specs.
896 pIpolicy = optionalField $ simpleField "ipolicy" [t| UncheckedDict |]
898 -- | DRBD helper program.
900 pDrbdHelper = optionalStringField "drbd_helper"
902 -- | Default iallocator for cluster.
903 pDefaultIAllocator :: Field
904 pDefaultIAllocator = optionalStringField "default_iallocator"
906 -- | Master network device.
907 pMasterNetdev :: Field
908 pMasterNetdev = optionalStringField "master_netdev"
910 -- | Netmask of the master IP.
911 pMasterNetmask :: Field
913 optionalField $ simpleField "master_netmask" [t| NonNegative Int |]
915 -- | List of reserved LVs.
916 pReservedLvs :: Field
918 optionalField $ simpleField "reserved_lvs" [t| [NonEmptyString] |]
920 -- | Modify list of hidden operating systems: each modification must
921 -- have two items, the operation and the OS name; the operation can be
924 pHiddenOs = optionalField $ simpleField "hidden_os" [t| TestClusterOsList |]
926 -- | Modify list of blacklisted operating systems: each modification
927 -- must have two items, the operation and the OS name; the operation
928 -- can be add or remove.
929 pBlacklistedOs :: Field
931 optionalField $ simpleField "blacklisted_os" [t| TestClusterOsList |]
933 -- | Whether to use an external master IP address setup script.
934 pUseExternalMipScript :: Field
935 pUseExternalMipScript = optionalField $ booleanField "use_external_mip_script"
937 -- | Requested fields.
938 pQueryFields :: Field
939 pQueryFields = simpleField "fields" [t| [NonEmptyString] |]
942 pQueryFilter :: Field
943 pQueryFilter = simpleField "qfilter" [t| Qlang.Filter String |]
945 -- | OOB command to run.
947 pOobCommand = simpleField "command" [t| OobCommand |]
949 -- | Timeout before the OOB helper will be terminated.
952 defaultField [| C.oobTimeout |] $ simpleField "timeout" [t| Int |]
954 -- | Ignores the node offline status for power off.
955 pIgnoreStatus :: Field
956 pIgnoreStatus = defaultFalse "ignore_status"
958 -- | Time in seconds to wait between powering on nodes.
961 -- FIXME: we can't use the proper type "NonNegative Double", since
962 -- the default constant is a plain Double, not a non-negative one.
963 defaultField [| C.oobPowerDelay |] $
964 simpleField "power_delay" [t| Double |]
966 -- | Primary IP address.
968 pPrimaryIp = optionalStringField "primary_ip"
970 -- | Secondary IP address.
971 pSecondaryIp :: Field
972 pSecondaryIp = optionalNEStringField "secondary_ip"
974 -- | Whether node is re-added to cluster.
976 pReadd = defaultFalse "readd"
978 -- | Initial node group.
980 pNodeGroup = optionalNEStringField "group"
982 -- | Whether node can become master or master candidate.
983 pMasterCapable :: Field
984 pMasterCapable = optionalField $ booleanField "master_capable"
986 -- | Whether node can host instances.
988 pVmCapable = optionalField $ booleanField "vm_capable"
992 pNames = defaultField [| [] |] $ simpleField "names" [t| [NonEmptyString] |]
994 -- | List of node names.
996 pNodes = defaultField [| [] |] $ simpleField "nodes" [t| [NonEmptyString] |]
998 -- | Required list of node names.
999 pRequiredNodes :: Field
1001 renameField "ReqNodes " $ simpleField "nodes" [t| [NonEmptyString] |]
1004 pStorageType :: Field
1005 pStorageType = simpleField "storage_type" [t| StorageType |]
1007 -- | Storage changes (unchecked).
1008 pStorageChanges :: Field
1009 pStorageChanges = simpleField "changes" [t| UncheckedDict |]
1011 -- | Whether the node should become a master candidate.
1012 pMasterCandidate :: Field
1013 pMasterCandidate = optionalField $ booleanField "master_candidate"
1015 -- | Whether the node should be marked as offline.
1017 pOffline = optionalField $ booleanField "offline"
1019 -- | Whether the node should be marked as drained.
1021 pDrained = optionalField $ booleanField "drained"
1023 -- | Whether node(s) should be promoted to master candidate if necessary.
1024 pAutoPromote :: Field
1025 pAutoPromote = defaultFalse "auto_promote"
1027 -- | Whether the node should be marked as powered
1029 pPowered = optionalField $ booleanField "powered"
1031 -- | Iallocator for deciding the target node for shared-storage
1032 -- instances during migrate and failover.
1033 pIallocator :: Field
1034 pIallocator = optionalNEStringField "iallocator"
1036 -- | New secondary node.
1037 pRemoteNode :: Field
1038 pRemoteNode = optionalNEStringField "remote_node"
1040 -- | Node evacuation mode.
1042 pEvacMode = renameField "EvacMode" $ simpleField "mode" [t| NodeEvacMode |]
1044 -- | Instance creation mode.
1045 pInstCreateMode :: Field
1047 renameField "InstCreateMode" $ simpleField "mode" [t| InstCreateMode |]
1049 -- | Do not install the OS (will disable automatic start).
1051 pNoInstall = optionalField $ booleanField "no_install"
1053 -- | OS type for instance installation.
1055 pInstOs = optionalNEStringField "os_type"
1057 -- | Primary node for an instance.
1058 pPrimaryNode :: Field
1059 pPrimaryNode = optionalNEStringField "pnode"
1061 -- | Secondary node for an instance.
1062 pSecondaryNode :: Field
1063 pSecondaryNode = optionalNEStringField "snode"
1065 -- | Signed handshake from source (remote import only).
1066 pSourceHandshake :: Field
1068 optionalField $ simpleField "source_handshake" [t| UncheckedList |]
1070 -- | Source instance name (remote import only).
1071 pSourceInstance :: Field
1072 pSourceInstance = optionalNEStringField "source_instance_name"
1074 -- | How long source instance was given to shut down (remote import only).
1075 -- FIXME: non-negative int, whereas the constant is a plain int.
1076 pSourceShutdownTimeout :: Field
1077 pSourceShutdownTimeout =
1078 defaultField [| forceNonNeg C.defaultShutdownTimeout |] $
1079 simpleField "source_shutdown_timeout" [t| NonNegative Int |]
1081 -- | Source X509 CA in PEM format (remote import only).
1082 pSourceX509Ca :: Field
1083 pSourceX509Ca = optionalNEStringField "source_x509_ca"
1085 -- | Source node for import.
1087 pSrcNode = optionalNEStringField "src_node"
1089 -- | Source directory for import.
1091 pSrcPath = optionalNEStringField "src_path"
1093 -- | Whether to start instance after creation.
1094 pStartInstance :: Field
1095 pStartInstance = defaultTrue "start"
1097 -- | Instance tags. FIXME: unify/simplify with pTags, once that
1098 -- migrates to NonEmpty String.
1101 renameField "InstTags" .
1102 defaultField [| [] |] $
1103 simpleField "tags" [t| [NonEmptyString] |]
1105 -- | Unchecked list of OpInstanceCreate, used in OpInstanceMultiAlloc.
1106 pMultiAllocInstances :: Field
1107 pMultiAllocInstances =
1108 renameField "InstMultiAlloc" .
1109 defaultField [| [] |] $
1110 simpleField "instances"[t| UncheckedList |]
1112 -- | Ignore failures parameter.
1113 pIgnoreFailures :: Field
1114 pIgnoreFailures = defaultFalse "ignore_failures"
1116 -- | New instance or cluster name.
1118 pNewName = simpleField "new_name" [t| NonEmptyString |]
1120 -- | Whether to start the instance even if secondary disks are failing.
1121 pIgnoreSecondaries :: Field
1122 pIgnoreSecondaries = defaultFalse "ignore_secondaries"
1124 -- | How to reboot the instance.
1125 pRebootType :: Field
1126 pRebootType = simpleField "reboot_type" [t| RebootType |]
1128 -- | Whether to ignore recorded disk size.
1129 pIgnoreDiskSize :: Field
1130 pIgnoreDiskSize = defaultFalse "ignore_size"
1132 -- | Disk list for recreate disks.
1133 pRecreateDisksInfo :: Field
1134 pRecreateDisksInfo =
1135 renameField "RecreateDisksInfo" .
1136 defaultField [| RecreateDisksAll |] $
1137 simpleField "disks" [t| RecreateDisksInfo |]
1139 -- | Whether to only return configuration data without querying nodes.
1141 pStatic = defaultFalse "static"
1143 -- | InstanceSetParams NIC changes.
1144 pInstParamsNicChanges :: Field
1145 pInstParamsNicChanges =
1146 renameField "InstNicChanges" .
1147 defaultField [| SetParamsEmpty |] $
1148 simpleField "nics" [t| SetParamsMods INicParams |]
1150 -- | InstanceSetParams Disk changes.
1151 pInstParamsDiskChanges :: Field
1152 pInstParamsDiskChanges =
1153 renameField "InstDiskChanges" .
1154 defaultField [| SetParamsEmpty |] $
1155 simpleField "disks" [t| SetParamsMods IDiskParams |]
1157 -- | New runtime memory.
1158 pRuntimeMem :: Field
1159 pRuntimeMem = optionalField $ simpleField "runtime_mem" [t| Positive Int |]
1161 -- | Change the instance's OS without reinstalling the instance
1162 pOsNameChange :: Field
1163 pOsNameChange = optionalNEStringField "os_name"
1165 -- | Disk index for e.g. grow disk.
1167 pDiskIndex = renameField "DiskIndex " $ simpleField "disk" [t| DiskIndex |]
1169 -- | Disk amount to add or grow to.
1170 pDiskChgAmount :: Field
1172 renameField "DiskChgAmount" $ simpleField "amount" [t| NonNegative Int |]
1174 -- | Whether the amount parameter is an absolute target or a relative one.
1175 pDiskChgAbsolute :: Field
1176 pDiskChgAbsolute = renameField "DiskChkAbsolute" $ defaultFalse "absolute"
1178 -- | Destination group names or UUIDs (defaults to \"all but current group\".
1179 pTargetGroups :: Field
1181 optionalField $ simpleField "target_groups" [t| [NonEmptyString] |]
1183 -- | Export mode field.
1184 pExportMode :: Field
1186 renameField "ExportMode" $ simpleField "mode" [t| ExportMode |]
1188 -- | Export target_node field, depends on mode.
1189 pExportTargetNode :: Field
1191 renameField "ExportTarget" $
1192 simpleField "target_node" [t| ExportTarget |]
1194 -- | Whether to remove instance after export.
1195 pRemoveInstance :: Field
1196 pRemoveInstance = defaultFalse "remove_instance"
1198 -- | Whether to ignore failures while removing instances.
1199 pIgnoreRemoveFailures :: Field
1200 pIgnoreRemoveFailures = defaultFalse "ignore_remove_failures"
1202 -- | Name of X509 key (remote export only).
1203 pX509KeyName :: Field
1204 pX509KeyName = optionalField $ simpleField "x509_key_name" [t| UncheckedList |]
1206 -- | Destination X509 CA (remote export only).
1207 pX509DestCA :: Field
1208 pX509DestCA = optionalNEStringField "destination_x509_ca"
1210 -- | Search pattern (regular expression). FIXME: this should be
1211 -- compiled at load time?
1212 pTagSearchPattern :: Field
1214 renameField "TagSearchPattern" $ simpleField "pattern" [t| NonEmptyString |]
1216 -- | Restricted command name.
1217 pRestrictedCommand :: Field
1218 pRestrictedCommand =
1219 renameField "RestrictedCommand" $
1220 simpleField "command" [t| NonEmptyString |]
1222 -- | Replace disks mode.
1223 pReplaceDisksMode :: Field
1225 renameField "ReplaceDisksMode" $ simpleField "mode" [t| ReplaceDisksMode |]
1227 -- | List of disk indices.
1228 pReplaceDisksList :: Field
1230 renameField "ReplaceDisksList" $ simpleField "disks" [t| [DiskIndex] |]
1232 -- | Whether do allow failover in migrations.
1233 pAllowFailover :: Field
1234 pAllowFailover = defaultFalse "allow_failover"
1236 -- * Test opcode parameters
1238 -- | Duration parameter for 'OpTestDelay'.
1239 pDelayDuration :: Field
1241 renameField "DelayDuration" $ simpleField "duration" [t| Double |]
1243 -- | on_master field for 'OpTestDelay'.
1244 pDelayOnMaster :: Field
1245 pDelayOnMaster = renameField "DelayOnMaster" $ defaultTrue "on_master"
1247 -- | on_nodes field for 'OpTestDelay'.
1248 pDelayOnNodes :: Field
1250 renameField "DelayOnNodes" .
1251 defaultField [| [] |] $
1252 simpleField "on_nodes" [t| [NonEmptyString] |]
1254 -- | Repeat parameter for OpTestDelay.
1255 pDelayRepeat :: Field
1257 renameField "DelayRepeat" .
1258 defaultField [| forceNonNeg (0::Int) |] $
1259 simpleField "repeat" [t| NonNegative Int |]
1261 -- | IAllocator test direction.
1262 pIAllocatorDirection :: Field
1263 pIAllocatorDirection =
1264 renameField "IAllocatorDirection" $
1265 simpleField "direction" [t| IAllocatorTestDir |]
1267 -- | IAllocator test mode.
1268 pIAllocatorMode :: Field
1270 renameField "IAllocatorMode" $
1271 simpleField "mode" [t| IAllocatorMode |]
1273 -- | IAllocator target name (new instance, node to evac, etc.).
1274 pIAllocatorReqName :: Field
1275 pIAllocatorReqName =
1276 renameField "IAllocatorReqName" $ simpleField "name" [t| NonEmptyString |]
1278 -- | Custom OpTestIAllocator nics.
1279 pIAllocatorNics :: Field
1281 renameField "IAllocatorNics" $ simpleField "nics" [t| [UncheckedDict] |]
1283 -- | Custom OpTestAllocator disks.
1284 pIAllocatorDisks :: Field
1286 renameField "IAllocatorDisks" $ simpleField "disks" [t| UncheckedList |]
1288 -- | IAllocator memory field.
1289 pIAllocatorMemory :: Field
1291 renameField "IAllocatorMem" .
1293 simpleField "memory" [t| NonNegative Int |]
1295 -- | IAllocator vcpus field.
1296 pIAllocatorVCpus :: Field
1298 renameField "IAllocatorVCpus" .
1300 simpleField "vcpus" [t| NonNegative Int |]
1302 -- | IAllocator os field.
1303 pIAllocatorOs :: Field
1304 pIAllocatorOs = renameField "IAllocatorOs" $ optionalNEStringField "os"
1306 -- | IAllocator instances field.
1307 pIAllocatorInstances :: Field
1308 pIAllocatorInstances =
1309 renameField "IAllocatorInstances " .
1311 simpleField "instances" [t| [NonEmptyString] |]
1313 -- | IAllocator evac mode.
1314 pIAllocatorEvacMode :: Field
1315 pIAllocatorEvacMode =
1316 renameField "IAllocatorEvacMode" .
1318 simpleField "evac_mode" [t| NodeEvacMode |]
1320 -- | IAllocator spindle use.
1321 pIAllocatorSpindleUse :: Field
1322 pIAllocatorSpindleUse =
1323 renameField "IAllocatorSpindleUse" .
1324 defaultField [| forceNonNeg (1::Int) |] $
1325 simpleField "spindle_use" [t| NonNegative Int |]
1327 -- | IAllocator count field.
1328 pIAllocatorCount :: Field
1330 renameField "IAllocatorCount" .
1331 defaultField [| forceNonNeg (1::Int) |] $
1332 simpleField "count" [t| NonNegative Int |]
1334 -- | 'OpTestJqueue' notify_waitlock.
1335 pJQueueNotifyWaitLock :: Field
1336 pJQueueNotifyWaitLock = defaultFalse "notify_waitlock"
1338 -- | 'OpTestJQueue' notify_exec.
1339 pJQueueNotifyExec :: Field
1340 pJQueueNotifyExec = defaultFalse "notify_exec"
1342 -- | 'OpTestJQueue' log_messages.
1343 pJQueueLogMessages :: Field
1344 pJQueueLogMessages =
1345 defaultField [| [] |] $ simpleField "log_messages" [t| [String] |]
1347 -- | 'OpTestJQueue' fail attribute.
1348 pJQueueFail :: Field
1350 renameField "JQueueFail" $ defaultFalse "fail"
1352 -- | 'OpTestDummy' result field.
1353 pTestDummyResult :: Field
1355 renameField "TestDummyResult" $ simpleField "result" [t| UncheckedValue |]
1357 -- | 'OpTestDummy' messages field.
1358 pTestDummyMessages :: Field
1359 pTestDummyMessages =
1360 renameField "TestDummyMessages" $
1361 simpleField "messages" [t| UncheckedValue |]
1363 -- | 'OpTestDummy' fail field.
1364 pTestDummyFail :: Field
1366 renameField "TestDummyFail" $ simpleField "fail" [t| UncheckedValue |]
1368 -- | 'OpTestDummy' submit_jobs field.
1369 pTestDummySubmitJobs :: Field
1370 pTestDummySubmitJobs =
1371 renameField "TestDummySubmitJobs" $
1372 simpleField "submit_jobs" [t| UncheckedValue |]
1374 -- * Network parameters
1377 pNetworkName :: Field
1378 pNetworkName = simpleField "network_name" [t| NonEmptyString |]
1380 -- | Network address (IPv4 subnet). FIXME: no real type for this.
1381 pNetworkAddress4 :: Field
1383 renameField "NetworkAddress4" $
1384 simpleField "network" [t| NonEmptyString |]
1386 -- | Network gateway (IPv4 address). FIXME: no real type for this.
1387 pNetworkGateway4 :: Field
1389 renameField "NetworkGateway4" $
1390 optionalNEStringField "gateway"
1392 -- | Network address (IPv6 subnet). FIXME: no real type for this.
1393 pNetworkAddress6 :: Field
1395 renameField "NetworkAddress6" $
1396 optionalNEStringField "network6"
1398 -- | Network gateway (IPv6 address). FIXME: no real type for this.
1399 pNetworkGateway6 :: Field
1401 renameField "NetworkGateway6" $
1402 optionalNEStringField "gateway6"
1404 -- | Network specific mac prefix (that overrides the cluster one).
1405 pNetworkMacPrefix :: Field
1407 renameField "NetMacPrefix" $
1408 optionalNEStringField "mac_prefix"
1410 -- | Network add reserved IPs.
1411 pNetworkAddRsvdIps :: Field
1412 pNetworkAddRsvdIps =
1413 renameField "NetworkAddRsvdIps" .
1415 simpleField "add_reserved_ips" [t| [NonEmptyString] |]
1417 -- | Network remove reserved IPs.
1418 pNetworkRemoveRsvdIps :: Field
1419 pNetworkRemoveRsvdIps =
1420 renameField "NetworkRemoveRsvdIps" .
1422 simpleField "remove_reserved_ips" [t| [NonEmptyString] |]
1424 -- | Network mode when connecting to a group.
1425 pNetworkMode :: Field
1426 pNetworkMode = simpleField "network_mode" [t| NICMode |]
1428 -- | Network link when connecting to a group.
1429 pNetworkLink :: Field
1430 pNetworkLink = simpleField "network_link" [t| NonEmptyString |]
1432 -- * Common opcode parameters
1434 -- | Run checks only, don't execute.
1436 pDryRun = optionalField $ booleanField "dry_run"
1439 pDebugLevel :: Field
1440 pDebugLevel = optionalField $ simpleField "debug_level" [t| NonNegative Int |]
1442 -- | Opcode priority. Note: python uses a separate constant, we're
1443 -- using the actual value we know it's the default.
1444 pOpPriority :: Field
1446 defaultField [| OpPrioNormal |] $
1447 simpleField "priority" [t| OpSubmitPriority |]
1449 -- | Job dependencies.
1450 pDependencies :: Field
1452 optionalNullSerField $ simpleField "depends" [t| [JobDependency] |]
1456 pComment = optionalNullSerField $ stringField "comment"
1458 -- | Reason trail field.
1460 pReason = simpleField C.opcodeReason [t| ReasonTrail |]
1462 -- * Entire opcode parameter list
1464 -- | Old-style query opcode, with locking.
1465 dOldQuery :: [Field]
1472 -- | Old-style query opcode, without locking.
1473 dOldQueryNoLocking :: [Field]
1474 dOldQueryNoLocking =