Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / mgr / ActivePyModules.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 #pragma once
15
16 #include "ActivePyModule.h"
17
18 #include "common/Finisher.h"
19 #include "common/Mutex.h"
20
21 #include "osdc/Objecter.h"
22 #include "client/Client.h"
23 #include "common/LogClient.h"
24 #include "mon/MgrMap.h"
25 #include "mon/MonCommand.h"
26
27 #include "DaemonState.h"
28 #include "ClusterState.h"
29
30 class health_check_map_t;
31
32 typedef std::map<std::string, std::string> PyModuleConfig;
33
34 class ActivePyModules
35 {
36
37   std::map<std::string, std::unique_ptr<ActivePyModule>> modules;
38   PyModuleConfig config_cache;
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
48   mutable Mutex lock{"ActivePyModules::lock"};
49
50 public:
51   ActivePyModules(PyModuleConfig const &config_,
52             DaemonStateIndex &ds, ClusterState &cs, MonClient &mc,
53             LogChannelRef clog_, Objecter &objecter_, Client &client_,
54             Finisher &f);
55
56   ~ActivePyModules();
57
58   // FIXME: wrap for send_command?
59   MonClient &get_monc() {return monc;}
60   Objecter  &get_objecter() {return objecter;}
61   Client    &get_client() {return client;}
62
63   PyObject *get_python(const std::string &what);
64   PyObject *get_server_python(const std::string &hostname);
65   PyObject *list_servers_python();
66   PyObject *get_metadata_python(
67     const std::string &svc_type, const std::string &svc_id);
68   PyObject *get_daemon_status_python(
69     const std::string &svc_type, const std::string &svc_id);
70   PyObject *get_counter_python(
71     const std::string &svc_type,
72     const std::string &svc_id,
73     const std::string &path);
74   PyObject *get_perf_schema_python(
75      const std::string svc_type,
76      const std::string &svc_id);
77   PyObject *get_context();
78   PyObject *get_osdmap();
79
80   bool get_config(const std::string &module_name,
81       const std::string &key, std::string *val) const;
82   PyObject *get_config_prefix(const std::string &module_name,
83                               const std::string &prefix) const;
84   void set_config(const std::string &module_name,
85       const std::string &key, const boost::optional<std::string> &val);
86
87   void set_health_checks(const std::string& module_name,
88                          health_check_map_t&& checks);
89   void get_health_checks(health_check_map_t *checks);
90
91   void set_uri(const std::string& module_name, const std::string &uri);
92
93   // Python command definitions, including callback
94   std::vector<ModuleCommand> get_py_commands() const;
95
96   // Monitor command definitions, suitable for CLI
97   std::vector<MonCommand> get_commands() const;
98
99   std::map<std::string, std::string> get_services() const;
100
101   // Public so that MonCommandCompletion can use it
102   // FIXME: for send_command completion notifications,
103   // send it to only the module that sent the command, not everyone
104   void notify_all(const std::string &notify_type,
105                   const std::string &notify_id);
106   void notify_all(const LogEntry &log_entry);
107
108   int init();
109   void shutdown();
110
111   int start_one(std::string const &module_name,
112                 PyObject *pClass,
113                 const SafeThreadState &pMyThreadState);
114
115   void dump_server(const std::string &hostname,
116                    const DaemonStateCollection &dmc,
117                    Formatter *f);
118 };
119