Unify the “--backend-parameters” option
[ganeti-local] / lib / confd / querylib.py
index 74ce458..11dad04 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#
 #
 
 # Copyright (C) 2009, Google Inc.
@@ -27,12 +27,14 @@ import logging
 
 from ganeti import constants
 
+
 # constants for some common errors to return from a query
 QUERY_UNKNOWN_ENTRY_ERROR = (constants.CONFD_REPL_STATUS_ERROR,
                              constants.CONFD_ERROR_UNKNOWN_ENTRY)
 QUERY_INTERNAL_ERROR = (constants.CONFD_REPL_STATUS_ERROR,
                         constants.CONFD_ERROR_INTERNAL)
 
+
 class ConfdQuery(object):
   """Confd Query base class.
 
@@ -66,11 +68,12 @@ class ConfdQuery(object):
 class PingQuery(ConfdQuery):
   """An empty confd query.
 
-  It will return success on an empty argument, and an error on any other argument.
+  It will return success on an empty argument, and an error on any other
+  argument.
 
   """
   def Exec(self, query):
-    """EmptyQuery main execution
+    """PingQuery main execution.
 
     """
     if query is None:
@@ -83,10 +86,30 @@ 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):
-  """An empty confd query.
+  """A query for the role of a node.
 
-  It will return success on an empty argument, and an error on any other argument.
+  It will return one of CONFD_NODE_ROLE_*, or an error for non-existing nodes.
 
   """
   def Exec(self, query):
@@ -116,13 +139,14 @@ class NodeRoleQuery(ConfdQuery):
 
 
 class InstanceIpToNodePrimaryIpQuery(ConfdQuery):
-  """An empty confd query.
+  """A query for the location of an instance's ip.
 
-  It will return success on an empty argument, and an error on any other argument.
+  It returns the primary ip of the node hosting the instance having the
+  requested ip address, or an error if no such address is known.
 
   """
   def Exec(self, query):
-    """EmptyQuery main execution
+    """InstanceIpToNodePrimaryIpQuery main execution.
 
     """
     instance_ip = query
@@ -144,3 +168,43 @@ class InstanceIpToNodePrimaryIpQuery(ConfdQuery):
 
     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
+