]> git.proxmox.com Git - ceph.git/blame - ceph/src/mgr/ActivePyModule.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / mgr / ActivePyModule.h
CommitLineData
7c673cae
FG
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
3efd9988 15#pragma once
7c673cae
FG
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"
3efd9988 22#include "common/Thread.h"
c07f9fc5 23#include "mon/health_check.h"
3efd9988
FG
24#include "mgr/Gil.h"
25
26#include "PyModuleRunner.h"
20effc67 27#include "PyModule.h"
7c673cae
FG
28
29#include <vector>
30#include <string>
31
32
3efd9988
FG
33class ActivePyModule;
34class ActivePyModules;
92f5a8d4
TL
35class MgrSession;
36class ModuleCommand;
7c673cae 37
3efd9988 38class ActivePyModule : public PyModuleRunner
7c673cae
FG
39{
40private:
c07f9fc5
FG
41 health_check_map_t health_checks;
42
3efd9988
FG
43 // Optional, URI exposed by plugins that implement serve()
44 std::string uri;
45
92f5a8d4
TL
46 std::string m_command_perms;
47 const MgrSession* m_session = nullptr;
48
7c673cae 49public:
11fdf7f2 50 ActivePyModule(const PyModuleRef &py_module_,
b32b8144 51 LogChannelRef clog_)
11fdf7f2 52 : PyModuleRunner(py_module_, clog_)
3efd9988 53 {}
7c673cae 54
3efd9988 55 int load(ActivePyModules *py_modules);
7c673cae
FG
56 void notify(const std::string &notify_type, const std::string &notify_id);
57 void notify_clog(const LogEntry &le);
58
11fdf7f2
TL
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);
7c673cae 66
7c673cae 67 int handle_command(
92f5a8d4
TL
68 const ModuleCommand& module_command,
69 const MgrSession& session,
7c673cae 70 const cmdmap_t &cmdmap,
11fdf7f2 71 const bufferlist &inbuf,
7c673cae
FG
72 std::stringstream *ds,
73 std::stringstream *ss);
c07f9fc5 74
11fdf7f2
TL
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;
c07f9fc5 81 health_checks = std::move(c);
11fdf7f2 82 return changed;
c07f9fc5
FG
83 }
84 void get_health_checks(health_check_map_t *checks);
11fdf7f2 85 void config_notify();
3efd9988
FG
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 }
92f5a8d4
TL
96
97 bool is_authorized(const std::map<std::string, std::string>& arguments) const;
98
7c673cae
FG
99};
100
7c673cae 101