Skip to content
Snippets Groups Projects
Commit 95b487bb authored by Flavio Silvestrow's avatar Flavio Silvestrow Committed by Guido Trotter
Browse files

confd: query the pnode of multiple instances at once


Signed-off-by: default avatarFlavio Silvestrow <flaviops@google.com>
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 3782acd7
No related branches found
No related tags found
No related merge requests found
...@@ -139,34 +139,55 @@ class NodeRoleQuery(ConfdQuery): ...@@ -139,34 +139,55 @@ class NodeRoleQuery(ConfdQuery):
class InstanceIpToNodePrimaryIpQuery(ConfdQuery): class InstanceIpToNodePrimaryIpQuery(ConfdQuery):
"""A query for the location of an instance's ip. """A query for the location of one or more instance's ips.
It returns the primary ip of the node hosting the instance having the Given a list of instance IPs, returns an ordered list with the same
requested ip address, or an error if no such address is known. number of elements as the input. Each element of the list is a tuple
containing the status (success or failure) and the content of the
query (IP of the primary node if successful, error constant if not).
If a string (instance's IP) is given instead of a list it will return
a single tuple, as opposed to a 1-element list containing that tuple.
""" """
def Exec(self, query): def Exec(self, query):
"""InstanceIpToNodePrimaryIpQuery main execution. """InstanceIpToNodePrimaryIpQuery main execution.
""" """
instance_ip = query if isinstance(query, list):
instance = self.reader.GetInstanceByIp(instance_ip) instances_list = query
if instance is None: else:
return QUERY_UNKNOWN_ENTRY_ERROR instances_list = [query]
pnodes_list = []
for instance_ip in instances_list:
instance = self.reader.GetInstanceByIp(instance_ip)
if not instance:
logging.debug("Invalid instance IP: %s" % instance)
pnodes_list.append(QUERY_UNKNOWN_ENTRY_ERROR)
continue
pnode = self.reader.GetInstancePrimaryNode(instance) pnode = self.reader.GetInstancePrimaryNode(instance)
if pnode is None: if not pnode:
# this shouldn't happen logging.error("Instance '%s' doesn't have an associated primary"
logging.error("Internal configuration inconsistent (instance-to-pnode)") " node" % instance)
return QUERY_INTERNAL_ERROR pnodes_list.append(QUERY_INTERNAL_ERROR)
continue
pnode_primary_ip = self.reader.GetNodePrimaryIp(pnode) pnode_primary_ip = self.reader.GetNodePrimaryIp(pnode)
if pnode_primary_ip is None: if not pnode_primary_ip:
# this shouldn't happen logging.error("Primary node '%s' doesn't have an associated"
logging.error("Internal configuration inconsistent (node-to-primary-ip)") " primary IP" % pnode)
return QUERY_INTERNAL_ERROR pnodes_list.append(QUERY_INTERNAL_ERROR)
continue
return constants.CONFD_REPL_STATUS_OK, pnode_primary_ip pnodes_list.append((constants.CONFD_REPL_STATUS_OK, pnode_primary_ip))
# If input was a string, return a tuple instead of a 1-element list
if isinstance(query, basestring):
return pnodes_list[0]
return constants.CONFD_REPL_STATUS_OK, pnodes_list
class NodesPipsQuery(ConfdQuery): class NodesPipsQuery(ConfdQuery):
...@@ -225,4 +246,3 @@ class InstancesIpsQuery(ConfdQuery): ...@@ -225,4 +246,3 @@ class InstancesIpsQuery(ConfdQuery):
answer = self.reader.GetInstancesIps(link) answer = self.reader.GetInstancesIps(link)
return status, answer return status, answer
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment