From: Sage Weil Date: Fri, 2 Jun 2017 14:24:39 +0000 (-0400) Subject: mgr: add get_config_prefix X-Git-Tag: v12.1.0~213^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1ebc3f12aabb3534f6218a0478dc6fe2f02d3201;p=ceph.git mgr: add get_config_prefix Fetch a dict of all config options with a given prefix. Signed-off-by: Sage Weil --- diff --git a/src/mgr/PyModules.cc b/src/mgr/PyModules.cc index 3b3962241d9..6a3929d67cc 100644 --- a/src/mgr/PyModules.cc +++ b/src/mgr/PyModules.cc @@ -512,6 +512,26 @@ bool PyModules::get_config(const std::string &handle, } } +PyObject *PyModules::get_config_prefix(const std::string &handle, + const std::string &prefix) const +{ + PyThreadState *tstate = PyEval_SaveThread(); + Mutex::Locker l(lock); + PyEval_RestoreThread(tstate); + + const std::string base_prefix = config_prefix + handle + "/"; + const std::string global_prefix = base_prefix + prefix; + dout(4) << __func__ << "prefix: " << global_prefix << dendl; + + PyFormatter f; + for (auto p = config_cache.lower_bound(global_prefix); + p != config_cache.end() && p->first.find(global_prefix) == 0; + ++p) { + f.dump_string(p->first.c_str() + base_prefix.size(), p->second); + } + return f.get(); +} + void PyModules::set_config(const std::string &handle, const std::string &key, const std::string &val) { diff --git a/src/mgr/PyModules.h b/src/mgr/PyModules.h index 4c858747306..6a71b649331 100644 --- a/src/mgr/PyModules.h +++ b/src/mgr/PyModules.h @@ -92,6 +92,8 @@ public: bool get_config(const std::string &handle, const std::string &key, std::string *val) const; + PyObject *get_config_prefix(const std::string &handle, + const std::string &prefix) const; void set_config(const std::string &handle, const std::string &key, const std::string &val); diff --git a/src/mgr/PyState.cc b/src/mgr/PyState.cc index 0b99e684ae8..c39efdab289 100644 --- a/src/mgr/PyState.cc +++ b/src/mgr/PyState.cc @@ -213,6 +213,19 @@ ceph_config_get(PyObject *self, PyObject *args) } } +static PyObject* +ceph_config_get_prefix(PyObject *self, PyObject *args) +{ + char *handle = nullptr; + char *prefix = nullptr; + if (!PyArg_ParseTuple(args, "ss:ceph_config_get", &handle, &prefix)) { + derr << "Invalid args!" << dendl; + return nullptr; + } + + return global_handle->get_config_prefix(handle, prefix); +} + static PyObject* ceph_config_set(PyObject *self, PyObject *args) { @@ -323,6 +336,8 @@ PyMethodDef CephStateMethods[] = { "Get the mgr id"}, {"get_config", ceph_config_get, METH_VARARGS, "Get a configuration value"}, + {"get_config_prefix", ceph_config_get_prefix, METH_VARARGS, + "Get all configuration values with a given prefix"}, {"set_config", ceph_config_set, METH_VARARGS, "Set a configuration value"}, {"get_counter", get_counter, METH_VARARGS, diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 03f642e0577..e76aa04be8a 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -182,6 +182,15 @@ class MgrModule(object): """ return ceph_state.get_config(self._handle, key) + def get_config_prefix(self, key_prefix): + """ + Retrieve a dict of config values with the given prefix + + :param key_prefix: str + :return: str + """ + return ceph_state.get_config_prefix(self._handle, key_prefix) + def set_config(self, key, val): """ Set the value of a persistent configuration setting