Commit d01ae714 authored by Luca Bigliardi's avatar Luca Bigliardi

Confd: add instances IPs query

Extend confd to answer queries about instances IPs.
Signed-off-by: default avatarLuca Bigliardi <shammash@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 3a541d90
......@@ -208,3 +208,23 @@ class MasterCandidatesPipsQuery(ConfdQuery):
return status, answer
class InstancesIpsQuery(ConfdQuery):
"""A query for instances IPs.
It returns the list of instances IPs.
"""
def Exec(self, query):
"""InstancesIpsQuery main execution.
"""
if query is None:
status = constants.CONFD_REPL_STATUS_OK
answer = self.reader.GetInstancesIps()
else:
status = constants.CONFD_REPL_STATUS_ERROR
answer = "non-empty instances IPs query"
return status, answer
......@@ -54,6 +54,7 @@ class ConfdProcessor(object):
constants.CONFD_REQ_CLUSTER_MASTER: querylib.ClusterMasterQuery,
constants.CONFD_REQ_NODE_PIP_LIST: querylib.NodesPipsQuery,
constants.CONFD_REQ_MC_PIP_LIST: querylib.MasterCandidatesPipsQuery,
constants.CONFD_REQ_INSTANCES_IPS_LIST: querylib.InstancesIpsQuery,
}
def __init__(self):
......
......@@ -641,6 +641,7 @@ 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_REQS = frozenset([
CONFD_REQ_PING,
......@@ -649,6 +650,7 @@ CONFD_REQS = frozenset([
CONFD_REQ_CLUSTER_MASTER,
CONFD_REQ_NODE_PIP_LIST,
CONFD_REQ_MC_PIP_LIST,
CONFD_REQ_INSTANCES_IPS_LIST,
])
CONFD_REPL_STATUS_OK = 0
......
......@@ -100,10 +100,12 @@ class SimpleConfigReader(object):
(self._file_name, err))
self._ip_to_instance = {}
self._instances_ips = []
for iname in self._config_data['instances']:
instance = self._config_data['instances'][iname]
for nic in instance['nics']:
if 'ip' in nic and nic['ip']:
self._instances_ips.append(nic['ip'])
self._ip_to_instance[nic['ip']] = iname
self._nodes_primary_ips = []
......@@ -201,6 +203,9 @@ class SimpleConfigReader(object):
def GetMasterCandidatesPrimaryIps(self):
return self._mc_primary_ips
def GetInstancesIps(self):
return self._instances_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