From: Sage Weil Date: Mon, 26 Jun 2017 19:55:19 +0000 (-0400) Subject: mgr: expose daemon status to modules X-Git-Tag: v12.1.1~98^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8074944e096782a065e4e74ab5646e93dc74afb4;p=ceph.git mgr: expose daemon status to modules Signed-off-by: Sage Weil --- diff --git a/src/mgr/PyModules.cc b/src/mgr/PyModules.cc index 5b5d379abc34..113dd665d9c4 100644 --- a/src/mgr/PyModules.cc +++ b/src/mgr/PyModules.cc @@ -131,6 +131,18 @@ PyObject *PyModules::get_metadata_python( return f.get(); } +PyObject *PyModules::get_daemon_status_python( + std::string const &handle, + const std::string &svc_name, + const std::string &svc_id) +{ + auto metadata = daemon_state.get(DaemonKey(svc_name, svc_id)); + PyFormatter f; + for (const auto &i : metadata->service_status) { + f.dump_string(i.first.c_str(), i.second); + } + return f.get(); +} PyObject *PyModules::get_python(const std::string &what) { diff --git a/src/mgr/PyModules.h b/src/mgr/PyModules.h index 80f8813d5ee0..8e52e173062a 100644 --- a/src/mgr/PyModules.h +++ b/src/mgr/PyModules.h @@ -67,6 +67,9 @@ public: PyObject *get_metadata_python( std::string const &handle, const std::string &svc_name, const std::string &svc_id); + PyObject *get_daemon_status_python( + std::string const &handle, + const std::string &svc_name, const std::string &svc_id); PyObject *get_counter_python( std::string const &handle, const std::string &svc_name, diff --git a/src/mgr/PyState.cc b/src/mgr/PyState.cc index dbde1e225286..bd57bf9ae9e0 100644 --- a/src/mgr/PyState.cc +++ b/src/mgr/PyState.cc @@ -278,6 +278,19 @@ get_metadata(PyObject *self, PyObject *args) return global_handle->get_metadata_python(handle, svc_name, svc_id); } +static PyObject* +get_daemon_status(PyObject *self, PyObject *args) +{ + char *handle = nullptr; + char *svc_name = NULL; + char *svc_id = NULL; + if (!PyArg_ParseTuple(args, "sss:get_daemon_status", &handle, &svc_name, + &svc_id)) { + return nullptr; + } + return global_handle->get_daemon_status_python(handle, svc_name, svc_id); +} + static PyObject* ceph_log(PyObject *self, PyObject *args) { @@ -327,6 +340,8 @@ PyMethodDef CephStateMethods[] = { "Get a server object"}, {"get_metadata", get_metadata, METH_VARARGS, "Get a service's metadata"}, + {"get_daemon_status", get_daemon_status, METH_VARARGS, + "Get a service's status"}, {"send_command", ceph_send_command, METH_VARARGS, "Send a mon command"}, {"get_mgr_id", ceph_get_mgr_id, METH_NOARGS, diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 8d5b0f9de6f5..9d3362d75e92 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -140,6 +140,16 @@ class MgrModule(object): """ return ceph_state.get_metadata(self._handle, svc_type, svc_id) + def get_daemon_status(self, svc_type, svc_id): + """ + Fetch the latest status for a particular service daemon. + + :param svc_type: string (e.g., 'rgw') + :param svc_id: string + :return: dict + """ + return ceph_state.get_daemon_status(self._handle, svc_type, svc_id) + def send_command(self, *args, **kwargs): """ Called by the plugin to send a command to the mon