From: John Spray Date: Thu, 9 Nov 2017 11:27:24 +0000 (-0500) Subject: mgr: expose have_mon_connection to python modules X-Git-Tag: v12.2.5~3^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b159da60aae3702c07f63164631fe40b8fb85eec;p=ceph.git mgr: expose have_mon_connection to python modules So that they can warn their end users if the data we have is probably stale. Signed-off-by: John Spray (cherry picked from commit 5633328e28c0f7a5122229737c2ca132174a4349) --- diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index 74d1a948f306e..6777a5238881c 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -502,6 +502,16 @@ ceph_set_uri(BaseMgrModule *self, PyObject *args) Py_RETURN_NONE; } +static PyObject* +ceph_have_mon_connection(BaseMgrModule *self, PyObject *args) +{ + if (self->py_modules->get_monc().is_connected()) { + Py_RETURN_TRUE; + } else { + Py_RETURN_FALSE; + } +} + PyMethodDef BaseMgrModule_methods[] = { {"_ceph_get", (PyCFunction)ceph_state_get, METH_VARARGS, @@ -555,6 +565,10 @@ PyMethodDef BaseMgrModule_methods[] = { {"_ceph_set_uri", (PyCFunction)ceph_set_uri, METH_VARARGS, "Advertize a service URI served by this module"}, + {"_ceph_have_mon_connection", (PyCFunction)ceph_have_mon_connection, + METH_NOARGS, "Find out whether this mgr daemon currently has " + "a connection to a monitor"}, + {NULL, NULL, 0, NULL} }; diff --git a/src/mon/MonClient.h b/src/mon/MonClient.h index 0b24e01e2bace..703da88fa2bbb 100644 --- a/src/mon/MonClient.h +++ b/src/mon/MonClient.h @@ -224,6 +224,8 @@ public: int authenticate(double timeout=0.0); bool is_authenticated() const {return authenticated;} + bool is_connected() const { return active_con != nullptr; } + /** * Try to flush as many log messages as we can in a single * message. Use this before shutting down to transmit your diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 1d75b6f431ba3..be4510265f9d0 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -573,3 +573,13 @@ class MgrModule(ceph_module.BaseMgrModule): :return: a string """ return self._ceph_set_uri(uri) + + def have_mon_connection(self): + """ + Check whether this ceph-mgr daemon has an open connection + to a monitor. If it doesn't, then it's likely that the + information we have about the cluster is out of date, + and/or the monitor cluster is down. + """ + + return self._ceph_have_mon_connection() \ No newline at end of file