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