Commit efbb4fd2 authored by Luca Bigliardi's avatar Luca Bigliardi
Browse files

Confd: add primary IPs queries



Extend confd to answer queries about nodes primary IPs and master candidates
primary IPs.
Signed-off-by: default avatarLuca Bigliardi <shammash@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent e1081705
......@@ -167,3 +167,44 @@ class InstanceIpToNodePrimaryIpQuery(ConfdQuery):
return QUERY_INTERNAL_ERROR
return constants.CONFD_REPL_STATUS_OK, pnode_primary_ip
class NodesPipsQuery(ConfdQuery):
"""A query for nodes primary IPs.
It returns the list of nodes primary IPs.
"""
def Exec(self, query):
"""NodesPipsQuery main execution.
"""
if query is None:
status = constants.CONFD_REPL_STATUS_OK
answer = self.reader.GetNodesPrimaryIps()
else:
status = constants.CONFD_REPL_STATUS_ERROR
answer = "non-empty node primary IPs query"
return status, answer
class MasterCandidatesPipsQuery(ConfdQuery):
"""A query for master candidates primary IPs.
It returns the list of master candidates primary IPs.
"""
def Exec(self, query):
"""MasterCandidatesPipsQuery main execution.
"""
if query is None:
status = constants.CONFD_REPL_STATUS_OK
answer = self.reader.GetMasterCandidatesPrimaryIps()
else:
status = constants.CONFD_REPL_STATUS_ERROR
answer = "non-empty master candidates primary IPs query"
return status, answer
......@@ -52,6 +52,8 @@ class ConfdProcessor(object):
constants.CONFD_REQ_NODE_PIP_BY_INSTANCE_IP:
querylib.InstanceIpToNodePrimaryIpQuery,
constants.CONFD_REQ_CLUSTER_MASTER: querylib.ClusterMasterQuery,
constants.CONFD_REQ_NODE_PIP_LIST: querylib.NodesPipsQuery,
constants.CONFD_REQ_MC_PIP_LIST: querylib.MasterCandidatesPipsQuery,
}
def __init__(self):
......
......@@ -639,12 +639,16 @@ 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_REQS = frozenset([
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_REPL_STATUS_OK = 0
......
......@@ -106,6 +106,14 @@ class SimpleConfigReader(object):
if 'ip' in nic and nic['ip']:
self._ip_to_instance[nic['ip']] = iname
self._nodes_primary_ips = []
self._mc_primary_ips = []
for node_name in self._config_data["nodes"]:
node = self._config_data["nodes"][node_name]
self._nodes_primary_ips.append(node["primary_ip"])
if node["master_candidate"]:
self._mc_primary_ips.append(node["primary_ip"])
return True
# Clients can request a reload of the config file, so we export our internal
......@@ -187,6 +195,12 @@ class SimpleConfigReader(object):
return None
return self._config_data["instances"][instance]["primary_node"]
def GetNodesPrimaryIps(self):
return self._nodes_primary_ips
def GetMasterCandidatesPrimaryIps(self):
return self._mc_primary_ips
class SimpleStore(object):
"""Interface to static cluster data.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment