+
+class InstanceIpToNodePrimaryIpQuery(ConfdQuery):
+ """A query for the location of an instance's ip.
+
+ 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):
+ """InstanceIpToNodePrimaryIpQuery main execution.
+
+ """
+ instance_ip = query
+ instance = self.reader.GetInstanceByIp(instance_ip)
+ if instance is None:
+ return QUERY_UNKNOWN_ENTRY_ERROR
+
+ pnode = self.reader.GetInstancePrimaryNode(instance)
+ if pnode is None:
+ # this shouldn't happen
+ logging.error("Internal configuration inconsistent (instance-to-pnode)")
+ return QUERY_INTERNAL_ERROR
+
+ pnode_primary_ip = self.reader.GetNodePrimaryIp(pnode)
+ if pnode_primary_ip is None:
+ # this shouldn't happen
+ logging.error("Internal configuration inconsistent (node-to-primary-ip)")
+ return QUERY_INTERNAL_ERROR
+
+ 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
+