]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/ActivePyModule.h
import quincy beta 17.1.0
[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 "mon/health_check.h"
24 #include "mgr/Gil.h"
25
26 #include "PyModuleRunner.h"
27 #include "PyModule.h"
28
29 #include <vector>
30 #include <string>
31
32
33 class ActivePyModule;
34 class ActivePyModules;
35 class MgrSession;
36 class ModuleCommand;
37
38 class ActivePyModule : public PyModuleRunner
39 {
40 private:
41 health_check_map_t health_checks;
42
43 // Optional, URI exposed by plugins that implement serve()
44 std::string uri;
45
46 std::string m_command_perms;
47 const MgrSession* m_session = nullptr;
48
49 public:
50 ActivePyModule(const PyModuleRef &py_module_,
51 LogChannelRef clog_)
52 : PyModuleRunner(py_module_, clog_)
53 {}
54
55 int load(ActivePyModules *py_modules);
56 void notify(const std::string &notify_type, const std::string &notify_id);
57 void notify_clog(const LogEntry &le);
58
59 bool method_exists(const std::string &method) const;
60
61 PyObject *dispatch_remote(
62 const std::string &method,
63 PyObject *args,
64 PyObject *kwargs,
65 std::string *err);
66
67 int handle_command(
68 const ModuleCommand& module_command,
69 const MgrSession& session,
70 const cmdmap_t &cmdmap,
71 const bufferlist &inbuf,
72 std::stringstream *ds,
73 std::stringstream *ss);
74
75
76 bool set_health_checks(health_check_map_t&& c) {
77 // when health checks change a report is immediately sent to the monitors.
78 // currently modules have static health check details, but this equality
79 // test could be made smarter if too much noise shows up in the future.
80 bool changed = health_checks != c;
81 health_checks = std::move(c);
82 return changed;
83 }
84 void get_health_checks(health_check_map_t *checks);
85 void config_notify();
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 bool is_authorized(const std::map<std::string, std::string>& arguments) const;
98
99 };
100
101