confd: add cluster master query
authorGuido Trotter <ultrotter@google.com>
Mon, 31 Aug 2009 14:54:20 +0000 (15:54 +0100)
committerGuido Trotter <ultrotter@google.com>
Mon, 31 Aug 2009 15:43:45 +0000 (16:43 +0100)
Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/confd/querylib.py
lib/confd/server.py
lib/constants.py

index af0c32d..b299034 100644 (file)
@@ -82,6 +82,25 @@ class PingQuery(ConfdQuery):
 
     return status, answer
 
+class ClusterMasterQuery(ConfdQuery):
+  """Cluster master query.
+
+  It accepts no arguments, and returns the current cluster master.
+
+  """
+  def Exec(self, query):
+    """ClusterMasterQuery main execution
+
+    """
+    if query is None:
+      status = constants.CONFD_REPL_STATUS_OK
+      answer = self.reader.GetMasterNode()
+    else:
+      status = constants.CONFD_REPL_STATUS_ERROR
+      answer = 'master query accepts no query argument'
+
+    return status, answer
+
 
 class NodeRoleQuery(ConfdQuery):
   """A query for the role of a node.
index 601b957..f27b225 100644 (file)
@@ -51,6 +51,7 @@ class ConfdProcessor(object):
       constants.CONFD_REQ_NODE_ROLE_BYNAME: querylib.NodeRoleQuery,
       constants.CONFD_REQ_NODE_PIP_BY_INSTANCE_IP:
         querylib.InstanceIpToNodePrimaryIpQuery,
+      constants.CONFD_REQ_CLUSTER_MASTER: querylib.ClusterMasterQuery,
   }
 
   def __init__(self):
index 5384765..80a663a 100644 (file)
@@ -638,11 +638,13 @@ CONFD_PROTOCOL_VERSION = 1
 CONFD_REQ_PING = 0
 CONFD_REQ_NODE_ROLE_BYNAME = 1
 CONFD_REQ_NODE_PIP_BY_INSTANCE_IP = 2
+CONFD_REQ_CLUSTER_MASTER = 3
 
 CONFD_REQS = frozenset([
   CONFD_REQ_PING,
   CONFD_REQ_NODE_ROLE_BYNAME,
   CONFD_REQ_NODE_PIP_BY_INSTANCE_IP,
+  CONFD_REQ_CLUSTER_MASTER,
   ])
 
 CONFD_REPL_STATUS_OK = 0