MCPcopy Create free account
hub / github.com/ceph/ceph / get_python

Method get_python

src/mgr/ActivePyModules.cc:237–554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235}
236
237PyObject *ActivePyModules::get_python(std::string_view what, const bool get_mutable)
238{
239 const bool use_cache =
240 !get_mutable &&
241 api_cache.is_enabled() &&
242 api_cache.is_cacheable(what) &&
243 PyGILState_Check();
244
245 PyFormatter py_formatter;
246 PyFormatterRO py_formatter_ro;
247 PyFormatter &f = use_cache ? (PyFormatter&)py_formatter_ro :
248 py_formatter;
249 if (what == "fs_map") {
250 without_gil_t no_gil;
251 cluster_state.with_fsmap([&](const FSMap &fsmap) {
252 no_gil.acquire_gil();
253 fsmap.dump(&f);
254 });
255 } else if (what == "osdmap_crush_map_text") {
256 without_gil_t no_gil;
257 bufferlist rdata;
258 cluster_state.with_osdmap([&](const OSDMap &osd_map){
259 osd_map.crush->encode(rdata, CEPH_FEATURES_SUPPORTED_DEFAULT);
260 });
261 std::string crush_text = rdata.to_str();
262 no_gil.acquire_gil();
263 return PyUnicode_FromString(crush_text.c_str());
264 } else if (what.substr(0, 7) == "osd_map") {
265 without_gil_t no_gil;
266 cluster_state.with_osdmap([&](const OSDMap &osd_map){
267 no_gil.acquire_gil();
268 if (what == "osd_map") {
269 osd_map.dump(&f, g_ceph_context);
270 } else if (what == "osd_map_tree") {
271 osd_map.print_tree(&f, nullptr);
272 } else if (what == "osd_map_crush") {
273 osd_map.crush->dump(&f);
274 }
275 });
276 } else if (what == "modified_config_options") {
277 without_gil_t no_gil;
278 auto all_daemons = daemon_state.get_all();
279 std::set<string> names;
280 for (auto& [key, daemon] : all_daemons) {
281 std::lock_guard l(daemon->lock);
282 for (auto& [name, valmap] : daemon->config) {
283 names.insert(name);
284 }
285 }
286 no_gil.acquire_gil();
287 f.open_array_section("options");
288 for (auto& name : names) {
289 f.dump_string("name", name);
290 }
291 f.close_section();
292 } else if (what.substr(0, 6) == "config") {
293 // We make a copy of the global config to avoid printing
294 // to py formater (which may drop-take GIL) while holding

Callers

nothing calls this directly

Calls 15

with_gilFunction · 0.85
pg_state_stringFunction · 0.85
stringifyFunction · 0.85
is_cacheableMethod · 0.80
with_fsmapMethod · 0.80
acquire_gilMethod · 0.80
substrMethod · 0.80
print_treeMethod · 0.80
with_servicemapMethod · 0.80
get_by_serviceMethod · 0.80
with_pgmapMethod · 0.80
with_devices2Method · 0.80

Tested by

no test coverage detected