mirror of
https://github.com/ceph/ceph
synced 2025-04-21 23:06:05 +00:00
pybind/mgr/mgr_module: make use of defined default value
Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
1f3e9d4811
commit
0f814f38e5
src
@ -538,23 +538,31 @@ int PyModule::load_options()
|
|||||||
option.long_desc = PyString_AsString(p);
|
option.long_desc = PyString_AsString(p);
|
||||||
}
|
}
|
||||||
p = PyDict_GetItemString(pOption, "default");
|
p = PyDict_GetItemString(pOption, "default");
|
||||||
if (p && PyObject_TypeCheck(p, &PyString_Type)) {
|
if (p) {
|
||||||
option.default_value = PyString_AsString(p);
|
auto q = PyObject_Str(p);
|
||||||
|
option.default_value = PyString_AsString(q);
|
||||||
|
Py_DECREF(q);
|
||||||
}
|
}
|
||||||
p = PyDict_GetItemString(pOption, "min");
|
p = PyDict_GetItemString(pOption, "min");
|
||||||
if (p && PyObject_TypeCheck(p, &PyString_Type)) {
|
if (p) {
|
||||||
option.min = PyString_AsString(p);
|
auto q = PyObject_Str(p);
|
||||||
|
option.min = PyString_AsString(q);
|
||||||
|
Py_DECREF(q);
|
||||||
}
|
}
|
||||||
p = PyDict_GetItemString(pOption, "max");
|
p = PyDict_GetItemString(pOption, "max");
|
||||||
if (p && PyObject_TypeCheck(p, &PyString_Type)) {
|
if (p) {
|
||||||
option.max = PyString_AsString(p);
|
auto q = PyObject_Str(p);
|
||||||
|
option.max = PyString_AsString(q);
|
||||||
|
Py_DECREF(q);
|
||||||
}
|
}
|
||||||
p = PyDict_GetItemString(pOption, "enum_allowed");
|
p = PyDict_GetItemString(pOption, "enum_allowed");
|
||||||
if (p && PyObject_TypeCheck(p, &PyList_Type)) {
|
if (p && PyObject_TypeCheck(p, &PyList_Type)) {
|
||||||
for (unsigned i = 0; i < PyList_Size(p); ++i) {
|
for (unsigned i = 0; i < PyList_Size(p); ++i) {
|
||||||
auto q = PyList_GetItem(p, i);
|
auto q = PyList_GetItem(p, i);
|
||||||
if (q && PyObject_TypeCheck(q, &PyString_Type)) {
|
if (q) {
|
||||||
option.enum_allowed.insert(PyString_AsString(q));
|
auto r = PyObject_Str(q);
|
||||||
|
option.enum_allowed.insert(PyString_AsString(r));
|
||||||
|
Py_DECREF(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,8 @@ class MgrStandbyModule(ceph_module.BaseMgrStandbyModule):
|
|||||||
"""
|
"""
|
||||||
r = self._ceph_get_module_option(key)
|
r = self._ceph_get_module_option(key)
|
||||||
if r is None:
|
if r is None:
|
||||||
return default
|
final_key = key.split('/')[-1]
|
||||||
|
return str(self.MODULE_OPTION_DEFAULTS.get(final_key, default))
|
||||||
else:
|
else:
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@ -273,6 +274,7 @@ class MgrStandbyModule(ceph_module.BaseMgrStandbyModule):
|
|||||||
class MgrModule(ceph_module.BaseMgrModule):
|
class MgrModule(ceph_module.BaseMgrModule):
|
||||||
COMMANDS = []
|
COMMANDS = []
|
||||||
MODULE_OPTIONS = []
|
MODULE_OPTIONS = []
|
||||||
|
MODULE_OPTION_DEFAULTS = {}
|
||||||
|
|
||||||
# Priority definitions for perf counters
|
# Priority definitions for perf counters
|
||||||
PRIO_CRITICAL = 10
|
PRIO_CRITICAL = 10
|
||||||
@ -319,6 +321,10 @@ class MgrModule(ceph_module.BaseMgrModule):
|
|||||||
# Keep a librados instance for those that need it.
|
# Keep a librados instance for those that need it.
|
||||||
self._rados = None
|
self._rados = None
|
||||||
|
|
||||||
|
for o in self.MODULE_OPTIONS:
|
||||||
|
if 'default' in o:
|
||||||
|
self.MODULE_OPTION_DEFAULTS[o['name']] = o['default']
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
unconfigure_logger(self, self.module_name)
|
unconfigure_logger(self, self.module_name)
|
||||||
|
|
||||||
@ -694,7 +700,8 @@ class MgrModule(ceph_module.BaseMgrModule):
|
|||||||
def _get_module_option(self, key, default):
|
def _get_module_option(self, key, default):
|
||||||
r = self._ceph_get_module_option(key)
|
r = self._ceph_get_module_option(key)
|
||||||
if r is None:
|
if r is None:
|
||||||
return default
|
final_key = key.split('/')[-1]
|
||||||
|
return str(self.MODULE_OPTION_DEFAULTS.get(final_key, default))
|
||||||
else:
|
else:
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user