From: Sage Weil Date: Tue, 29 Jun 2021 22:46:36 +0000 (-0400) Subject: mgr: add get() for standby modules X-Git-Tag: v16.2.5~10^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8ffe9ab0ffbb56123f0f7eecdc5792423c4045ec;p=ceph.git mgr: add get() for standby modules Fixes: https://tracker.ceph.com/issues/51446 Signed-off-by: Sage Weil (cherry picked from commit 8b8e7522982476d25685ad055d4a89f6173041f8) --- diff --git a/src/mgr/BaseMgrStandbyModule.cc b/src/mgr/BaseMgrStandbyModule.cc index 84c9b79f2f7b..6f35088d0309 100644 --- a/src/mgr/BaseMgrStandbyModule.cc +++ b/src/mgr/BaseMgrStandbyModule.cc @@ -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 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"}, diff --git a/src/mgr/StandbyPyModules.h b/src/mgr/StandbyPyModules.h index b434c917c7ae..501dfc8c7e40 100644 --- a/src/mgr/StandbyPyModules.h +++ b/src/mgr/StandbyPyModules.h @@ -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(); }; diff --git a/src/pybind/mgr/ceph_module.pyi b/src/pybind/mgr/ceph_module.pyi index 75575aeca150..4a5bac33f3e1 100644 --- a/src/pybind/mgr/ceph_module.pyi +++ b/src/pybind/mgr/ceph_module.pyi @@ -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):... diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 4e39b2306770..dd558ec61eec 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -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()