Revision 5b349fd1 lib/confd/client.py
b/lib/confd/client.py | ||
---|---|---|
60 | 60 |
from ganeti import daemon # contains AsyncUDPSocket |
61 | 61 |
from ganeti import errors |
62 | 62 |
from ganeti import confd |
63 |
from ganeti import ssconf |
|
63 | 64 |
|
64 | 65 |
|
65 | 66 |
class ConfdAsyncUDPClient(daemon.AsyncUDPSocket): |
... | ... | |
494 | 495 |
elif up.type == UPCALL_EXPIRE: |
495 | 496 |
self._HandleExpire(up) |
496 | 497 |
self._callback(up) |
498 |
|
|
499 |
def GetConfdClient(callback): |
|
500 |
"""Return a client configured using the given callback. |
|
501 |
|
|
502 |
This is handy to abstract the MC list and HMAC key reading. |
|
503 |
|
|
504 |
@attention: This should only be called on nodes which are part of a |
|
505 |
cluster, since it depends on a valid (ganeti) data directory; |
|
506 |
for code running outside of a cluster, you need to create the |
|
507 |
client manually |
|
508 |
|
|
509 |
""" |
|
510 |
ss = ssconf.SimpleStore() |
|
511 |
mc_file = ss.KeyToFilename(constants.SS_MASTER_CANDIDATES_IPS) |
|
512 |
mc_list = utils.ReadFile(mc_file).splitlines() |
|
513 |
hmac_key = utils.ReadFile(constants.CONFD_HMAC_KEY) |
|
514 |
return ConfdClient(hmac_key, mc_list, callback) |
Also available in: Unified diff