Commit e16e4824 authored by Guido Trotter's avatar Guido Trotter

Implement confd queries

We'll start with a simple ping query, which returns ok if it gets no
query argument, and an error if it gets any. Also non-implemented query
are handled by the base ConfdQuery class, so we don't have to
special-case them in ConfdProcessor anymore.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 09444532
......@@ -114,7 +114,8 @@ http_PYTHON = \
confd_PYTHON = \
lib/confd/__init__.py \
lib/confd/server.py
lib/confd/server.py \
lib/confd/querylib.py
docrst = \
doc/admin.rst \
......
#!/usr/bin/python
#
# Copyright (C) 2009, Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Ganeti configuration daemon queries library.
"""
from ganeti import constants
class ConfdQuery(object):
"""Confd Query base class.
"""
def __init__(self, reader):
"""Constructor for Confd Query
@type reader: L{ssconf.SimpleConfigReader}
@param reader: ConfigReader to use to access the config
"""
self.reader = reader
def Exec(self, query):
"""Process a single UDP request from a client.
Different queries should override this function, which by defaults returns
a "non-implemented" answer.
@type query: (undefined)
@param query: ConfdRequest 'query' field
@rtype: (integer, undefined)
@return: status and answer to give to the client
"""
status = constants.CONFD_REPL_STATUS_NOTIMPLEMENTED
answer = 'not implemented'
return status, answer
class PingQuery(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
"""
if query is None:
status = constants.CONFD_REPL_STATUS_OK
answer = 'ok'
else:
status = constants.CONFD_REPL_STATUS_ERROR
answer = 'non-empty ping query'
return status, answer
......@@ -35,12 +35,17 @@ from ganeti import errors
from ganeti import utils
from ganeti import serializer
from ganeti.confd import querylib
class ConfdProcessor(object):
"""A processor for confd requests.
"""
DISPATCH_TABLE = {
constants.CONFD_REQ_PING: querylib.PingQuery,
constants.CONFD_REQ_NODE_ROLE_BYNAME: querylib.ConfdQuery,
constants.CONFD_REQ_NODE_PIP_BY_INSTANCE_IP: querylib.ConfdQuery,
}
def __init__(self, reader):
......@@ -127,16 +132,17 @@ class ConfdProcessor(object):
raise errors.ConfdRequestError(msg)
if request.type not in self.DISPATCH_TABLE:
answer = 'not implemented'
status = constants.CONFD_REPL_STATUS_NOTIMPLEMENTED
reply = objects.ConfdReply(
protocol=constants.CONFD_PROTOCOL_VERSION,
status=status,
answer=answer,
)
else:
# TODO: actually dispatch queries to some classes to handle them
assert False, "DISPATCH_TABLE is populated but handler is not"
msg = "Valid request %d not in DISPATCH_TABLE" % request.type
raise errors.ProgrammerError(msg)
query_object = self.DISPATCH_TABLE[request.type](self.reader)
status, answer = query_object.Exec(request.query)
reply = objects.ConfdReply(
protocol=constants.CONFD_PROTOCOL_VERSION,
status=status,
answer=answer,
serial=self.reader.GetConfigSerialNo(),
)
logging.debug("Sending reply: %s" % reply)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment