#include "common/errno.h"
#include "common/version.h"
+#include "PyUtil.h"
#include "BaseMgrModule.h"
#include "Gil.h"
return nullptr;
}
- std::string value;
- int r = g_conf().get_val(string(what), &value);
- if (r >= 0) {
+ const Option *opt = g_conf().find_option(string(what));
+ if (opt) {
+ std::string value;
+ int r = g_conf().get_val(string(what), &value);
+ assert(r >= 0);
dout(10) << "ceph_option_get " << what << " found: " << value << dendl;
- return PyString_FromString(value.c_str());
+ return get_python_typed_option_value(opt->type, value);
} else {
dout(4) << "ceph_option_get " << what << " not found " << dendl;
Py_RETURN_NONE;
OSDPerfMetricTypes.cc
OSDPerfMetricCollector.cc
PyFormatter.cc
+ PyUtil.cc
PyModule.cc
PyModuleRegistry.cc
PyModuleRunner.cc
#include "BaseMgrStandbyModule.h"
#include "PyOSDMap.h"
#include "MgrContext.h"
+#include "PyUtil.h"
#include "PyModule.h"
// are set up exactly once during startup.
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 get_python_typed_option_value((Option::type_t)p->second.type, value);
}
return PyString_FromString(value.c_str());
}
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "PyUtil.h"
+#include "PythonCompat.h"
+
+PyObject *get_python_typed_option_value(
+ Option::type_t type,
+ const std::string& value)
+{
+ switch (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;
+ }
+ case Option::TYPE_STR:
+ case Option::TYPE_ADDR:
+ case Option::TYPE_ADDRVEC:
+ case Option::TYPE_UUID:
+ break;
+ }
+ return PyString_FromString(value.c_str());
+}
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include <string>
+
+#include "Python.h"
+#include "common/options.h"
+
+PyObject *get_python_typed_option_value(
+ Option::type_t type,
+ const std::string& value);