module Ganeti.OpCodes
( OpCode(..)
+ , TagObject(..)
+ , tagObjectFrom
+ , encodeTagObject
+ , decodeTagObject
, ReplaceDisksMode(..)
, DiskIndex
, mkDiskIndex
, allOpIDs
) where
-import Text.JSON (readJSON, showJSON, makeObj, JSON)
+import Text.JSON (readJSON, showJSON, JSON())
-import qualified Ganeti.Constants as C
import Ganeti.THH
-import Ganeti.JSON
-
--- | 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 }
- deriving (Show, Read, Eq, Ord)
-
--- | 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
+import Ganeti.OpParams
-- | OpCode representation.
--
--- We only implement a subset of Ganeti opcodes, but only what we
--- actually use in the htools codebase.
+-- We only implement a subset of Ganeti opcodes: those which are actually used
+-- in the htools codebase.
$(genOpCode "OpCode"
[ ("OpTestDelay",
[ simpleField "duration" [t| Double |]
, simpleField "on_nodes" [t| [String] |]
])
, ("OpInstanceReplaceDisks",
- [ simpleField "instance_name" [t| String |]
- , optionalField $ simpleField "remote_node" [t| String |]
+ [ pInstanceName
+ , pRemoteNode
, simpleField "mode" [t| ReplaceDisksMode |]
, simpleField "disks" [t| [DiskIndex] |]
- , optionalField $ simpleField "iallocator" [t| String |]
+ , pIallocator
])
, ("OpInstanceFailover",
- [ simpleField "instance_name" [t| String |]
+ [ pInstanceName
, simpleField "ignore_consistency" [t| Bool |]
- , optionalField $ simpleField "target_node" [t| String |]
+ , pMigrationTargetNode
])
, ("OpInstanceMigrate",
- [ simpleField "instance_name" [t| String |]
+ [ pInstanceName
, simpleField "live" [t| Bool |]
, simpleField "cleanup" [t| Bool |]
, defaultField [| False |] $ simpleField "allow_failover" [t| Bool |]
- , optionalField $ simpleField "target_node" [t| String |]
+ , pMigrationTargetNode
+ ])
+ , ("OpTagsSet",
+ [ pTagsObject
+ , pTagsList
+ ])
+ , ("OpTagsDel",
+ [ pTagsObject
+ , pTagsList
+ ])
+ , ("OpClusterPostInit", [])
+ , ("OpClusterDestroy", [])
+ , ("OpClusterQuery", [])
+ , ("OpClusterVerify",
+ [ pDebugSimulateErrors
+ , pErrorCodes
+ , pSkipChecks
+ , pIgnoreErrors
+ , pVerbose
+ , pOptGroupName
+ ])
+ , ("OpClusterVerifyConfig",
+ [ pDebugSimulateErrors
+ , pErrorCodes
+ , pIgnoreErrors
+ , pVerbose
+ ])
+ , ("OpClusterVerifyGroup",
+ [ pGroupName
+ , pDebugSimulateErrors
+ , pErrorCodes
+ , pSkipChecks
+ , pIgnoreErrors
+ , pVerbose
+ ])
+ , ("OpClusterVerifyDisks", [])
+ , ("OpGroupVerifyDisks",
+ [ pGroupName
+ ])
+ , ("OpClusterRepairDiskSizes",
+ [ pInstances
+ ])
+ , ("OpClusterConfigQuery",
+ [ pOutputFields
+ ])
+ , ("OpClusterRename",
+ [ pName
+ ])
+ , ("OpClusterSetParams",
+ [ pHvState
+ , pDiskState
+ , pVgName
+ , pEnabledHypervisors
+ , pClusterHvParams
+ , pClusterBeParams
+ , pOsHvp
+ , pOsParams
+ , pDiskParams
+ , pCandidatePoolSize
+ , pUidPool
+ , pAddUids
+ , pRemoveUids
+ , pMaintainNodeHealth
+ , pPreallocWipeDisks
+ , pNicParams
+ , pNdParams
+ , pIpolicy
+ , pDrbdHelper
+ , pDefaultIAllocator
+ , pMasterNetdev
+ , pReservedLvs
+ , pHiddenOs
+ , pBlacklistedOs
+ , pUseExternalMipScript
+ ])
+ , ("OpClusterRedistConf", [])
+ , ("OpClusterActivateMasterIp", [])
+ , ("OpClusterDeactivateMasterIp", [])
+ , ("OpQuery",
+ [ pQueryWhat
+ , pUseLocking
+ , pQueryFields
+ , pQueryFilter
+ ])
+ , ("OpQueryFields",
+ [ pQueryWhat
+ , pQueryFields
+ ])
+ , ("OpOobCommand",
+ [ pNodeNames
+ , pOobCommand
+ , pOobTimeout
+ , pIgnoreStatus
+ , pPowerDelay
+ ])
+ , ("OpNodeRemove", [ pNodeName ])
+ , ("OpNodeAdd",
+ [ pNodeName
+ , pHvState
+ , pDiskState
+ , pPrimaryIp
+ , pSecondaryIp
+ , pReadd
+ , pNodeGroup
+ , pMasterCapable
+ , pVmCapable
+ , pNdParams
+ ])
+ , ("OpNodeQuery",
+ [ pOutputFields
+ , pUseLocking
+ , pNames
+ ])
+ , ("OpNodeQueryvols",
+ [ pOutputFields
+ , pNodes
+ ])
+ , ("OpNodeQueryStorage",
+ [ pOutputFields
+ , pStorageType
+ , pNodes
+ , pStorageName
+ ])
+ , ("OpNodeModifyStorage",
+ [ pNodeName
+ , pStorageType
+ , pStorageName
+ , pStorageChanges
+ ])
+ , ("OpRepairNodeStorage",
+ [ pNodeName
+ , pStorageType
+ , pStorageName
+ , pIgnoreConsistency
+ ])
+ , ("OpNodeSetParams",
+ [ pNodeName
+ , pForce
+ , pHvState
+ , pDiskState
+ , pMasterCandidate
+ , pOffline
+ , pDrained
+ , pAutoPromote
+ , pMasterCapable
+ , pVmCapable
+ , pSecondaryIp
+ , pNdParams
+ ])
+ , ("OpNodePowercycle",
+ [ pNodeName
+ , pForce
+ ])
+ , ("OpNodeMigrate",
+ [ pNodeName
+ , pMigrationMode
+ , pMigrationLive
+ , pMigrationTargetNode
+ , pAllowRuntimeChgs
+ , pIgnoreIpolicy
+ , pIallocator
+ ])
+ , ("OpNodeEvacuate",
+ [ pEarlyRelease
+ , pNodeName
+ , pRemoteNode
+ , pIallocator
+ , pEvacMode
])
])