Commit 9748ab35 authored by Guido Trotter's avatar Guido Trotter
Browse files

Move fourcc packing/unpacking to main confd module

This way it can be used by the client as well
Signed-off-by: default avatarGuido Trotter <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 28a34a39
......@@ -43,6 +43,7 @@ from ganeti import daemon
from ganeti import ssconf
from ganeti.asyncnotifier import AsyncNotifier
from ganeti.confd.server import ConfdProcessor
from ganeti.confd import PackMagic, UnpackMagic
class ConfdAsyncUDPServer(daemon.AsyncUDPSocket):
......@@ -69,23 +70,16 @@ class ConfdAsyncUDPServer(daemon.AsyncUDPSocket):
# this method is overriding a daemon.AsyncUDPSocket method
def handle_datagram(self, payload_in, ip, port):
if len(payload_in) < len(constants.CONFD_MAGIC_FOURCC):
logging.debug("Received a query which is too short to be true")
magic_number = payload_in[:4]
query = payload_in[4:]
if magic_number != constants.CONFD_MAGIC_FOURCC:
logging.debug("Received a query with an unknown magic number")
query = UnpackMagic(payload_in)
except errors.ConfdMagicError, err:
answer = self.processor.ExecQuery(query, ip, port)
if answer is not None:
payload_out = ''.join([constants.CONFD_MAGIC_FOURCC, answer])
self.enqueue_send(ip, port, payload_out)
self.enqueue_send(ip, port, PackMagic(answer))
except errors.UdpDataSizeError:
logging.error("Reply too big to fit in an udp packet.")
......@@ -19,6 +19,34 @@
# 02110-1301, USA.
"""Ganeti confd library
"""Ganeti confd client/server library
from ganeti import constants
def PackMagic(payload):
"""Prepend the confd magic fourcc to a payload.
return ''.join([constants.CONFD_MAGIC_FOURCC, payload])
def UnpackMagic(payload):
"""Unpack and check the confd magic fourcc from a payload.
if len(payload) < _FOURCC_LEN:
raise errors.ConfdMagicError("UDP payload too short to contain the"
" fourcc code")
magic_number = payload[:_FOURCC_LEN]
if magic_number != constants.CONFD_MAGIC_FOURCC:
raise errors.ConfdMagicError("UDP payload contains an unkown fourcc")
return payload[_FOURCC_LEN:]
......@@ -297,6 +297,14 @@ class ConfdRequestError(GenericError):
class ConfdMagicError(GenericError):
"""A magic fourcc error in Ganeti confd.
Errors processing the fourcc in ganeti confd datagrams.
class UdpDataSizeError(GenericError):
"""UDP payload too big.
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