This implements CONFD_REQ_NODE_PIP_BY_INSTANCE_IP, and maps instance ips to primary node ips.
Signed-off-by: Guido Trotter <ultrot...@google.com> --- lib/confd/querylib.py | 34 ++++++++++++++++++++++++++++++++++ lib/confd/server.py | 3 ++- 2 files changed, 36 insertions(+), 1 deletions(-) diff --git a/lib/confd/querylib.py b/lib/confd/querylib.py index fa4ff51..23c9c33 100644 --- a/lib/confd/querylib.py +++ b/lib/confd/querylib.py @@ -23,6 +23,8 @@ """ +import logging + from ganeti import constants @@ -112,3 +114,35 @@ class NodeRoleQuery(ConfdQuery): return constants.CONFD_REPL_STATUS_OK, answer + +class InstanceIPToNodePrimaryIPQuery(ConfdQuery): + """An empty confd query. + + It will return success on an empty argument, and an error on any other argument. + + """ + def Exec(self, query): + """EmptyQuery main execution + + """ + instance_ip = query + instance = self.reader.GetInstanceByIP(instance_ip) + if instance is None: + return self.UnknownEntryError + + pnode = self.reader.GetInstancePrimaryNode(instance) + if pnode is None: + # this shouldn't happen + msg = "Internal configuration inconsistent (instance-to-pnode)" + logging.error(msg) + return self.InternalError + + pnode_primary_ip = self.reader.GetNodePrimaryIP(pnode) + if pnode_primary_ip is None: + # this shouldn't happen + msg = "Internal configuration inconsistent (node-to-primary-ip)" + logging.error(msg) + return self.InternalError + + return constants.CONFD_REPL_STATUS_OK, pnode_primary_ip + diff --git a/lib/confd/server.py b/lib/confd/server.py index a39a535..0cacfae 100644 --- a/lib/confd/server.py +++ b/lib/confd/server.py @@ -45,7 +45,8 @@ class ConfdProcessor(object): DISPATCH_TABLE = { constants.CONFD_REQ_PING: querylib.PingQuery, constants.CONFD_REQ_NODE_ROLE_BYNAME: querylib.NodeRoleQuery, - constants.CONFD_REQ_NODE_PIP_BY_INSTANCE_IP: querylib.ConfdQuery, + constants.CONFD_REQ_NODE_PIP_BY_INSTANCE_IP: + querylib.InstanceIPToNodePrimaryIPQuery, } def __init__(self, reader): -- 1.5.6.5