]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | |
3 | // vim: ts=8 sw=2 smarttab | |
4 | /* | |
5 | * Ceph - scalable distributed file system | |
6 | * | |
7 | * Copyright (C) 2016 John Spray <john.spray@redhat.com> | |
8 | * | |
9 | * This is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU Lesser General Public | |
11 | * License version 2.1, as published by the Free Software | |
12 | * Foundation. See file COPYING. | |
13 | */ | |
14 | ||
15 | ||
16 | #ifndef MGR_PY_MODULE_H_ | |
17 | #define MGR_PY_MODULE_H_ | |
18 | ||
19 | // Python.h comes first because otherwise it clobbers ceph's assert | |
20 | #include "Python.h" | |
21 | ||
22 | #include "common/cmdparse.h" | |
23 | #include "common/LogEntry.h" | |
c07f9fc5 FG |
24 | #include "common/Mutex.h" |
25 | #include "mon/health_check.h" | |
7c673cae FG |
26 | |
27 | #include <vector> | |
28 | #include <string> | |
29 | ||
30 | ||
31 | class MgrPyModule; | |
32 | ||
33 | /** | |
34 | * A Ceph CLI command description provided from a Python module | |
35 | */ | |
36 | class ModuleCommand { | |
37 | public: | |
38 | std::string cmdstring; | |
39 | std::string helpstring; | |
40 | std::string perm; | |
41 | MgrPyModule *handler; | |
42 | }; | |
43 | ||
44 | class MgrPyModule | |
45 | { | |
46 | private: | |
47 | const std::string module_name; | |
48 | PyObject *pClassInstance; | |
31f18b77 FG |
49 | PyThreadState *pMainThreadState; |
50 | PyThreadState *pMyThreadState = nullptr; | |
7c673cae | 51 | |
c07f9fc5 FG |
52 | health_check_map_t health_checks; |
53 | ||
7c673cae FG |
54 | std::vector<ModuleCommand> commands; |
55 | ||
56 | int load_commands(); | |
57 | ||
58 | public: | |
31f18b77 | 59 | MgrPyModule(const std::string &module_name, const std::string &sys_path, PyThreadState *main_ts); |
7c673cae FG |
60 | ~MgrPyModule(); |
61 | ||
62 | int load(); | |
63 | int serve(); | |
64 | void shutdown(); | |
65 | void notify(const std::string ¬ify_type, const std::string ¬ify_id); | |
66 | void notify_clog(const LogEntry &le); | |
67 | ||
68 | const std::vector<ModuleCommand> &get_commands() const | |
69 | { | |
70 | return commands; | |
71 | } | |
72 | ||
73 | const std::string &get_name() const | |
74 | { | |
75 | return module_name; | |
76 | } | |
77 | ||
78 | int handle_command( | |
79 | const cmdmap_t &cmdmap, | |
80 | std::stringstream *ds, | |
81 | std::stringstream *ss); | |
c07f9fc5 FG |
82 | |
83 | void set_health_checks(health_check_map_t&& c) { | |
84 | health_checks = std::move(c); | |
85 | } | |
86 | void get_health_checks(health_check_map_t *checks); | |
7c673cae FG |
87 | }; |
88 | ||
89 | std::string handle_pyerror(); | |
90 | ||
91 | #endif | |
92 |