Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / mgr / ActivePyModule.h
1
2 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
3 // vim: ts=8 sw=2 smarttab
4 /*
5  * Ceph - scalable distributed file system
6  *
7  * Copyright (C) 2016 John Spray <john.spray@redhat.com>
8  *
9  * This is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software
12  * Foundation.  See file COPYING.
13  */
14
15
16 #pragma once
17
18 // Python.h comes first because otherwise it clobbers ceph's assert
19 #include "Python.h"
20
21 #include "common/cmdparse.h"
22 #include "common/LogEntry.h"
23 #include "common/Mutex.h"
24 #include "common/Thread.h"
25 #include "mon/health_check.h"
26 #include "mgr/Gil.h"
27
28 #include "PyModuleRunner.h"
29
30 #include <vector>
31 #include <string>
32
33
34 class ActivePyModule;
35 class ActivePyModules;
36
37 /**
38  * A Ceph CLI command description provided from a Python module
39  */
40 class ModuleCommand {
41 public:
42   std::string cmdstring;
43   std::string helpstring;
44   std::string perm;
45   ActivePyModule *handler;
46 };
47
48 class ActivePyModule : public PyModuleRunner
49 {
50 private:
51   health_check_map_t health_checks;
52
53   std::vector<ModuleCommand> commands;
54
55   int load_commands();
56
57   // Optional, URI exposed by plugins that implement serve()
58   std::string uri;
59
60 public:
61   ActivePyModule(const std::string &module_name_,
62       PyObject *pClass_,
63       const SafeThreadState &my_ts_)
64     : PyModuleRunner(module_name_, pClass_, my_ts_)
65   {}
66
67   int load(ActivePyModules *py_modules);
68   void notify(const std::string &notify_type, const std::string &notify_id);
69   void notify_clog(const LogEntry &le);
70
71   const std::vector<ModuleCommand> &get_commands() const
72   {
73     return commands;
74   }
75
76   int handle_command(
77     const cmdmap_t &cmdmap,
78     std::stringstream *ds,
79     std::stringstream *ss);
80
81   void set_health_checks(health_check_map_t&& c) {
82     health_checks = std::move(c);
83   }
84   void get_health_checks(health_check_map_t *checks);
85
86   void set_uri(const std::string &str)
87   {
88     uri = str;
89   }
90
91   std::string get_uri() const
92   {
93     return uri;
94   }
95 };
96
97 std::string handle_pyerror();
98