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