]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/PyModules.h
431abec76f0e3cf4b814ed51239dc5d7feb99a46
[ceph.git] / ceph / src / mgr / PyModules.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) 2014 John Spray <john.spray@inktank.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 #ifndef PY_MODULES_H_
15 #define PY_MODULES_H_
16
17 #include "MgrPyModule.h"
18
19 #include "common/Finisher.h"
20 #include "common/Mutex.h"
21 #include "common/Thread.h"
22
23 #include "osdc/Objecter.h"
24 #include "client/Client.h"
25 #include "common/LogClient.h"
26 #include "mon/MgrMap.h"
27 #include "mon/MonCommand.h"
28
29 #include "DaemonState.h"
30 #include "ClusterState.h"
31
32 class ServeThread;
33 class health_check_map_t;
34
35 class PyModules
36 {
37 std::map<std::string, std::unique_ptr<MgrPyModule>> modules;
38 std::map<std::string, std::unique_ptr<ServeThread>> serve_threads;
39 DaemonStateIndex &daemon_state;
40 ClusterState &cluster_state;
41 MonClient &monc;
42 LogChannelRef clog;
43 Objecter &objecter;
44 Client &client;
45 Finisher &finisher;
46
47 mutable Mutex lock{"PyModules::lock"};
48
49 std::string get_site_packages();
50
51 PyThreadState *pMainThreadState = nullptr;
52
53 public:
54 static std::string config_prefix;
55
56 PyModules(DaemonStateIndex &ds, ClusterState &cs, MonClient &mc,
57 LogChannelRef clog_, Objecter &objecter_, Client &client_,
58 Finisher &f);
59
60 ~PyModules();
61
62 // FIXME: wrap for send_command?
63 MonClient &get_monc() {return monc;}
64 Objecter &get_objecter() {return objecter;}
65 Client &get_client() {return client;}
66
67 PyObject *get_python(const std::string &what);
68 PyObject *get_server_python(const std::string &hostname);
69 PyObject *list_servers_python();
70 PyObject *get_metadata_python(
71 std::string const &handle,
72 const std::string &svc_name, const std::string &svc_id);
73 PyObject *get_daemon_status_python(
74 std::string const &handle,
75 const std::string &svc_name, const std::string &svc_id);
76 PyObject *get_counter_python(
77 std::string const &handle,
78 const std::string &svc_name,
79 const std::string &svc_id,
80 const std::string &path);
81 PyObject *get_perf_schema_python(
82 const std::string &handle,
83 const std::string svc_type,
84 const std::string &svc_id);
85 PyObject *get_context();
86
87 std::map<std::string, std::string> config_cache;
88
89 // Python command definitions, including callback
90 std::vector<ModuleCommand> get_py_commands() const;
91
92 // Monitor command definitions, suitable for CLI
93 std::vector<MonCommand> get_commands() const;
94
95 void insert_config(const std::map<std::string, std::string> &new_config);
96
97 // Public so that MonCommandCompletion can use it
98 // FIXME: for send_command completion notifications,
99 // send it to only the module that sent the command, not everyone
100 void notify_all(const std::string &notify_type,
101 const std::string &notify_id);
102 void notify_all(const LogEntry &log_entry);
103
104 int init();
105 void start();
106 void shutdown();
107
108 void dump_server(const std::string &hostname,
109 const DaemonStateCollection &dmc,
110 Formatter *f);
111
112 bool get_config(const std::string &handle,
113 const std::string &key, std::string *val) const;
114 PyObject *get_config_prefix(const std::string &handle,
115 const std::string &prefix) const;
116 void set_config(const std::string &handle,
117 const std::string &key, const std::string &val);
118
119 void set_health_checks(const std::string& handle,
120 health_check_map_t&& checks);
121 void get_health_checks(health_check_map_t *checks);
122
123 void log(const std::string &handle,
124 int level, const std::string &record);
125
126 static void list_modules(std::set<std::string> *modules);
127 };
128
129 #endif
130