pybind/mgr/mgr_module: add get_option()

get_config() gets a mgr-style config option.  Add get_option which
fetches a compiled-in config option.

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2018-09-19 14:33:16 -05:00
parent b4c17cca15
commit 4fc2af95ce
2 changed files with 26 additions and 0 deletions

View File

@ -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"},

View File

@ -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