return site_packages.str();
}
+#if PY_MAJOR_VERSION >= 3
+PyObject* PyModule::init_ceph_logger()
+{
+ auto py_logger = PyModule_Create(&ceph_logger_module);
+ PySys_SetObject("stderr", py_logger);
+ PySys_SetObject("stdout", py_logger);
+ return py_logger;
+}
+#else
+void PyModule::init_ceph_logger()
+{
+ auto py_logger = Py_InitModule("ceph_logger", log_methods);
+ PySys_SetObject(const_cast<char*>("stderr"), py_logger);
+ PySys_SetObject(const_cast<char*>("stdout"), py_logger);
+}
+#endif
+
+#if PY_MAJOR_VERSION >= 3
+PyObject* PyModule::init_ceph_module()
+#else
+void PyModule::init_ceph_module()
+#endif
+{
+ static PyMethodDef module_methods[] = {
+ {nullptr, nullptr, 0, nullptr}
+ };
+#if PY_MAJOR_VERSION >= 3
+ static PyModuleDef ceph_module_def = {
+ PyModuleDef_HEAD_INIT,
+ "ceph_module",
+ nullptr,
+ -1,
+ module_methods,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr
+ };
+ PyObject *ceph_module = PyModule_Create(&ceph_module_def);
+#else
+ PyObject *ceph_module = Py_InitModule("ceph_module", module_methods);
+#endif
+ assert(ceph_module != nullptr);
+ std::map<const char*, PyTypeObject*> classes{
+ {{"BaseMgrModule", &BaseMgrModuleType},
+ {"BaseMgrStandbyModule", &BaseMgrStandbyModuleType},
+ {"BasePyOSDMap", &BasePyOSDMapType},
+ {"BasePyOSDMapIncremental", &BasePyOSDMapIncrementalType},
+ {"BasePyCRUSH", &BasePyCRUSHType}}
+ };
+ for (auto [name, type] : classes) {
+ type->tp_new = PyType_GenericNew;
+ if (PyType_Ready(type) < 0) {
+ assert(0);
+ }
+ Py_INCREF(type);
+
+ PyModule_AddObject(ceph_module, name, (PyObject *)type);
+ }
+#if PY_MAJOR_VERSION >= 3
+ return ceph_module;
+#endif
+}
int PyModule::load(PyThreadState *pMainThreadState)
{
assert(pMainThreadState != nullptr);
- // Configure sub-interpreter and construct C++-generated python classes
+ // Configure sub-interpreter
{
SafeThreadState sts(pMainThreadState);
Gil gil(sts);
const char *argv[] = {"ceph-mgr"};
PySys_SetArgv(1, (char**)argv);
#endif
-
- if (g_conf->daemonize) {
-#if PY_MAJOR_VERSION >= 3
- auto py_logger = PyModule_Create(&ceph_logger_module);
- PySys_SetObject("stderr", py_logger);
- PySys_SetObject("stdout", py_logger);
-#else
- auto py_logger = Py_InitModule("ceph_logger", log_methods);
- PySys_SetObject(const_cast<char*>("stderr"), py_logger);
- PySys_SetObject(const_cast<char*>("stdout"), py_logger);
-#endif
- }
-
// Configure sys.path to include mgr_module_path
string paths = (":" + get_site_packages() +
":" + g_conf->get_val<std::string>("mgr_module_path"));
dout(10) << "Computed sys.path '" << sys_path << "'" << dendl;
#endif
}
-
- static PyMethodDef module_methods[] = {
- {nullptr}
- };
-#if PY_MAJOR_VERSION >= 3
- static PyModuleDef ceph_module_def = {
- PyModuleDef_HEAD_INIT,
- "ceph_module",
- nullptr,
- -1,
- module_methods,
- };
-#endif
-
- // Initialize module
-#if PY_MAJOR_VERSION >= 3
- PyObject *ceph_module = PyModule_Create(&ceph_module_def);
-#else
- PyObject *ceph_module = Py_InitModule("ceph_module", module_methods);
-#endif
- assert(ceph_module != nullptr);
-
- auto load_class = [ceph_module](const char *name, PyTypeObject *type)
- {
- type->tp_new = PyType_GenericNew;
- if (PyType_Ready(type) < 0) {
- assert(0);
- }
- Py_INCREF(type);
-
- PyModule_AddObject(ceph_module, name, (PyObject *)type);
- };
-
- load_class("BaseMgrModule", &BaseMgrModuleType);
- load_class("BaseMgrStandbyModule", &BaseMgrStandbyModuleType);
- load_class("BasePyOSDMap", &BasePyOSDMapType);
- load_class("BasePyOSDMapIncremental", &BasePyOSDMapIncrementalType);
- load_class("BasePyCRUSH", &BasePyCRUSHType);
}
-
// Environment is all good, import the external module
{
Gil gil(pMyThreadState);