]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/PyModules.h
6a71b64933116fca5fa12c88ae96950048a362ed
[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
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 PyThreadState *pMainThreadState = nullptr;
47
48 public:
49 static std::string config_prefix;
50
51 PyModules(DaemonStateIndex &ds, ClusterState &cs, MonClient &mc,
52 Objecter &objecter_, Client &client_,
53 Finisher &f);
54
55 ~PyModules();
56
57 // FIXME: wrap for send_command?
58 MonClient &get_monc() {return monc;}
59 Objecter &get_objecter() {return objecter;}
60 Client &get_client() {return client;}
61
62 PyObject *get_python(const std::string &what);
63 PyObject *get_server_python(const std::string &hostname);
64 PyObject *list_servers_python();
65 PyObject *get_metadata_python(std::string const &handle,
66 entity_type_t svc_type, const std::string &svc_id);
67 PyObject *get_counter_python(std::string const &handle,
68 entity_type_t svc_type, const std::string &svc_id,
69 const std::string &path);
70 PyObject *get_context();
71
72 std::map<std::string, std::string> config_cache;
73
74 std::vector<ModuleCommand> get_commands();
75
76 void insert_config(const std::map<std::string, std::string> &new_config);
77
78 // Public so that MonCommandCompletion can use it
79 // FIXME: for send_command completion notifications,
80 // send it to only the module that sent the command, not everyone
81 void notify_all(const std::string &notify_type,
82 const std::string &notify_id);
83 void notify_all(const LogEntry &log_entry);
84
85 int init();
86 void start();
87 void shutdown();
88
89 void dump_server(const std::string &hostname,
90 const DaemonStateCollection &dmc,
91 Formatter *f);
92
93 bool get_config(const std::string &handle,
94 const std::string &key, std::string *val) const;
95 PyObject *get_config_prefix(const std::string &handle,
96 const std::string &prefix) const;
97 void set_config(const std::string &handle,
98 const std::string &key, const std::string &val);
99
100 void log(const std::string &handle,
101 int level, const std::string &record);
102 };
103
104 #endif
105