On Mon, Oct 7, 2013 at 4:37 PM, Jose A. Lopes <[email protected]> wrote:
> Hs2Py constants: add 'Ganeti.Confd' types. > > Signed-off-by: Jose A. Lopes <[email protected]> > --- > lib/constants.py | 67 ++++++++++++----------------- > src/Ganeti/Confd/Types.hs | 90 ++++++++++++++++----------------------- > src/Ganeti/ConstantUtils.hs | 7 +++ > src/Ganeti/HsConstants.hs | 101 > +++++++++++++++++++++++++++++++++++++++++--- > 4 files changed, 164 insertions(+), 101 deletions(-) > > diff --git a/lib/constants.py b/lib/constants.py > index 30378c0..e5bdddb 100644 > --- a/lib/constants.py > +++ b/lib/constants.py > @@ -2060,17 +2060,18 @@ PART_MARGIN = .01 > # Space reserved when creating instance disks > PART_RESERVED = .02 > > -CONFD_PROTOCOL_VERSION = 1 > - > -CONFD_REQ_PING = 0 > -CONFD_REQ_NODE_ROLE_BYNAME = 1 > -CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2 > -CONFD_REQ_CLUSTER_MASTER = 3 > -CONFD_REQ_NODE_PIP_LIST = 4 > -CONFD_REQ_MC_PIP_LIST = 5 > -CONFD_REQ_INSTANCES_IPS_LIST = 6 > -CONFD_REQ_NODE_DRBD = 7 > -CONFD_REQ_NODE_INSTANCES = 8 > +CONFD_PROTOCOL_VERSION = _constants.CONFD_PROTOCOL_VERSION > + > +CONFD_REQ_PING = _constants.CONFD_REQ_PING > +CONFD_REQ_NODE_ROLE_BYNAME = _constants.CONFD_REQ_NODE_ROLE_BYNAME > +CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = > _constants.CONFD_REQ_NODE_PIP_BY_INSTANCE_IP > +CONFD_REQ_CLUSTER_MASTER = _constants.CONFD_REQ_CLUSTER_MASTER > +CONFD_REQ_NODE_PIP_LIST = _constants.CONFD_REQ_NODE_PIP_LIST > +CONFD_REQ_MC_PIP_LIST = _constants.CONFD_REQ_MC_PIP_LIST > +CONFD_REQ_INSTANCES_IPS_LIST = _constants.CONFD_REQ_INSTANCES_IPS_LIST > +CONFD_REQ_NODE_DRBD = _constants.CONFD_REQ_NODE_DRBD > +CONFD_REQ_NODE_INSTANCES = _constants.CONFD_REQ_NODE_INSTANCES > +CONFD_REQS = _constants.CONFD_REQS > > # Confd request query fields. These are used to narrow down queries. > # These must be strings rather than integers, because json-encoding > @@ -2080,39 +2081,23 @@ CONFD_REQQ_IP = _constants.CONFD_REQQ_IP > CONFD_REQQ_IPLIST = _constants.CONFD_REQQ_IPLIST > CONFD_REQQ_FIELDS = _constants.CONFD_REQQ_FIELDS > > -CONFD_REQFIELD_NAME = "0" > -CONFD_REQFIELD_IP = "1" > -CONFD_REQFIELD_MNODE_PIP = "2" > - > -CONFD_REQS = compat.UniqueFrozenset([ > - CONFD_REQ_PING, > - CONFD_REQ_NODE_ROLE_BYNAME, > - CONFD_REQ_NODE_PIP_BY_INSTANCE_IP, > - CONFD_REQ_CLUSTER_MASTER, > - CONFD_REQ_NODE_PIP_LIST, > - CONFD_REQ_MC_PIP_LIST, > - CONFD_REQ_INSTANCES_IPS_LIST, > - CONFD_REQ_NODE_DRBD, > - ]) > - > -CONFD_REPL_STATUS_OK = 0 > -CONFD_REPL_STATUS_ERROR = 1 > -CONFD_REPL_STATUS_NOTIMPLEMENTED = 2 > +# FIXME: perhaps update code that uses these constants to deal with > +# integers instead of strings > +CONFD_REQFIELD_NAME = str(_constants.CONFD_REQFIELD_NAME) > +CONFD_REQFIELD_IP = str(_constants.CONFD_REQFIELD_IP) > +CONFD_REQFIELD_MNODE_PIP = str(_constants.CONFD_REQFIELD_MNODE_PIP) > > -CONFD_REPL_STATUSES = compat.UniqueFrozenset([ > - CONFD_REPL_STATUS_OK, > - CONFD_REPL_STATUS_ERROR, > - CONFD_REPL_STATUS_NOTIMPLEMENTED, > - ]) > +CONFD_REPL_STATUS_OK = _constants.CONFD_REPL_STATUS_OK > +CONFD_REPL_STATUS_ERROR = _constants.CONFD_REPL_STATUS_ERROR > +CONFD_REPL_STATUS_NOTIMPLEMENTED = > _constants.CONFD_REPL_STATUS_NOTIMPLEMENTED > +CONFD_REPL_STATUSES = _constants.CONFD_REPL_STATUSES > > -(CONFD_NODE_ROLE_MASTER, > - CONFD_NODE_ROLE_CANDIDATE, > - CONFD_NODE_ROLE_OFFLINE, > - CONFD_NODE_ROLE_DRAINED, > - CONFD_NODE_ROLE_REGULAR, > - ) = range(5) > +CONFD_NODE_ROLE_MASTER = _constants.CONFD_NODE_ROLE_MASTER > +CONFD_NODE_ROLE_CANDIDATE = _constants.CONFD_NODE_ROLE_CANDIDATE > +CONFD_NODE_ROLE_OFFLINE = _constants.CONFD_NODE_ROLE_OFFLINE > +CONFD_NODE_ROLE_DRAINED = _constants.CONFD_NODE_ROLE_DRAINED > +CONFD_NODE_ROLE_REGULAR = _constants.CONFD_NODE_ROLE_REGULAR > > -# A few common errors for confd > CONFD_ERROR_UNKNOWN_ENTRY = _constants.CONFD_ERROR_UNKNOWN_ENTRY > CONFD_ERROR_INTERNAL = _constants.CONFD_ERROR_INTERNAL > CONFD_ERROR_ARGUMENT = _constants.CONFD_ERROR_ARGUMENT > diff --git a/src/Ganeti/Confd/Types.hs b/src/Ganeti/Confd/Types.hs > index 60fd79e..03aded6 100644 > --- a/src/Ganeti/Confd/Types.hs > +++ b/src/Ganeti/Confd/Types.hs > @@ -26,21 +26,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, > Boston, MA > -} > > module Ganeti.Confd.Types > - ( C.confdProtocolVersion > - , C.confdMaxClockSkew > - , C.confdConfigReloadTimeout > - , C.confdConfigReloadRatelimit > - , C.confdMagicFourcc > - , C.confdDefaultReqCoverage > - , C.confdClientExpireTimeout > - , C.maxUdpDataSize > - , ConfdClient(..) > + ( ConfdClient(..) > , ConfdRequestType(..) > - , ConfdReqQ(..) > + , confdRequestTypeToRaw > , ConfdReqField(..) > + , confdReqFieldToRaw > + , ConfdReqQ(..) > , ConfdReplyStatus(..) > + , confdReplyStatusToRaw > , ConfdNodeRole(..) > + , confdNodeRoleToRaw > , ConfdErrorType(..) > + , confdErrorTypeToRaw > , ConfdRequest(..) > , newConfdRequest > , ConfdReply(..) > @@ -51,42 +48,28 @@ module Ganeti.Confd.Types > import Text.JSON > import qualified Network.Socket as S > > -import qualified Ganeti.Constants as C > import qualified Ganeti.ConstantUtils as ConstantUtils > import Ganeti.Hash > import Ganeti.THH > import Ganeti.Utils (newUUID) > > -{- > - Note that we re-export as is from Constants the following simple items: > - - confdProtocolVersion > - - confdMaxClockSkew > - - confdConfigReloadTimeout > - - confdConfigReloadRatelimit > - - confdMagicFourcc > - - confdDefaultReqCoverage > - - confdClientExpireTimeout > - - maxUdpDataSize > - > --} > - > -$(declareIADT "ConfdRequestType" > - [ ("ReqPing", 'C.confdReqPing ) > - , ("ReqNodeRoleByName", 'C.confdReqNodeRoleByname ) > - , ("ReqNodePipList", 'C.confdReqNodePipList ) > - , ("ReqNodePipByInstPip", 'C.confdReqNodePipByInstanceIp ) > - , ("ReqClusterMaster", 'C.confdReqClusterMaster ) > - , ("ReqMcPipList", 'C.confdReqMcPipList ) > - , ("ReqInstIpsList", 'C.confdReqInstancesIpsList ) > - , ("ReqNodeDrbd", 'C.confdReqNodeDrbd ) > - , ("ReqNodeInstances", 'C.confdReqNodeInstances) > +$(declareILADT "ConfdRequestType" > + [ ("ReqPing", 0) > + , ("ReqNodeRoleByName", 1) > + , ("ReqNodePipByInstPip", 2) > + , ("ReqClusterMaster", 3) > + , ("ReqNodePipList", 4) > + , ("ReqMcPipList", 5) > + , ("ReqInstIpsList", 6) > + , ("ReqNodeDrbd", 7) > + , ("ReqNodeInstances", 8) > ]) > $(makeJSONInstance ''ConfdRequestType) > > -$(declareSADT "ConfdReqField" > - [ ("ReqFieldName", 'C.confdReqfieldName ) > - , ("ReqFieldIp", 'C.confdReqfieldIp ) > - , ("ReqFieldMNodePip", 'C.confdReqfieldMnodePip ) > +$(declareILADT "ConfdReqField" > + [ ("ReqFieldName", 0) > + , ("ReqFieldIp", 1) > + , ("ReqFieldMNodePip", 2) > ]) > $(makeJSONInstance ''ConfdReqField) > > @@ -128,30 +111,29 @@ instance JSON ConfdQuery where > PlainQuery s -> showJSON s > DictQuery drq -> showJSON drq > > -$(declareIADT "ConfdReplyStatus" > - [ ( "ReplyStatusOk", 'C.confdReplStatusOk ) > - , ( "ReplyStatusError", 'C.confdReplStatusError ) > - , ( "ReplyStatusNotImpl", 'C.confdReplStatusNotimplemented ) > +$(declareILADT "ConfdReplyStatus" > + [ ("ReplyStatusOk", 0) > + , ("ReplyStatusError", 1) > + , ("ReplyStatusNotImpl", 2) > ]) > $(makeJSONInstance ''ConfdReplyStatus) > > -$(declareIADT "ConfdNodeRole" > - [ ( "NodeRoleMaster", 'C.confdNodeRoleMaster ) > - , ( "NodeRoleCandidate", 'C.confdNodeRoleCandidate ) > - , ( "NodeRoleOffline", 'C.confdNodeRoleOffline ) > - , ( "NodeRoleDrained", 'C.confdNodeRoleDrained ) > - , ( "NodeRoleRegular", 'C.confdNodeRoleRegular ) > +$(declareILADT "ConfdNodeRole" > + [ ("NodeRoleMaster", 0) > + , ("NodeRoleCandidate", 1) > + , ("NodeRoleOffline", 2) > + , ("NodeRoleDrained", 3) > + , ("NodeRoleRegular", 4) > ]) > $(makeJSONInstance ''ConfdNodeRole) > > - > -- Note that the next item is not a frozenset in Python, but we make > -- it a separate type for safety > > -$(declareIADT "ConfdErrorType" > - [ ( "ConfdErrorUnknownEntry", 'C.confdErrorUnknownEntry ) > - , ( "ConfdErrorInternal", 'C.confdErrorInternal ) > - , ( "ConfdErrorArgument", 'C.confdErrorArgument ) > +$(declareILADT "ConfdErrorType" > + [ ("ConfdErrorUnknownEntry", 0) > + , ("ConfdErrorInternal", 1) > + , ("ConfdErrorArgument", 2) > ]) > $(makeJSONInstance ''ConfdErrorType) > > @@ -167,7 +149,7 @@ $(buildObject "ConfdRequest" "confdRq" > newConfdRequest :: ConfdRequestType -> ConfdQuery -> IO ConfdRequest > newConfdRequest reqType query = do > rsalt <- newUUID > - return $ ConfdRequest C.confdProtocolVersion reqType query rsalt > + return $ ConfdRequest ConstantUtils.confdProtocolVersion reqType query > rsalt > > $(buildObject "ConfdReply" "confdReply" > [ simpleField "protocol" [t| Int |] > diff --git a/src/Ganeti/ConstantUtils.hs b/src/Ganeti/ConstantUtils.hs > index 02c9701..9d68eb8 100644 > --- a/src/Ganeti/ConstantUtils.hs > +++ b/src/Ganeti/ConstantUtils.hs > @@ -109,6 +109,13 @@ buildVersion :: Int -> Int -> Int -> Int > buildVersion major minor revision = > 1000000 * major + 10000 * minor + 1 * revision > > +-- | Confd protocol version > +-- > +-- This is defined here in order to avoid a circular dependency > +-- between 'Ganeti.Confd.Types' and 'Ganeti.HsConstants'. > +confdProtocolVersion :: Int > +confdProtocolVersion = 1 > + > -- * Confd request query fields. > -- > -- These are defined here and not in 'Ganeti.Types' due to GHC stage > diff --git a/src/Ganeti/HsConstants.hs b/src/Ganeti/HsConstants.hs > index c483ff3..c56de77 100644 > --- a/src/Ganeti/HsConstants.hs > +++ b/src/Ganeti/HsConstants.hs > @@ -36,6 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, > Boston, MA > -} > module Ganeti.HsConstants where > > +import Data.List ((\\)) > import Data.Map (Map) > import qualified Data.Map as Map (fromList) > > @@ -49,6 +50,10 @@ import qualified Ganeti.Logging as Logging > (syslogUsageToRaw) > import qualified Ganeti.Runtime as Runtime > import Ganeti.Types > import qualified Ganeti.Types as Types > +import Ganeti.Confd.Types (ConfdRequestType(..), ConfdReqField(..), > + ConfdReplyStatus(..), ConfdNodeRole(..), > + ConfdErrorType(..)) > +import qualified Ganeti.Confd.Types as Types > > -- * 'autoconf' constants for Python only > ('autotools/build-bash-completion') > > @@ -154,6 +159,7 @@ protocolVersion :: Int > protocolVersion = buildVersion configMajor configMinor configRevision > > -- * User separation > + > daemonsGroup :: String > daemonsGroup = Runtime.daemonGroup (ExtraGroup DaemonsGroup) > > @@ -1225,18 +1231,101 @@ elogRemoteImport = Types.eLogTypeToRaw > ELogRemoteImport > elogJqueueTest :: String > elogJqueueTest = Types.eLogTypeToRaw ELogJqueueTest > > +-- * Confd > + > +confdProtocolVersion :: Int > +confdProtocolVersion = ConstantUtils.confdProtocolVersion > + > +-- Confd request type > + > +confdReqPing :: Int > +confdReqPing = Types.confdRequestTypeToRaw ReqPing > + > +confdReqNodeRoleByname :: Int > +confdReqNodeRoleByname = Types.confdRequestTypeToRaw ReqNodeRoleByName > + > +confdReqNodePipByInstanceIp :: Int > +confdReqNodePipByInstanceIp = Types.confdRequestTypeToRaw > ReqNodePipByInstPip > + > +confdReqClusterMaster :: Int > +confdReqClusterMaster = Types.confdRequestTypeToRaw ReqClusterMaster > + > +confdReqNodePipList :: Int > +confdReqNodePipList = Types.confdRequestTypeToRaw ReqNodePipList > + > +confdReqMcPipList :: Int > +confdReqMcPipList = Types.confdRequestTypeToRaw ReqMcPipList > + > +confdReqInstancesIpsList :: Int > +confdReqInstancesIpsList = Types.confdRequestTypeToRaw ReqInstIpsList > + > +confdReqNodeDrbd :: Int > +confdReqNodeDrbd = Types.confdRequestTypeToRaw ReqNodeDrbd > + > +confdReqNodeInstances :: Int > +confdReqNodeInstances = Types.confdRequestTypeToRaw ReqNodeInstances > + > +confdReqs :: FrozenSet Int > +confdReqs = > + ConstantUtils.mkSet . > + map Types.confdRequestTypeToRaw $ > + [minBound..] \\ [ReqNodeInstances] > + > +-- * Confd request type > + > +confdReqfieldName :: Int > +confdReqfieldName = Types.confdReqFieldToRaw ReqFieldName > + > +confdReqfieldIp :: Int > +confdReqfieldIp = Types.confdReqFieldToRaw ReqFieldIp > + > +confdReqfieldMnodePip :: Int > +confdReqfieldMnodePip = Types.confdReqFieldToRaw ReqFieldMNodePip > + > +-- * Confd repl status > + > +confdReplStatusOk :: Int > +confdReplStatusOk = Types.confdReplyStatusToRaw ReplyStatusOk > + > +confdReplStatusError :: Int > +confdReplStatusError = Types.confdReplyStatusToRaw ReplyStatusError > + > +confdReplStatusNotimplemented :: Int > +confdReplStatusNotimplemented = Types.confdReplyStatusToRaw > ReplyStatusNotImpl > + > +confdReplStatuses :: FrozenSet Int > +confdReplStatuses = > + ConstantUtils.mkSet $ map Types.confdReplyStatusToRaw [minBound..] > + > +-- * Confd node role > + > +confdNodeRoleMaster :: Int > +confdNodeRoleMaster = Types.confdNodeRoleToRaw NodeRoleMaster > + > +confdNodeRoleCandidate :: Int > +confdNodeRoleCandidate = Types.confdNodeRoleToRaw NodeRoleCandidate > + > +confdNodeRoleOffline :: Int > +confdNodeRoleOffline = Types.confdNodeRoleToRaw NodeRoleOffline > + > +confdNodeRoleDrained :: Int > +confdNodeRoleDrained = Types.confdNodeRoleToRaw NodeRoleDrained > + > +confdNodeRoleRegular :: Int > +confdNodeRoleRegular = Types.confdNodeRoleToRaw NodeRoleRegular > + > -- * A few common errors for confd > > -confdErrorArgument :: Int > -confdErrorArgument = 3 > +confdErrorUnknownEntry :: Int > +confdErrorUnknownEntry = Types.confdErrorTypeToRaw ConfdErrorUnknownEntry > > confdErrorInternal :: Int > -confdErrorInternal = 2 > +confdErrorInternal = Types.confdErrorTypeToRaw ConfdErrorInternal > > -confdErrorUnknownEntry :: Int > -confdErrorUnknownEntry = 1 > +confdErrorArgument :: Int > +confdErrorArgument = Types.confdErrorTypeToRaw ConfdErrorArgument > > --- Confd request query fields > +-- * Confd request query fields > > confdReqqLink :: String > confdReqqLink = ConstantUtils.confdReqqLink > -- > 1.8.4 > > LGTM, thanks. -- Thomas Thrainer | Software Engineer | [email protected] | Google Germany GmbH Dienerstr. 12 80331 München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores
