]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: add get() for standby modules
authorSage Weil <sage@newdream.net>
Tue, 29 Jun 2021 22:46:36 +0000 (18:46 -0400)
committerSage Weil <sage@newdream.net>
Wed, 30 Jun 2021 15:20:06 +0000 (11:20 -0400)
Fixes: https://tracker.ceph.com/issues/51446
Signed-off-by: Sage Weil <sage@newdream.net>
(cherry picked from commit 8b8e7522982476d25685ad055d4a89f6173041f8)

src/mgr/BaseMgrStandbyModule.cc
src/mgr/StandbyPyModules.h
src/pybind/mgr/ceph_module.pyi
src/pybind/mgr/mgr_module.py

index 84c9b79f2f7bab51d3045235021873e259ffeea3..6f35088d0309e74d94faed0e99619f52d705667a 100644 (file)
@@ -15,6 +15,7 @@
 #include "BaseMgrStandbyModule.h"
 
 #include "StandbyPyModules.h"
+#include "PyFormatter.h"
 
 
 #define dout_context g_ceph_context
@@ -164,7 +165,46 @@ ceph_log(BaseMgrStandbyModule *self, PyObject *args)
   Py_RETURN_NONE;
 }
 
+static PyObject*
+ceph_standby_state_get(BaseMgrStandbyModule *self, PyObject *args)
+{
+  char *whatc = NULL;
+  if (!PyArg_ParseTuple(args, "s:ceph_state_get", &whatc)) {
+    return NULL;
+  }
+  std::string what(whatc);
+
+  PyFormatter f;
+
+  // Drop the GIL, as most of the following blocks will block on
+  // a mutex -- they are all responsible for re-taking the GIL before
+  // touching the PyFormatter instance or returning from the function.
+  without_gil_t no_gil;
+
+  if (what == "mgr_ips") {
+    entity_addrvec_t myaddrs = self->this_module->get_myaddrs();
+    with_gil_t with_gil{no_gil};
+    f.open_array_section("ips");
+    std::set<std::string> did;
+    for (auto& i : myaddrs.v) {
+      std::string ip = i.ip_only_to_str();
+      if (auto [where, inserted] = did.insert(ip); inserted) {
+       f.dump_string("ip", ip);
+      }
+    }
+    f.close_section();
+    return f.get();
+  } else {
+    derr << "Python module requested unknown data '" << what << "'" << dendl;
+    with_gil_t with_gil{no_gil};
+    Py_RETURN_NONE;
+  }
+}
+
+
 PyMethodDef BaseMgrStandbyModule_methods[] = {
+  {"_ceph_get", (PyCFunction)ceph_standby_state_get, METH_VARARGS,
+   "Get a cluster object (standby)"},
 
   {"_ceph_get_mgr_id", (PyCFunction)ceph_get_mgr_id, METH_NOARGS,
    "Get the name of the Mgr daemon where we are running"},
index b434c917c7aec15b984f211b451a4ea26b832113..501dfc8c7e408ad7392c3a7067ace6668ad3b184 100644 (file)
@@ -93,6 +93,9 @@ class StandbyPyModule : public PyModuleRunner
   bool get_config(const std::string &key, std::string *value) const;
   bool get_store(const std::string &key, std::string *value) const;
   std::string get_active_uri() const;
+  entity_addrvec_t get_myaddrs() const {
+    return state.get_monc().get_myaddrs();
+  }
 
   int load();
 };
index 75575aeca150f2df17349c65f139428a5ed476b9..4a5bac33f3e1b8869cfcb653961ac2a3c145fe72 100644 (file)
@@ -39,6 +39,7 @@ class BasePyCRUSH(object):
 
 class BaseMgrStandbyModule(object):
     def __init__(self, capsule): pass
+    def _ceph_get(self, data_name: str) -> Dict[str, Any]: ...
     def _ceph_get_mgr_id(self):...
     def _ceph_get_module_option(self, key, prefix=None):...
     def _ceph_get_option(self, key):...
index 4e39b2306770bc4babee7326d675f22e33657c6d..dd558ec61eecf1b4bb5b8454443bea7b81dd4dd0 100644 (file)
@@ -795,6 +795,9 @@ class MgrStandbyModule(ceph_module.BaseMgrStandbyModule, MgrModuleLoggingMixin):
     def get_active_uri(self) -> str:
         return self._ceph_get_active_uri()
 
+    def get(self, data_name: str):
+        return self._ceph_get(data_name)
+
     def get_mgr_ip(self) -> str:
         # we don't have get() for standby modules; make do with the hostname
         return socket.gethostname()