Fetch a dict of all config options with a given prefix.
Signed-off-by: Sage Weil <sage@redhat.com>
}
}
+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)
{
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);
}
}
+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)
{
"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,
"""
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