diff --git a/lib/confd/client.py b/lib/confd/client.py index efcb68d3361272fc8d0e88f81d0d8f88f84b0336..dfbc650630b0f52fffc8368664d0c5ba4c9d8c88 100644 --- a/lib/confd/client.py +++ b/lib/confd/client.py @@ -60,6 +60,7 @@ from ganeti import serializer from ganeti import daemon # contains AsyncUDPSocket from ganeti import errors from ganeti import confd +from ganeti import ssconf class ConfdAsyncUDPClient(daemon.AsyncUDPSocket): @@ -494,3 +495,20 @@ class ConfdCountingCallback: elif up.type == UPCALL_EXPIRE: self._HandleExpire(up) self._callback(up) + +def GetConfdClient(callback): + """Return a client configured using the given callback. + + This is handy to abstract the MC list and HMAC key reading. + + @attention: This should only be called on nodes which are part of a + cluster, since it depends on a valid (ganeti) data directory; + for code running outside of a cluster, you need to create the + client manually + + """ + ss = ssconf.SimpleStore() + mc_file = ss.KeyToFilename(constants.SS_MASTER_CANDIDATES_IPS) + mc_list = utils.ReadFile(mc_file).splitlines() + hmac_key = utils.ReadFile(constants.CONFD_HMAC_KEY) + return ConfdClient(hmac_key, mc_list, callback) diff --git a/tools/burnin b/tools/burnin index a7ca79a8cfbd624528263b0e3465158486dfedbc..5ab5e87cc392dc7ceb2a92a93cc2b5fa473b774f 100755 --- a/tools/burnin +++ b/tools/burnin @@ -36,7 +36,6 @@ from ganeti import constants from ganeti import cli from ganeti import errors from ganeti import utils -from ganeti import ssconf from ganeti.confd import client as confd_client @@ -266,7 +265,6 @@ class Burner(object): self.hvp = self.bep = None self.ParseOptions() self.cl = cli.GetClient() - self.ss = ssconf.SimpleStore() self.GetState() def ClearFeedbackBuf(self): @@ -885,15 +883,11 @@ class Burner(object): """ Log("Checking confd results") - hmac_key = utils.ReadFile(constants.CONFD_HMAC_KEY) - mc_file = self.ss.KeyToFilename(constants.SS_MASTER_CANDIDATES_IPS) - mc_list = utils.ReadFile(mc_file).splitlines() filter_callback = confd_client.ConfdFilterCallback(self.ConfdCallback) counting_callback = confd_client.ConfdCountingCallback(filter_callback) self.confd_counting_callback = counting_callback - self.confd_client = confd_client.ConfdClient(hmac_key, mc_list, - counting_callback) + self.confd_client = confd_client.GetConfdClient(counting_callback) req = confd_client.ConfdClientRequest(type=constants.CONFD_REQ_PING) self.DoConfdRequestReply(req)