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.
Backwards compatibility is preserved. Signed-off-by: Guido Trotter <[email protected]> --- lib/confd/querylib.py | 23 ++++++++++++++++++++--- lib/constants.py | 4 ++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/confd/querylib.py b/lib/confd/querylib.py index 17621dd..f757760 100644 --- a/lib/confd/querylib.py +++ b/lib/confd/querylib.py @@ -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 diff --git a/lib/constants.py b/lib/constants.py index 9ff3958..07493cd 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -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, -- 1.6.5
