]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/ActivePyModule.h
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / mgr / ActivePyModule.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2016 John Spray <john.spray@redhat.com>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 */
13
14
15 #pragma once
16
17 // Python.h comes first because otherwise it clobbers ceph's assert
18 #include "Python.h"
19
20 #include "common/cmdparse.h"
21 #include "common/LogEntry.h"
22 #include "common/Thread.h"
23 #include "common/Finisher.h"
24 #include "mon/health_check.h"
25 #include "mgr/Gil.h"
26
27 #include "PyModuleRunner.h"
28 #include "PyModule.h"
29
30 #include <vector>
31 #include <string>
32
33
34 class ActivePyModule;
35 class ActivePyModules;
36 class MgrSession;
37 class ModuleCommand;
38
39 class ActivePyModule : public PyModuleRunner
40 {
41 private:
42 health_check_map_t health_checks;
43
44 // Optional, URI exposed by plugins that implement serve()
45 std::string uri;
46
47 std::string m_command_perms;
48 const MgrSession* m_session = nullptr;
49 std::string fin_thread_name;
50 public:
51 Finisher finisher; // per active module finisher to execute commands
52
53 public:
54 ActivePyModule(const PyModuleRef &py_module_,
55 LogChannelRef clog_)
56 : PyModuleRunner(py_module_, clog_),
57 fin_thread_name(std::string("m-fin-" + py_module->get_name()).substr(0,15)),
58 finisher(g_ceph_context, thread_name, fin_thread_name)
59
60 {
61 }
62
63 int load(ActivePyModules *py_modules);
64 void notify(const std::string &notify_type, const std::string &notify_id);
65 void notify_clog(const LogEntry &le);
66
67 bool method_exists(const std::string &method) const;
68
69 PyObject *dispatch_remote(
70 const std::string &method,
71 PyObject *args,
72 PyObject *kwargs,
73 std::string *err);
74
75 int handle_command(
76 const ModuleCommand& module_command,
77 const MgrSession& session,
78 const cmdmap_t &cmdmap,
79 const bufferlist &inbuf,
80 std::stringstream *ds,
81 std::stringstream *ss);
82
83
84 bool set_health_checks(health_check_map_t&& c) {
85 // when health checks change a report is immediately sent to the monitors.
86 // currently modules have static health check details, but this equality
87 // test could be made smarter if too much noise shows up in the future.
88 bool changed = health_checks != c;
89 health_checks = std::move(c);
90 return changed;
91 }
92 void get_health_checks(health_check_map_t *checks);
93 void config_notify();
94
95 void set_uri(const std::string &str)
96 {
97 uri = str;
98 }
99
100 std::string get_uri() const
101 {
102 return uri;
103 }
104
105 std::string get_fin_thread_name() const
106 {
107 return fin_thread_name;
108 }
109
110 bool is_authorized(const std::map<std::string, std::string>& arguments) const;
111
112 };
113
114