root / lib / confd / __init__.py @ 31d3b918
History | View | Annotate | Download (1.8 kB)
1 | 12426ae1 | Guido Trotter | #
|
---|---|---|---|
2 | 12426ae1 | Guido Trotter | #
|
3 | 12426ae1 | Guido Trotter | |
4 | 7acbda7b | Iustin Pop | # Copyright (C) 2009, 2012 Google Inc.
|
5 | 12426ae1 | Guido Trotter | #
|
6 | 12426ae1 | Guido Trotter | # This program is free software; you can redistribute it and/or modify
|
7 | 12426ae1 | Guido Trotter | # it under the terms of the GNU General Public License as published by
|
8 | 12426ae1 | Guido Trotter | # the Free Software Foundation; either version 2 of the License, or
|
9 | 12426ae1 | Guido Trotter | # (at your option) any later version.
|
10 | 12426ae1 | Guido Trotter | #
|
11 | 12426ae1 | Guido Trotter | # This program is distributed in the hope that it will be useful, but
|
12 | 12426ae1 | Guido Trotter | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 12426ae1 | Guido Trotter | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 12426ae1 | Guido Trotter | # General Public License for more details.
|
15 | 12426ae1 | Guido Trotter | #
|
16 | 12426ae1 | Guido Trotter | # You should have received a copy of the GNU General Public License
|
17 | 12426ae1 | Guido Trotter | # along with this program; if not, write to the Free Software
|
18 | 12426ae1 | Guido Trotter | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 12426ae1 | Guido Trotter | # 02110-1301, USA.
|
20 | 12426ae1 | Guido Trotter | |
21 | 12426ae1 | Guido Trotter | |
22 | 9748ab35 | Guido Trotter | """Ganeti confd client/server library
|
23 | 12426ae1 | Guido Trotter |
|
24 | 12426ae1 | Guido Trotter | """
|
25 | 9748ab35 | Guido Trotter | |
26 | 9748ab35 | Guido Trotter | from ganeti import constants |
27 | 6855f043 | Guido Trotter | from ganeti import errors |
28 | 7acbda7b | Iustin Pop | from ganeti import ht |
29 | 9748ab35 | Guido Trotter | |
30 | 9748ab35 | Guido Trotter | |
31 | 9748ab35 | Guido Trotter | _FOURCC_LEN = 4
|
32 | 9748ab35 | Guido Trotter | |
33 | 9748ab35 | Guido Trotter | |
34 | 7acbda7b | Iustin Pop | #: Items in the individual rows of the NodeDrbd query
|
35 | 7acbda7b | Iustin Pop | _HTNodeDrbdItems = [ht.TString, ht.TInt, ht.TString, |
36 | 7acbda7b | Iustin Pop | ht.TString, ht.TString, ht.TString] |
37 | 7acbda7b | Iustin Pop | #: Type for the (top-level) result of NodeDrbd query
|
38 | 7acbda7b | Iustin Pop | HTNodeDrbd = ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(len(_HTNodeDrbdItems)),
|
39 | 7acbda7b | Iustin Pop | ht.TItems(_HTNodeDrbdItems))) |
40 | 7acbda7b | Iustin Pop | |
41 | 7acbda7b | Iustin Pop | |
42 | 9748ab35 | Guido Trotter | def PackMagic(payload): |
43 | 9748ab35 | Guido Trotter | """Prepend the confd magic fourcc to a payload.
|
44 | 9748ab35 | Guido Trotter |
|
45 | 9748ab35 | Guido Trotter | """
|
46 | 3ccb3a64 | Michael Hanselmann | return "".join([constants.CONFD_MAGIC_FOURCC, payload]) |
47 | 9748ab35 | Guido Trotter | |
48 | 9748ab35 | Guido Trotter | |
49 | 9748ab35 | Guido Trotter | def UnpackMagic(payload): |
50 | 9748ab35 | Guido Trotter | """Unpack and check the confd magic fourcc from a payload.
|
51 | 9748ab35 | Guido Trotter |
|
52 | 9748ab35 | Guido Trotter | """
|
53 | 9748ab35 | Guido Trotter | if len(payload) < _FOURCC_LEN: |
54 | 9748ab35 | Guido Trotter | raise errors.ConfdMagicError("UDP payload too short to contain the" |
55 | 9748ab35 | Guido Trotter | " fourcc code")
|
56 | 9748ab35 | Guido Trotter | |
57 | 9748ab35 | Guido Trotter | magic_number = payload[:_FOURCC_LEN] |
58 | 9748ab35 | Guido Trotter | if magic_number != constants.CONFD_MAGIC_FOURCC:
|
59 | 9748ab35 | Guido Trotter | raise errors.ConfdMagicError("UDP payload contains an unkown fourcc") |
60 | 9748ab35 | Guido Trotter | |
61 | 9748ab35 | Guido Trotter | return payload[_FOURCC_LEN:] |