Commit 250554a9 authored by Guido Trotter's avatar Guido Trotter
Browse files

confd ClusterMasterQuery: allow fields request



Change the ClusterMasterQuery to allow a query, and if present accept a
list of fields to be returned. Currently only name and ip are accepted.

This feature will be used by NLD to route the cluster ip over the nbma.

Backwards compatibility is preserved.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
parent 016308cb
......@@ -98,12 +98,29 @@ class ClusterMasterQuery(ConfdQuery):
"""ClusterMasterQuery main execution
"""
if query is None:
if isinstance(query, dict):
if constants.CONFD_REQQ_FIELDS in query:
status = constants.CONFD_REPL_STATUS_OK
req_fields = query[constants.CONFD_REQQ_FIELDS]
if not isinstance(req_fields, (list, tuple)):
logging.debug("FIELDS request should be a list")
return QUERY_ARGUMENT_ERROR
answer = []
for field in req_fields:
if field == constants.CONFD_REQFIELD_NAME:
answer.append(self.reader.GetMasterNode())
elif field == constants.CONFD_REQFIELD_IP:
answer.append(self.reader.GetMasterIP())
else:
logging.debug("missing FIELDS in query dict")
return QUERY_ARGUMENT_ERROR
elif not query:
status = constants.CONFD_REPL_STATUS_OK
answer = self.reader.GetMasterNode()
else:
status = constants.CONFD_REPL_STATUS_ERROR
answer = 'master query accepts no query argument'
logging.debug("Invalid master query argument: not dict or empty")
return QUERY_ARGUMENT_ERROR
return status, answer
......
......@@ -687,6 +687,10 @@ CONFD_REQ_INSTANCES_IPS_LIST = 6
CONFD_REQQ_LINK = "0"
CONFD_REQQ_IP = "1"
CONFD_REQQ_IPLIST = "2"
CONFD_REQQ_FIELDS = "3"
CONFD_REQFIELD_NAME = "0"
CONFD_REQFIELD_IP = "1"
CONFD_REQS = frozenset([
CONFD_REQ_PING,
......
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