Revision 9748ab35
b/daemons/ganeti-confd | ||
---|---|---|
43 | 43 |
from ganeti import ssconf |
44 | 44 |
from ganeti.asyncnotifier import AsyncNotifier |
45 | 45 |
from ganeti.confd.server import ConfdProcessor |
46 |
from ganeti.confd import PackMagic, UnpackMagic |
|
46 | 47 |
|
47 | 48 |
|
48 | 49 |
class ConfdAsyncUDPServer(daemon.AsyncUDPSocket): |
... | ... | |
69 | 70 |
|
70 | 71 |
# this method is overriding a daemon.AsyncUDPSocket method |
71 | 72 |
def handle_datagram(self, payload_in, ip, port): |
72 |
|
|
73 |
if len(payload_in) < len(constants.CONFD_MAGIC_FOURCC): |
|
74 |
logging.debug("Received a query which is too short to be true") |
|
75 |
return |
|
76 |
|
|
77 |
magic_number = payload_in[:4] |
|
78 |
query = payload_in[4:] |
|
79 |
|
|
80 |
if magic_number != constants.CONFD_MAGIC_FOURCC: |
|
81 |
logging.debug("Received a query with an unknown magic number") |
|
73 |
try: |
|
74 |
query = UnpackMagic(payload_in) |
|
75 |
except errors.ConfdMagicError, err: |
|
76 |
logging.debug(err) |
|
82 | 77 |
return |
83 | 78 |
|
84 | 79 |
answer = self.processor.ExecQuery(query, ip, port) |
85 | 80 |
if answer is not None: |
86 |
payload_out = ''.join([constants.CONFD_MAGIC_FOURCC, answer]) |
|
87 | 81 |
try: |
88 |
self.enqueue_send(ip, port, payload_out)
|
|
82 |
self.enqueue_send(ip, port, PackMagic(answer))
|
|
89 | 83 |
except errors.UdpDataSizeError: |
90 | 84 |
logging.error("Reply too big to fit in an udp packet.") |
91 | 85 |
|
b/lib/confd/__init__.py | ||
---|---|---|
19 | 19 |
# 02110-1301, USA. |
20 | 20 |
|
21 | 21 |
|
22 |
"""Ganeti confd library |
|
22 |
"""Ganeti confd client/server library
|
|
23 | 23 |
|
24 | 24 |
""" |
25 |
|
|
26 |
from ganeti import constants |
|
27 |
|
|
28 |
|
|
29 |
_FOURCC_LEN = 4 |
|
30 |
|
|
31 |
|
|
32 |
def PackMagic(payload): |
|
33 |
"""Prepend the confd magic fourcc to a payload. |
|
34 |
|
|
35 |
""" |
|
36 |
return ''.join([constants.CONFD_MAGIC_FOURCC, payload]) |
|
37 |
|
|
38 |
|
|
39 |
def UnpackMagic(payload): |
|
40 |
"""Unpack and check the confd magic fourcc from a payload. |
|
41 |
|
|
42 |
""" |
|
43 |
if len(payload) < _FOURCC_LEN: |
|
44 |
raise errors.ConfdMagicError("UDP payload too short to contain the" |
|
45 |
" fourcc code") |
|
46 |
|
|
47 |
magic_number = payload[:_FOURCC_LEN] |
|
48 |
if magic_number != constants.CONFD_MAGIC_FOURCC: |
|
49 |
raise errors.ConfdMagicError("UDP payload contains an unkown fourcc") |
|
50 |
|
|
51 |
return payload[_FOURCC_LEN:] |
|
52 |
|
b/lib/errors.py | ||
---|---|---|
297 | 297 |
""" |
298 | 298 |
|
299 | 299 |
|
300 |
class ConfdMagicError(GenericError): |
|
301 |
"""A magic fourcc error in Ganeti confd. |
|
302 |
|
|
303 |
Errors processing the fourcc in ganeti confd datagrams. |
|
304 |
|
|
305 |
""" |
|
306 |
|
|
307 |
|
|
300 | 308 |
class UdpDataSizeError(GenericError): |
301 | 309 |
"""UDP payload too big. |
302 | 310 |
|
Also available in: Unified diff