Revision cdac0552
b/lib/constants.py | ||
---|---|---|
2060 | 2060 |
# Space reserved when creating instance disks |
2061 | 2061 |
PART_RESERVED = .02 |
2062 | 2062 |
|
2063 |
CONFD_PROTOCOL_VERSION = 1 |
|
2064 |
|
|
2065 |
CONFD_REQ_PING = 0 |
|
2066 |
CONFD_REQ_NODE_ROLE_BYNAME = 1 |
|
2067 |
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2 |
|
2068 |
CONFD_REQ_CLUSTER_MASTER = 3 |
|
2069 |
CONFD_REQ_NODE_PIP_LIST = 4 |
|
2070 |
CONFD_REQ_MC_PIP_LIST = 5 |
|
2071 |
CONFD_REQ_INSTANCES_IPS_LIST = 6 |
|
2072 |
CONFD_REQ_NODE_DRBD = 7 |
|
2073 |
CONFD_REQ_NODE_INSTANCES = 8 |
|
2063 |
CONFD_PROTOCOL_VERSION = _constants.CONFD_PROTOCOL_VERSION |
|
2064 |
|
|
2065 |
CONFD_REQ_PING = _constants.CONFD_REQ_PING |
|
2066 |
CONFD_REQ_NODE_ROLE_BYNAME = _constants.CONFD_REQ_NODE_ROLE_BYNAME |
|
2067 |
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = _constants.CONFD_REQ_NODE_PIP_BY_INSTANCE_IP |
|
2068 |
CONFD_REQ_CLUSTER_MASTER = _constants.CONFD_REQ_CLUSTER_MASTER |
|
2069 |
CONFD_REQ_NODE_PIP_LIST = _constants.CONFD_REQ_NODE_PIP_LIST |
|
2070 |
CONFD_REQ_MC_PIP_LIST = _constants.CONFD_REQ_MC_PIP_LIST |
|
2071 |
CONFD_REQ_INSTANCES_IPS_LIST = _constants.CONFD_REQ_INSTANCES_IPS_LIST |
|
2072 |
CONFD_REQ_NODE_DRBD = _constants.CONFD_REQ_NODE_DRBD |
|
2073 |
CONFD_REQ_NODE_INSTANCES = _constants.CONFD_REQ_NODE_INSTANCES |
|
2074 |
CONFD_REQS = _constants.CONFD_REQS |
|
2074 | 2075 |
|
2075 | 2076 |
# Confd request query fields. These are used to narrow down queries. |
2076 | 2077 |
# These must be strings rather than integers, because json-encoding |
... | ... | |
2080 | 2081 |
CONFD_REQQ_IPLIST = _constants.CONFD_REQQ_IPLIST |
2081 | 2082 |
CONFD_REQQ_FIELDS = _constants.CONFD_REQQ_FIELDS |
2082 | 2083 |
|
2083 |
CONFD_REQFIELD_NAME = "0" |
|
2084 |
CONFD_REQFIELD_IP = "1" |
|
2085 |
CONFD_REQFIELD_MNODE_PIP = "2" |
|
2086 |
|
|
2087 |
CONFD_REQS = compat.UniqueFrozenset([ |
|
2088 |
CONFD_REQ_PING, |
|
2089 |
CONFD_REQ_NODE_ROLE_BYNAME, |
|
2090 |
CONFD_REQ_NODE_PIP_BY_INSTANCE_IP, |
|
2091 |
CONFD_REQ_CLUSTER_MASTER, |
|
2092 |
CONFD_REQ_NODE_PIP_LIST, |
|
2093 |
CONFD_REQ_MC_PIP_LIST, |
|
2094 |
CONFD_REQ_INSTANCES_IPS_LIST, |
|
2095 |
CONFD_REQ_NODE_DRBD, |
|
2096 |
]) |
|
2097 |
|
|
2098 |
CONFD_REPL_STATUS_OK = 0 |
|
2099 |
CONFD_REPL_STATUS_ERROR = 1 |
|
2100 |
CONFD_REPL_STATUS_NOTIMPLEMENTED = 2 |
|
2084 |
# FIXME: perhaps update code that uses these constants to deal with |
|
2085 |
# integers instead of strings |
|
2086 |
CONFD_REQFIELD_NAME = str(_constants.CONFD_REQFIELD_NAME) |
|
2087 |
CONFD_REQFIELD_IP = str(_constants.CONFD_REQFIELD_IP) |
|
2088 |
CONFD_REQFIELD_MNODE_PIP = str(_constants.CONFD_REQFIELD_MNODE_PIP) |
|
2101 | 2089 |
|
2102 |
CONFD_REPL_STATUSES = compat.UniqueFrozenset([ |
|
2103 |
CONFD_REPL_STATUS_OK, |
|
2104 |
CONFD_REPL_STATUS_ERROR, |
|
2105 |
CONFD_REPL_STATUS_NOTIMPLEMENTED, |
|
2106 |
]) |
|
2090 |
CONFD_REPL_STATUS_OK = _constants.CONFD_REPL_STATUS_OK |
|
2091 |
CONFD_REPL_STATUS_ERROR = _constants.CONFD_REPL_STATUS_ERROR |
|
2092 |
CONFD_REPL_STATUS_NOTIMPLEMENTED = _constants.CONFD_REPL_STATUS_NOTIMPLEMENTED |
|
2093 |
CONFD_REPL_STATUSES = _constants.CONFD_REPL_STATUSES |
|
2107 | 2094 |
|
2108 |
(CONFD_NODE_ROLE_MASTER, |
|
2109 |
CONFD_NODE_ROLE_CANDIDATE, |
|
2110 |
CONFD_NODE_ROLE_OFFLINE, |
|
2111 |
CONFD_NODE_ROLE_DRAINED, |
|
2112 |
CONFD_NODE_ROLE_REGULAR, |
|
2113 |
) = range(5) |
|
2095 |
CONFD_NODE_ROLE_MASTER = _constants.CONFD_NODE_ROLE_MASTER |
|
2096 |
CONFD_NODE_ROLE_CANDIDATE = _constants.CONFD_NODE_ROLE_CANDIDATE |
|
2097 |
CONFD_NODE_ROLE_OFFLINE = _constants.CONFD_NODE_ROLE_OFFLINE |
|
2098 |
CONFD_NODE_ROLE_DRAINED = _constants.CONFD_NODE_ROLE_DRAINED |
|
2099 |
CONFD_NODE_ROLE_REGULAR = _constants.CONFD_NODE_ROLE_REGULAR |
|
2114 | 2100 |
|
2115 |
# A few common errors for confd |
|
2116 | 2101 |
CONFD_ERROR_UNKNOWN_ENTRY = _constants.CONFD_ERROR_UNKNOWN_ENTRY |
2117 | 2102 |
CONFD_ERROR_INTERNAL = _constants.CONFD_ERROR_INTERNAL |
2118 | 2103 |
CONFD_ERROR_ARGUMENT = _constants.CONFD_ERROR_ARGUMENT |
b/src/Ganeti/Confd/Types.hs | ||
---|---|---|
26 | 26 |
-} |
27 | 27 |
|
28 | 28 |
module Ganeti.Confd.Types |
29 |
( C.confdProtocolVersion |
|
30 |
, C.confdMaxClockSkew |
|
31 |
, C.confdConfigReloadTimeout |
|
32 |
, C.confdConfigReloadRatelimit |
|
33 |
, C.confdMagicFourcc |
|
34 |
, C.confdDefaultReqCoverage |
|
35 |
, C.confdClientExpireTimeout |
|
36 |
, C.maxUdpDataSize |
|
37 |
, ConfdClient(..) |
|
29 |
( ConfdClient(..) |
|
38 | 30 |
, ConfdRequestType(..) |
39 |
, ConfdReqQ(..)
|
|
31 |
, confdRequestTypeToRaw
|
|
40 | 32 |
, ConfdReqField(..) |
33 |
, confdReqFieldToRaw |
|
34 |
, ConfdReqQ(..) |
|
41 | 35 |
, ConfdReplyStatus(..) |
36 |
, confdReplyStatusToRaw |
|
42 | 37 |
, ConfdNodeRole(..) |
38 |
, confdNodeRoleToRaw |
|
43 | 39 |
, ConfdErrorType(..) |
40 |
, confdErrorTypeToRaw |
|
44 | 41 |
, ConfdRequest(..) |
45 | 42 |
, newConfdRequest |
46 | 43 |
, ConfdReply(..) |
... | ... | |
51 | 48 |
import Text.JSON |
52 | 49 |
import qualified Network.Socket as S |
53 | 50 |
|
54 |
import qualified Ganeti.Constants as C |
|
55 | 51 |
import qualified Ganeti.ConstantUtils as ConstantUtils |
56 | 52 |
import Ganeti.Hash |
57 | 53 |
import Ganeti.THH |
58 | 54 |
import Ganeti.Utils (newUUID) |
59 | 55 |
|
60 |
{- |
|
61 |
Note that we re-export as is from Constants the following simple items: |
|
62 |
- confdProtocolVersion |
|
63 |
- confdMaxClockSkew |
|
64 |
- confdConfigReloadTimeout |
|
65 |
- confdConfigReloadRatelimit |
|
66 |
- confdMagicFourcc |
|
67 |
- confdDefaultReqCoverage |
|
68 |
- confdClientExpireTimeout |
|
69 |
- maxUdpDataSize |
|
70 |
|
|
71 |
-} |
|
72 |
|
|
73 |
$(declareIADT "ConfdRequestType" |
|
74 |
[ ("ReqPing", 'C.confdReqPing ) |
|
75 |
, ("ReqNodeRoleByName", 'C.confdReqNodeRoleByname ) |
|
76 |
, ("ReqNodePipList", 'C.confdReqNodePipList ) |
|
77 |
, ("ReqNodePipByInstPip", 'C.confdReqNodePipByInstanceIp ) |
|
78 |
, ("ReqClusterMaster", 'C.confdReqClusterMaster ) |
|
79 |
, ("ReqMcPipList", 'C.confdReqMcPipList ) |
|
80 |
, ("ReqInstIpsList", 'C.confdReqInstancesIpsList ) |
|
81 |
, ("ReqNodeDrbd", 'C.confdReqNodeDrbd ) |
|
82 |
, ("ReqNodeInstances", 'C.confdReqNodeInstances) |
|
56 |
$(declareILADT "ConfdRequestType" |
|
57 |
[ ("ReqPing", 0) |
|
58 |
, ("ReqNodeRoleByName", 1) |
|
59 |
, ("ReqNodePipByInstPip", 2) |
|
60 |
, ("ReqClusterMaster", 3) |
|
61 |
, ("ReqNodePipList", 4) |
|
62 |
, ("ReqMcPipList", 5) |
|
63 |
, ("ReqInstIpsList", 6) |
|
64 |
, ("ReqNodeDrbd", 7) |
|
65 |
, ("ReqNodeInstances", 8) |
|
83 | 66 |
]) |
84 | 67 |
$(makeJSONInstance ''ConfdRequestType) |
85 | 68 |
|
86 |
$(declareSADT "ConfdReqField"
|
|
87 |
[ ("ReqFieldName", 'C.confdReqfieldName )
|
|
88 |
, ("ReqFieldIp", 'C.confdReqfieldIp )
|
|
89 |
, ("ReqFieldMNodePip", 'C.confdReqfieldMnodePip )
|
|
69 |
$(declareILADT "ConfdReqField"
|
|
70 |
[ ("ReqFieldName", 0)
|
|
71 |
, ("ReqFieldIp", 1)
|
|
72 |
, ("ReqFieldMNodePip", 2)
|
|
90 | 73 |
]) |
91 | 74 |
$(makeJSONInstance ''ConfdReqField) |
92 | 75 |
|
... | ... | |
128 | 111 |
PlainQuery s -> showJSON s |
129 | 112 |
DictQuery drq -> showJSON drq |
130 | 113 |
|
131 |
$(declareIADT "ConfdReplyStatus" |
|
132 |
[ ( "ReplyStatusOk", 'C.confdReplStatusOk )
|
|
133 |
, ( "ReplyStatusError", 'C.confdReplStatusError )
|
|
134 |
, ( "ReplyStatusNotImpl", 'C.confdReplStatusNotimplemented )
|
|
114 |
$(declareILADT "ConfdReplyStatus"
|
|
115 |
[ ("ReplyStatusOk", 0)
|
|
116 |
, ("ReplyStatusError", 1)
|
|
117 |
, ("ReplyStatusNotImpl", 2)
|
|
135 | 118 |
]) |
136 | 119 |
$(makeJSONInstance ''ConfdReplyStatus) |
137 | 120 |
|
138 |
$(declareIADT "ConfdNodeRole" |
|
139 |
[ ( "NodeRoleMaster", 'C.confdNodeRoleMaster )
|
|
140 |
, ( "NodeRoleCandidate", 'C.confdNodeRoleCandidate )
|
|
141 |
, ( "NodeRoleOffline", 'C.confdNodeRoleOffline )
|
|
142 |
, ( "NodeRoleDrained", 'C.confdNodeRoleDrained )
|
|
143 |
, ( "NodeRoleRegular", 'C.confdNodeRoleRegular )
|
|
121 |
$(declareILADT "ConfdNodeRole"
|
|
122 |
[ ("NodeRoleMaster", 0)
|
|
123 |
, ("NodeRoleCandidate", 1)
|
|
124 |
, ("NodeRoleOffline", 2)
|
|
125 |
, ("NodeRoleDrained", 3)
|
|
126 |
, ("NodeRoleRegular", 4)
|
|
144 | 127 |
]) |
145 | 128 |
$(makeJSONInstance ''ConfdNodeRole) |
146 | 129 |
|
147 |
|
|
148 | 130 |
-- Note that the next item is not a frozenset in Python, but we make |
149 | 131 |
-- it a separate type for safety |
150 | 132 |
|
151 |
$(declareIADT "ConfdErrorType" |
|
152 |
[ ( "ConfdErrorUnknownEntry", 'C.confdErrorUnknownEntry )
|
|
153 |
, ( "ConfdErrorInternal", 'C.confdErrorInternal )
|
|
154 |
, ( "ConfdErrorArgument", 'C.confdErrorArgument )
|
|
133 |
$(declareILADT "ConfdErrorType"
|
|
134 |
[ ("ConfdErrorUnknownEntry", 0)
|
|
135 |
, ("ConfdErrorInternal", 1)
|
|
136 |
, ("ConfdErrorArgument", 2)
|
|
155 | 137 |
]) |
156 | 138 |
$(makeJSONInstance ''ConfdErrorType) |
157 | 139 |
|
... | ... | |
167 | 149 |
newConfdRequest :: ConfdRequestType -> ConfdQuery -> IO ConfdRequest |
168 | 150 |
newConfdRequest reqType query = do |
169 | 151 |
rsalt <- newUUID |
170 |
return $ ConfdRequest C.confdProtocolVersion reqType query rsalt |
|
152 |
return $ ConfdRequest ConstantUtils.confdProtocolVersion reqType query rsalt
|
|
171 | 153 |
|
172 | 154 |
$(buildObject "ConfdReply" "confdReply" |
173 | 155 |
[ simpleField "protocol" [t| Int |] |
b/src/Ganeti/ConstantUtils.hs | ||
---|---|---|
109 | 109 |
buildVersion major minor revision = |
110 | 110 |
1000000 * major + 10000 * minor + 1 * revision |
111 | 111 |
|
112 |
-- | Confd protocol version |
|
113 |
-- |
|
114 |
-- This is defined here in order to avoid a circular dependency |
|
115 |
-- between 'Ganeti.Confd.Types' and 'Ganeti.HsConstants'. |
|
116 |
confdProtocolVersion :: Int |
|
117 |
confdProtocolVersion = 1 |
|
118 |
|
|
112 | 119 |
-- * Confd request query fields. |
113 | 120 |
-- |
114 | 121 |
-- These are defined here and not in 'Ganeti.Types' due to GHC stage |
b/src/Ganeti/HsConstants.hs | ||
---|---|---|
36 | 36 |
-} |
37 | 37 |
module Ganeti.HsConstants where |
38 | 38 |
|
39 |
import Data.List ((\\)) |
|
39 | 40 |
import Data.Map (Map) |
40 | 41 |
import qualified Data.Map as Map (fromList) |
41 | 42 |
|
... | ... | |
49 | 50 |
import qualified Ganeti.Runtime as Runtime |
50 | 51 |
import Ganeti.Types |
51 | 52 |
import qualified Ganeti.Types as Types |
53 |
import Ganeti.Confd.Types (ConfdRequestType(..), ConfdReqField(..), |
|
54 |
ConfdReplyStatus(..), ConfdNodeRole(..), |
|
55 |
ConfdErrorType(..)) |
|
56 |
import qualified Ganeti.Confd.Types as Types |
|
52 | 57 |
|
53 | 58 |
-- * 'autoconf' constants for Python only ('autotools/build-bash-completion') |
54 | 59 |
|
... | ... | |
154 | 159 |
protocolVersion = buildVersion configMajor configMinor configRevision |
155 | 160 |
|
156 | 161 |
-- * User separation |
162 |
|
|
157 | 163 |
daemonsGroup :: String |
158 | 164 |
daemonsGroup = Runtime.daemonGroup (ExtraGroup DaemonsGroup) |
159 | 165 |
|
... | ... | |
1225 | 1231 |
elogJqueueTest :: String |
1226 | 1232 |
elogJqueueTest = Types.eLogTypeToRaw ELogJqueueTest |
1227 | 1233 |
|
1234 |
-- * Confd |
|
1235 |
|
|
1236 |
confdProtocolVersion :: Int |
|
1237 |
confdProtocolVersion = ConstantUtils.confdProtocolVersion |
|
1238 |
|
|
1239 |
-- Confd request type |
|
1240 |
|
|
1241 |
confdReqPing :: Int |
|
1242 |
confdReqPing = Types.confdRequestTypeToRaw ReqPing |
|
1243 |
|
|
1244 |
confdReqNodeRoleByname :: Int |
|
1245 |
confdReqNodeRoleByname = Types.confdRequestTypeToRaw ReqNodeRoleByName |
|
1246 |
|
|
1247 |
confdReqNodePipByInstanceIp :: Int |
|
1248 |
confdReqNodePipByInstanceIp = Types.confdRequestTypeToRaw ReqNodePipByInstPip |
|
1249 |
|
|
1250 |
confdReqClusterMaster :: Int |
|
1251 |
confdReqClusterMaster = Types.confdRequestTypeToRaw ReqClusterMaster |
|
1252 |
|
|
1253 |
confdReqNodePipList :: Int |
|
1254 |
confdReqNodePipList = Types.confdRequestTypeToRaw ReqNodePipList |
|
1255 |
|
|
1256 |
confdReqMcPipList :: Int |
|
1257 |
confdReqMcPipList = Types.confdRequestTypeToRaw ReqMcPipList |
|
1258 |
|
|
1259 |
confdReqInstancesIpsList :: Int |
|
1260 |
confdReqInstancesIpsList = Types.confdRequestTypeToRaw ReqInstIpsList |
|
1261 |
|
|
1262 |
confdReqNodeDrbd :: Int |
|
1263 |
confdReqNodeDrbd = Types.confdRequestTypeToRaw ReqNodeDrbd |
|
1264 |
|
|
1265 |
confdReqNodeInstances :: Int |
|
1266 |
confdReqNodeInstances = Types.confdRequestTypeToRaw ReqNodeInstances |
|
1267 |
|
|
1268 |
confdReqs :: FrozenSet Int |
|
1269 |
confdReqs = |
|
1270 |
ConstantUtils.mkSet . |
|
1271 |
map Types.confdRequestTypeToRaw $ |
|
1272 |
[minBound..] \\ [ReqNodeInstances] |
|
1273 |
|
|
1274 |
-- * Confd request type |
|
1275 |
|
|
1276 |
confdReqfieldName :: Int |
|
1277 |
confdReqfieldName = Types.confdReqFieldToRaw ReqFieldName |
|
1278 |
|
|
1279 |
confdReqfieldIp :: Int |
|
1280 |
confdReqfieldIp = Types.confdReqFieldToRaw ReqFieldIp |
|
1281 |
|
|
1282 |
confdReqfieldMnodePip :: Int |
|
1283 |
confdReqfieldMnodePip = Types.confdReqFieldToRaw ReqFieldMNodePip |
|
1284 |
|
|
1285 |
-- * Confd repl status |
|
1286 |
|
|
1287 |
confdReplStatusOk :: Int |
|
1288 |
confdReplStatusOk = Types.confdReplyStatusToRaw ReplyStatusOk |
|
1289 |
|
|
1290 |
confdReplStatusError :: Int |
|
1291 |
confdReplStatusError = Types.confdReplyStatusToRaw ReplyStatusError |
|
1292 |
|
|
1293 |
confdReplStatusNotimplemented :: Int |
|
1294 |
confdReplStatusNotimplemented = Types.confdReplyStatusToRaw ReplyStatusNotImpl |
|
1295 |
|
|
1296 |
confdReplStatuses :: FrozenSet Int |
|
1297 |
confdReplStatuses = |
|
1298 |
ConstantUtils.mkSet $ map Types.confdReplyStatusToRaw [minBound..] |
|
1299 |
|
|
1300 |
-- * Confd node role |
|
1301 |
|
|
1302 |
confdNodeRoleMaster :: Int |
|
1303 |
confdNodeRoleMaster = Types.confdNodeRoleToRaw NodeRoleMaster |
|
1304 |
|
|
1305 |
confdNodeRoleCandidate :: Int |
|
1306 |
confdNodeRoleCandidate = Types.confdNodeRoleToRaw NodeRoleCandidate |
|
1307 |
|
|
1308 |
confdNodeRoleOffline :: Int |
|
1309 |
confdNodeRoleOffline = Types.confdNodeRoleToRaw NodeRoleOffline |
|
1310 |
|
|
1311 |
confdNodeRoleDrained :: Int |
|
1312 |
confdNodeRoleDrained = Types.confdNodeRoleToRaw NodeRoleDrained |
|
1313 |
|
|
1314 |
confdNodeRoleRegular :: Int |
|
1315 |
confdNodeRoleRegular = Types.confdNodeRoleToRaw NodeRoleRegular |
|
1316 |
|
|
1228 | 1317 |
-- * A few common errors for confd |
1229 | 1318 |
|
1230 |
confdErrorArgument :: Int
|
|
1231 |
confdErrorArgument = 3
|
|
1319 |
confdErrorUnknownEntry :: Int
|
|
1320 |
confdErrorUnknownEntry = Types.confdErrorTypeToRaw ConfdErrorUnknownEntry
|
|
1232 | 1321 |
|
1233 | 1322 |
confdErrorInternal :: Int |
1234 |
confdErrorInternal = 2
|
|
1323 |
confdErrorInternal = Types.confdErrorTypeToRaw ConfdErrorInternal
|
|
1235 | 1324 |
|
1236 |
confdErrorUnknownEntry :: Int
|
|
1237 |
confdErrorUnknownEntry = 1
|
|
1325 |
confdErrorArgument :: Int
|
|
1326 |
confdErrorArgument = Types.confdErrorTypeToRaw ConfdErrorArgument
|
|
1238 | 1327 |
|
1239 |
-- Confd request query fields |
|
1328 |
-- * Confd request query fields
|
|
1240 | 1329 |
|
1241 | 1330 |
confdReqqLink :: String |
1242 | 1331 |
confdReqqLink = ConstantUtils.confdReqqLink |
Also available in: Unified diff