what, &value);
if (found) {
dout(10) << __func__ << " " << what << " found: " << value.c_str() << dendl;
- return PyString_FromString(value.c_str());
+ return self->this_module->py_module->get_typed_option_value(what, value);
} else {
dout(4) << __func__ << " " << what << " not found " << dendl;
Py_RETURN_NONE;
bool found = self->this_module->get_config(what, &value);
if (found) {
dout(10) << __func__ << " " << what << " found: " << value.c_str() << dendl;
- return PyString_FromString(value.c_str());
+ return self->this_module->py_module->get_typed_option_value(what, value);
} else {
dout(4) << __func__ << " " << what << " not found " << dendl;
Py_RETURN_NONE;
return options.count(option_name) > 0;
}
+PyObject *PyModule::get_typed_option_value(const std::string& name,
+ const std::string& value)
+{
+ auto p = options.find(name);
+ if (p != options.end()) {
+ switch (p->second.type) {
+ case Option::TYPE_INT:
+ case Option::TYPE_UINT:
+ case Option::TYPE_SIZE:
+ return PyInt_FromString((char *)value.c_str(), nullptr, 0);
+ case Option::TYPE_SECS:
+ case Option::TYPE_FLOAT:
+ {
+ PyObject *s = PyString_FromString(value.c_str());
+ PyObject *f = PyFloat_FromString(s, nullptr);
+ Py_DECREF(s);
+ return f;
+ }
+ case Option::TYPE_BOOL:
+ if (value == "1" || value == "true" || value == "True" ||
+ value == "on" || value == "yes") {
+ Py_INCREF(Py_True);
+ return Py_True;
+ } else {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
+ }
+ }
+ return PyString_FromString(value.c_str());
+}
+
int PyModule::load_subclass_of(const char* base_class, PyObject** py_class)
{
// load the base class
return options;
}
+ PyObject *get_typed_option_value(
+ const std::string& option,
+ const std::string& value);
+
int load(PyThreadState *pMainThreadState);
#if PY_MAJOR_VERSION >= 3
static PyObject* init_ceph_logger();
*/
class PyModuleRunner
{
-protected:
+public:
// Info about the module we're going to run
PyModuleRef py_module;
+protected:
// Populated by descendent class
PyObject *pClassInstance = nullptr;
r = self._ceph_get_module_option(key)
if r is None:
final_key = key.split('/')[-1]
- return str(self.MODULE_OPTION_DEFAULTS.get(final_key, default))
+ return self.MODULE_OPTION_DEFAULTS.get(final_key, default)
else:
return r
r = self._ceph_get_module_option(key)
if r is None:
final_key = key.split('/')[-1]
- return str(self.MODULE_OPTION_DEFAULTS.get(final_key, default))
+ return self.MODULE_OPTION_DEFAULTS.get(final_key, default)
else:
return r