]>
Commit | Line | Data |
---|---|---|
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) 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" | |
224ce89b WB |
25 | #include "common/LogClient.h" |
26 | #include "mon/MgrMap.h" | |
7c673cae FG |
27 | |
28 | #include "DaemonState.h" | |
29 | #include "ClusterState.h" | |
30 | ||
31 | class ServeThread; | |
32 | ||
33 | class PyModules | |
34 | { | |
35 | std::map<std::string, std::unique_ptr<MgrPyModule>> modules; | |
36 | std::map<std::string, std::unique_ptr<ServeThread>> serve_threads; | |
37 | DaemonStateIndex &daemon_state; | |
38 | ClusterState &cluster_state; | |
39 | MonClient &monc; | |
224ce89b | 40 | LogChannelRef clog; |
7c673cae FG |
41 | Objecter &objecter; |
42 | Client &client; | |
43 | Finisher &finisher; | |
44 | ||
45 | mutable Mutex lock{"PyModules"}; | |
46 | ||
47 | std::string get_site_packages(); | |
48 | ||
31f18b77 FG |
49 | PyThreadState *pMainThreadState = nullptr; |
50 | ||
7c673cae | 51 | public: |
31f18b77 | 52 | static std::string config_prefix; |
7c673cae FG |
53 | |
54 | PyModules(DaemonStateIndex &ds, ClusterState &cs, MonClient &mc, | |
224ce89b | 55 | LogChannelRef clog_, Objecter &objecter_, Client &client_, |
7c673cae FG |
56 | Finisher &f); |
57 | ||
58 | ~PyModules(); | |
59 | ||
60 | // FIXME: wrap for send_command? | |
61 | MonClient &get_monc() {return monc;} | |
62 | Objecter &get_objecter() {return objecter;} | |
63 | Client &get_client() {return client;} | |
64 | ||
65 | PyObject *get_python(const std::string &what); | |
66 | PyObject *get_server_python(const std::string &hostname); | |
67 | PyObject *list_servers_python(); | |
224ce89b WB |
68 | PyObject *get_metadata_python( |
69 | std::string const &handle, | |
70 | const std::string &svc_name, const std::string &svc_id); | |
71 | PyObject *get_daemon_status_python( | |
72 | std::string const &handle, | |
73 | const std::string &svc_name, const std::string &svc_id); | |
74 | PyObject *get_counter_python( | |
75 | std::string const &handle, | |
76 | const std::string &svc_name, | |
77 | const std::string &svc_id, | |
78 | const std::string &path); | |
7c673cae FG |
79 | PyObject *get_context(); |
80 | ||
81 | std::map<std::string, std::string> config_cache; | |
82 | ||
83 | std::vector<ModuleCommand> get_commands(); | |
84 | ||
85 | void insert_config(const std::map<std::string, std::string> &new_config); | |
86 | ||
87 | // Public so that MonCommandCompletion can use it | |
88 | // FIXME: for send_command completion notifications, | |
89 | // send it to only the module that sent the command, not everyone | |
90 | void notify_all(const std::string ¬ify_type, | |
91 | const std::string ¬ify_id); | |
92 | void notify_all(const LogEntry &log_entry); | |
93 | ||
94 | int init(); | |
95 | void start(); | |
96 | void shutdown(); | |
97 | ||
98 | void dump_server(const std::string &hostname, | |
99 | const DaemonStateCollection &dmc, | |
100 | Formatter *f); | |
101 | ||
102 | bool get_config(const std::string &handle, | |
103 | const std::string &key, std::string *val) const; | |
31f18b77 FG |
104 | PyObject *get_config_prefix(const std::string &handle, |
105 | const std::string &prefix) const; | |
7c673cae FG |
106 | void set_config(const std::string &handle, |
107 | const std::string &key, const std::string &val); | |
108 | ||
109 | void log(const std::string &handle, | |
110 | int level, const std::string &record); | |
224ce89b WB |
111 | |
112 | static void list_modules(std::set<std::string> *modules); | |
7c673cae FG |
113 | }; |
114 | ||
115 | #endif | |
116 |