X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/ebf380646857819d447b10dd36f82edffc9bea00..c65621d7f7d921bfbc6886e28c69f1ba8eb965bc:/htools/Ganeti/OpCodes.hs?ds=sidebyside diff --git a/htools/Ganeti/OpCodes.hs b/htools/Ganeti/OpCodes.hs index 4b54e21..033a68b 100644 --- a/htools/Ganeti/OpCodes.hs +++ b/htools/Ganeti/OpCodes.hs @@ -6,7 +6,7 @@ {- -Copyright (C) 2009, 2010, 2011 Google Inc. +Copyright (C) 2009, 2010, 2011, 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 @@ -27,60 +27,228 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Ganeti.OpCodes ( OpCode(..) + , TagObject(..) + , tagObjectFrom + , encodeTagObject + , decodeTagObject , ReplaceDisksMode(..) + , DiskIndex + , mkDiskIndex + , unDiskIndex , opID + , allOpIDs ) where -import Text.JSON (readJSON, showJSON, makeObj, JSON) -import qualified Text.JSON as J +import Text.JSON (readJSON, showJSON, JSON()) -import qualified Ganeti.Constants as C import Ganeti.THH -import Ganeti.HTools.Utils - --- | Replace disks type. -$(declareSADT "ReplaceDisksMode" - [ ("ReplaceOnPrimary", 'C.replaceDiskPri) - , ("ReplaceOnSecondary", 'C.replaceDiskSec) - , ("ReplaceNewSecondary", 'C.replaceDiskChg) - , ("ReplaceAuto", 'C.replaceDiskAuto) - ]) -$(makeJSONInstance ''ReplaceDisksMode) +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", - [ ("duration", [t| Double |], noDefault) - , ("on_master", [t| Bool |], noDefault) - , ("on_nodes", [t| [String] |], noDefault) + [ simpleField "duration" [t| Double |] + , simpleField "on_master" [t| Bool |] + , simpleField "on_nodes" [t| [String] |] ]) , ("OpInstanceReplaceDisks", - [ ("instance_name", [t| String |], noDefault) - , ("remote_node", [t| Maybe String |], noDefault) - , ("mode", [t| ReplaceDisksMode |], noDefault) - , ("disks", [t| [Int] |], noDefault) - , ("iallocator", [t| Maybe String |], noDefault) + [ pInstanceName + , pRemoteNode + , simpleField "mode" [t| ReplaceDisksMode |] + , simpleField "disks" [t| [DiskIndex] |] + , pIallocator ]) , ("OpInstanceFailover", - [ ("instance_name", [t| String |], noDefault) - , ("ignore_consistency", [t| Bool |], noDefault) - , ("target_node", [t| Maybe String |], noDefault) + [ pInstanceName + , simpleField "ignore_consistency" [t| Bool |] + , pMigrationTargetNode ]) , ("OpInstanceMigrate", - [ ("instance_name", [t| String |], noDefault) - , ("live", [t| Bool |], noDefault) - , ("cleanup", [t| Bool |], noDefault) - , ("allow_failover", [t| Bool |], [| Just False |]) - , ("target_node", [t| Maybe String |], noDefault) + [ pInstanceName + , simpleField "live" [t| Bool |] + , simpleField "cleanup" [t| Bool |] + , defaultField [| False |] $ simpleField "allow_failover" [t| Bool |] + , 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 ]) ]) +-- | Returns the OP_ID for a given opcode value. $(genOpID ''OpCode "opID") +-- | A list of all defined/supported opcode IDs. +$(genAllOpIDs ''OpCode "allOpIDs") + instance JSON OpCode where readJSON = loadOpCode showJSON = saveOpCode