diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index 5c587b91cbc..038490dedad 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -347,6 +347,26 @@ ceph_get_mgr_id(BaseMgrModule *self, PyObject *args) return PyString_FromString(g_conf()->name.get_id().c_str()); } +static PyObject* +ceph_option_get(BaseMgrModule *self, PyObject *args) +{ + char *what = nullptr; + if (!PyArg_ParseTuple(args, "s:ceph_option_get", &what)) { + derr << "Invalid args!" << dendl; + return nullptr; + } + + std::string value; + int r = g_conf().get_val(string(what), &value); + if (r >= 0) { + dout(10) << "ceph_option_get " << what << " found: " << value << dendl; + return PyString_FromString(value.c_str()); + } else { + dout(4) << "ceph_config_get " << what << " not found " << dendl; + Py_RETURN_NONE; + } +} + static PyObject* ceph_config_get(BaseMgrModule *self, PyObject *args) { @@ -690,6 +710,9 @@ PyMethodDef BaseMgrModule_methods[] = { {"_ceph_get_mgr_id", (PyCFunction)ceph_get_mgr_id, METH_NOARGS, "Get the name of the Mgr daemon where we are running"}, + {"_ceph_get_option", (PyCFunction)ceph_option_get, METH_VARARGS, + "Get a configuration option value"}, + {"_ceph_get_config", (PyCFunction)ceph_config_get, METH_VARARGS, "Get a configuration value"}, diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index cc5079c5ad9..3c9510fbdab 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -630,6 +630,9 @@ class MgrModule(ceph_module.BaseMgrModule): """ return self._ceph_get_mgr_id() + def get_option(self, key): + return self._ceph_get_option(key) + def _validate_option(self, key): """ Helper: don't allow get/set config callers to