]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: add get_config_prefix
authorSage Weil <sage@redhat.com>
Fri, 2 Jun 2017 14:24:39 +0000 (10:24 -0400)
committerSage Weil <sage@redhat.com>
Thu, 8 Jun 2017 18:29:37 +0000 (14:29 -0400)
Fetch a dict of all config options with a given prefix.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/PyModules.cc
src/mgr/PyModules.h
src/mgr/PyState.cc
src/pybind/mgr/mgr_module.py

index 3b3962241d94c60a3047a2a43b1c9d319c378a17..6a3929d67cc509e2e4e9052328552ec354410fcd 100644 (file)
@@ -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)
 {
index 4c858747306fa6224aad02807d11be9a42bffb6d..6a71b64933116fca5fa12c88ae96950048a362ed 100644 (file)
@@ -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);
 
index 0b99e684ae81be586484a35ca725a78d6528599d..c39efdab289451f3035d9a1a4a8d48be57109e78 100644 (file)
@@ -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,
index 03f642e0577a6b36e1e148887ed8592567ae44a7..e76aa04be8a487244bce772b1f908e1f2a9981c0 100644 (file)
@@ -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