PyObject *ActivePyModules::get_typed_config(
const std::string &module_name,
- const std::string &key) const
+ const std::string &key,
+ const std::string &prefix) const
{
PyThreadState *tstate = PyEval_SaveThread();
std::string value;
- bool found = get_config(module_name, key, &value);
+ std::string final_key;
+ bool found = false;
+ if (prefix.size()) {
+ final_key = prefix + "/" + key;
+ found = get_config(module_name, final_key, &value);
+ }
+ if (!found) {
+ final_key = key;
+ found = get_config(module_name, final_key, &value);
+ }
if (found) {
PyModuleRef module = py_module_registry.get_module(module_name);
PyEval_RestoreThread(tstate);
derr << "Module '" << module_name << "' is not available" << dendl;
Py_RETURN_NONE;
}
- dout(10) << __func__ << " " << key << " found: " << value << dendl;
+ dout(10) << __func__ << " " << final_key << " found: " << value << dendl;
return module->get_typed_option_value(key, value);
}
PyEval_RestoreThread(tstate);
- dout(4) << __func__ << " " << key << " not found " << dendl;
+ if (prefix.size()) {
+ dout(4) << __func__ << " [" << prefix << "/]" << key << " not found "
+ << dendl;
+ } else {
+ dout(4) << __func__ << " " << key << " not found " << dendl;
+ }
Py_RETURN_NONE;
}
const std::string &key, const boost::optional<std::string> &val);
PyObject *get_typed_config(const std::string &module_name,
- const std::string &key) const;
+ const std::string &key,
+ const std::string &prefix) const;
void set_health_checks(const std::string& module_name,
health_check_map_t&& checks);
{
char *module = nullptr;
char *key = nullptr;
- if (!PyArg_ParseTuple(args, "ss:ceph_get_module_option", &module, &key)) {
+ char *prefix = nullptr;
+ if (!PyArg_ParseTuple(args, "sss:ceph_get_module_option", &module, &key,
+ &prefix)) {
derr << "Invalid args!" << dendl;
return nullptr;
}
- auto pResult = self->py_modules->get_typed_config(module, key);
+ std::string str_prefix;
+ if (prefix) {
+ str_prefix = prefix;
+ }
+ assert(self->this_module->py_module);
+ auto pResult = self->py_modules->get_typed_config(module, key, str_prefix);
return pResult;
}
ceph_get_module_option(BaseMgrStandbyModule *self, PyObject *args)
{
char *what = nullptr;
- if (!PyArg_ParseTuple(args, "s:ceph_get_module_option", &what)) {
+ char *prefix = nullptr;
+ if (!PyArg_ParseTuple(args, "ss:ceph_get_module_option", &what)) {
derr << "Invalid args!" << dendl;
return nullptr;
}
-
+ std::string final_key;
std::string value;
- bool found = self->this_module->get_config(what, &value);
+ bool found = false;
+ if (prefix) {
+ final_key = std::string(prefix) + "/" + what;
+ found = self->this_module->get_config(final_key, &value);
+ }
+ if (!found) {
+ final_key = what;
+ found = self->this_module->get_config(final_key, &value);
+ }
if (found) {
- dout(10) << __func__ << " " << what << " found: " << value.c_str() << dendl;
+ dout(10) << __func__ << " " << final_key << " found: " << value.c_str()
+ << dendl;
return self->this_module->py_module->get_typed_option_value(what, value);
} else {
- dout(4) << __func__ << " " << what << " not found " << dendl;
+ if (prefix) {
+ dout(4) << __func__ << " [" << prefix << "/]" << what << " not found "
+ << dendl;
+ } else {
+ dout(4) << __func__ << " " << what << " not found " << dendl;
+ }
Py_RETURN_NONE;
}
}
:param default: the default value of the config if it is not found
:return: str
"""
- r = self._ceph_get_module_option(key)
+ r = self._ceph_get_module_option(key, "")
if r is None:
final_key = key.split('/')[-1]
return self.MODULE_OPTION_DEFAULTS.get(final_key, default)
return self._ceph_get_active_uri()
def get_localized_module_option(self, key, default=None):
- r = self.get_module_option(self.get_mgr_id() + '/' + key)
+ r = self._ceph_get_module_option(key, self.get_mgr_id())
if r is None:
- r = self.get_module_option(key)
-
- if r is None:
- r = default
- return r
+ final_key = key.split('/')[-1]
+ return self.MODULE_OPTION_DEFAULTS.get(final_key, default)
+ else:
+ return r
class MgrModule(ceph_module.BaseMgrModule):
raise RuntimeError("Config option '{0}' is not in {1}.MODULE_OPTIONS".
format(key, self.__class__.__name__))
- def _get_module_option(self, key, default):
- r = self._ceph_get_module_option(self.module_name, key)
+ def _get_module_option(self, key, default, localized_prefix=""):
+ r = self._ceph_get_module_option(self.module_name, key,
+ localized_prefix)
if r is None:
final_key = key.split('/')[-1]
return self.MODULE_OPTION_DEFAULTS.get(final_key, default)
"""
if module == self.module_name:
self._validate_module_option(key)
- r = self._ceph_get_module_option(module, key)
+ r = self._ceph_get_module_option(module, key, "")
return default if r is None else r
def get_store_prefix(self, key_prefix):
:return: str
"""
self._validate_module_option(key)
- r = self._ceph_get_module_option(
- self.module_name, '{}/{}'.format(self.get_mgr_id(), key))
- if r is None:
- r = self._ceph_get_module_option(self.module_name, key)
- if r is None:
- final_key = key.split('/')[-1]
- r = self.MODULE_OPTION_DEFAULTS.get(final_key, default)
- return r
+ return self._get_module_option(key, default, self.get_mgr_id())
def _set_module_option(self, key, val):
return self._ceph_set_module_option(self.module_name, key, str(val))