]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/mgr_module: add get_option()
authorSage Weil <sage@redhat.com>
Wed, 19 Sep 2018 19:33:16 +0000 (14:33 -0500)
committerSage Weil <sage@redhat.com>
Tue, 16 Oct 2018 12:22:48 +0000 (07:22 -0500)
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>
src/mgr/BaseMgrModule.cc
src/pybind/mgr/mgr_module.py

index 5c587b91cbc326ee0edc68872c4fa414bad6cd4f..038490dedadf2b46d7889ab645a7357e2308381d 100644 (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"},
 
index cc5079c5ad9f0288ed79089f9ca125396b1963cb..3c9510fbdabb7c36e1bd7ecf37ce914cb6ddce1f 100644 (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