]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/ActivePyModule.h
update sources to v12.2.3
[ceph.git] / ceph / src / mgr / ActivePyModule.h
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 #pragma once
17
18 // Python.h comes first because otherwise it clobbers ceph's assert
19 #include "Python.h"
20
21 #include "common/cmdparse.h"
22 #include "common/LogEntry.h"
23 #include "common/Mutex.h"
24 #include "common/Thread.h"
25 #include "mon/health_check.h"
26 #include "mgr/Gil.h"
27
28 #include "PyModuleRunner.h"
29
30 #include <vector>
31 #include <string>
32
33
34 class ActivePyModule;
35 class ActivePyModules;
36
37 /**
38 * A Ceph CLI command description provided from a Python module
39 */
40 class ModuleCommand {
41 public:
42 std::string cmdstring;
43 std::string helpstring;
44 std::string perm;
45 ActivePyModule *handler;
46 };
47
48 class ActivePyModule : public PyModuleRunner
49 {
50 private:
51 health_check_map_t health_checks;
52
53 std::vector<ModuleCommand> commands;
54
55 int load_commands();
56
57 // Optional, URI exposed by plugins that implement serve()
58 std::string uri;
59
60 public:
61 ActivePyModule(const std::string &module_name_,
62 PyObject *pClass_,
63 const SafeThreadState &my_ts_,
64 LogChannelRef clog_)
65 : PyModuleRunner(module_name_, pClass_, my_ts_, clog_)
66 {}
67
68 int load(ActivePyModules *py_modules);
69 void notify(const std::string &notify_type, const std::string &notify_id);
70 void notify_clog(const LogEntry &le);
71
72 const std::vector<ModuleCommand> &get_commands() const
73 {
74 return commands;
75 }
76
77 int handle_command(
78 const cmdmap_t &cmdmap,
79 std::stringstream *ds,
80 std::stringstream *ss);
81
82 void set_health_checks(health_check_map_t&& c) {
83 health_checks = std::move(c);
84 }
85 void get_health_checks(health_check_map_t *checks);
86
87 void set_uri(const std::string &str)
88 {
89 uri = str;
90 }
91
92 std::string get_uri() const
93 {
94 return uri;
95 }
96 };
97
98 std::string handle_pyerror();
99