]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: expose daemon status to modules
authorSage Weil <sage@redhat.com>
Mon, 26 Jun 2017 19:55:19 +0000 (15:55 -0400)
committerSage Weil <sage@redhat.com>
Sun, 9 Jul 2017 18:09:04 +0000 (14:09 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/PyModules.cc
src/mgr/PyModules.h
src/mgr/PyState.cc
src/pybind/mgr/mgr_module.py

index 5b5d379abc34f721303192af99c9127caac45ac6..113dd665d9c4a1b2837147e61cd3c3d84ee9fb08 100644 (file)
@@ -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)
 {
index 80f8813d5ee0c502efe46172dc6b226da766c963..8e52e173062ae2f1c5f539a2193ef0fba4bbf532 100644 (file)
@@ -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,
index dbde1e2252867bd088d36809c6fe56422735de42..bd57bf9ae9e054d4fa704039ebc1f987a76c374b 100644 (file)
@@ -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,
index 8d5b0f9de6f5b818ea66584575376a9163660726..9d3362d75e922ec9d72915e6817da91d4fafddc7 100644 (file)
@@ -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