-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMgrPyModule.h
83 lines (63 loc) · 1.67 KB
/
MgrPyModule.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2016 John Spray <[email protected]>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*/
#ifndef MGR_PY_MODULE_H_
#define MGR_PY_MODULE_H_
// Python.h comes first because otherwise it clobbers ceph's assert
#include "Python.h"
#include "common/cmdparse.h"
#include "common/LogEntry.h"
#include <vector>
#include <string>
class MgrPyModule;
/**
* A Ceph CLI command description provided from a Python module
*/
class ModuleCommand {
public:
std::string cmdstring;
std::string helpstring;
std::string perm;
MgrPyModule *handler;
};
class MgrPyModule
{
private:
const std::string module_name;
PyObject *pClassInstance;
PyThreadState *pMainThreadState;
PyThreadState *pMyThreadState = nullptr;
std::vector<ModuleCommand> commands;
int load_commands();
public:
MgrPyModule(const std::string &module_name, const std::string &sys_path, PyThreadState *main_ts);
~MgrPyModule();
int load();
int serve();
void shutdown();
void notify(const std::string ¬ify_type, const std::string ¬ify_id);
void notify_clog(const LogEntry &le);
const std::vector<ModuleCommand> &get_commands() const
{
return commands;
}
const std::string &get_name() const
{
return module_name;
}
int handle_command(
const cmdmap_t &cmdmap,
std::stringstream *ds,
std::stringstream *ss);
};
std::string handle_pyerror();
#endif