]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/mgr_module.py
2 import ceph_state
#noqa
8 class CommandResult(object):
10 Use with MgrModule.send_command
12 def __init__(self
, tag
):
13 self
.ev
= threading
.Event()
18 # This is just a convenience for notifications from
19 # C++ land, to avoid passing addresses around in messages.
22 def complete(self
, r
, outb
, outs
):
30 return self
.r
, self
.outb
, self
.outs
33 class MgrModule(object):
36 def __init__(self
, handle
):
38 self
._logger
= logging
.getLogger(handle
)
40 # Don't filter any logs at the python level, leave it to C++
41 self
._logger
.setLevel(logging
.DEBUG
)
43 # FIXME: we should learn the log level from C++ land, and then
44 # avoid calling ceph_state.log when we know a message is of
45 # an insufficient level to be ultimately output
47 class CPlusPlusHandler(logging
.Handler
):
48 def emit(self
, record
):
49 if record
.levelno
<= logging
.DEBUG
:
51 elif record
.levelno
<= logging
.INFO
:
53 elif record
.levelno
<= logging
.WARNING
:
58 ceph_state
.log(handle
, ceph_level
, self
.format(record
))
60 self
._logger
.addHandler(CPlusPlusHandler())
62 self
._version
= ceph_state
.get_version()
72 def notify(self
, notify_type
, notify_id
):
74 Called by the ceph-mgr service to notify the Python plugin
75 that new state is available.
81 Called by the ceph-mgr service to start any server that
82 is provided by this Python plugin. The implementation
83 of this function should block until ``shutdown`` is called.
85 You *must* implement ``shutdown`` if you implement ``serve``
91 Called by the ceph-mgr service to request that this
92 module drop out of its serve() function. You do not
93 need to implement this if you do not implement serve()
99 def get(self
, data_name
):
101 Called by the plugin to load some cluster state from ceph-mgr
103 return ceph_state
.get(self
._handle
, data_name
)
105 def get_server(self
, hostname
):
107 Called by the plugin to load information about a particular
110 :param hostname: a hostame
112 return ceph_state
.get_server(self
._handle
, hostname
)
114 def get_perf_schema(self
, svc_type
, svc_name
):
116 Called by the plugin to fetch perf counter schema info.
117 svc_name can be nullptr, as can svc_type, in which case
122 :return: list of dicts describing the counters requested
124 return ceph_state
.get_perf_schema(self
._handle
, svc_type
, svc_name
)
126 def get_counter(self
, svc_type
, svc_name
, path
):
128 Called by the plugin to fetch data for a particular perf counter
129 on a particular service.
134 :return: A list of two-element lists containing time and value
136 return ceph_state
.get_counter(self
._handle
, svc_type
, svc_name
, path
)
138 def list_servers(self
):
140 Like ``get_server``, but instead of returning information
141 about just one node, return all the nodes in an array.
143 return ceph_state
.get_server(self
._handle
, None)
145 def get_metadata(self
, svc_type
, svc_id
):
147 Fetch the metadata for a particular service.
149 :param svc_type: string (e.g., 'mds', 'osd', 'mon')
150 :param svc_id: string
153 return ceph_state
.get_metadata(self
._handle
, svc_type
, svc_id
)
155 def get_daemon_status(self
, svc_type
, svc_id
):
157 Fetch the latest status for a particular service daemon.
159 :param svc_type: string (e.g., 'rgw')
160 :param svc_id: string
163 return ceph_state
.get_daemon_status(self
._handle
, svc_type
, svc_id
)
165 def send_command(self
, *args
, **kwargs
):
167 Called by the plugin to send a command to the mon
170 ceph_state
.send_command(self
._handle
, *args
, **kwargs
)
172 def set_health_checks(self
, checks
):
174 Set module's health checks
176 Set the module's current map of health checks. Argument is a
177 dict of check names to info, in this form:
181 'severity': 'warning', # or 'error'
182 'summary': 'summary string',
183 'detail': [ 'list', 'of', 'detail', 'strings' ],
187 'summary': 'bars are bad',
188 'detail': [ 'too hard' ],
192 :param list: dict of health check dicts
194 ceph_state
.set_health_checks(self
._handle
, checks
)
196 def handle_command(self
, cmd
):
198 Called by ceph-mgr to request the plugin to handle one
199 of the commands that it declared in self.COMMANDS
201 Return a status code, an output buffer, and an
202 output string. The output buffer is for data results,
203 the output string is for informative text.
205 :param cmd: dict, from Ceph's cmdmap_t
207 :return: 3-tuple of (int, str, str)
210 # Should never get called if they didn't declare
212 raise NotImplementedError()
214 def get_mgr_id(self
):
220 return ceph_state
.get_mgr_id()
222 def get_config(self
, key
):
224 Retrieve the value of a persistent configuration setting
229 return ceph_state
.get_config(self
._handle
, key
)
231 def get_config_prefix(self
, key_prefix
):
233 Retrieve a dict of config values with the given prefix
235 :param key_prefix: str
238 return ceph_state
.get_config_prefix(self
._handle
, key_prefix
)
240 def get_localized_config(self
, key
, default
=None):
242 Retrieve localized configuration for this ceph-mgr instance
247 r
= self
.get_config(self
.get_mgr_id() + '/' + key
)
249 r
= self
.get_config(key
)
255 def set_config(self
, key
, val
):
257 Set the value of a persistent configuration setting
262 ceph_state
.set_config(self
._handle
, key
, val
)
264 def set_localized_config(self
, key
, val
):
266 Set localized configuration for this ceph-mgr instance
271 return self
.set_config(self
.get_mgr_id() + '/' + key
, val
)
273 def set_config_json(self
, key
, val
):
275 Helper for setting json-serialized-config
278 :param val: json-serializable object
280 self
.set_config(key
, json
.dumps(val
))
282 def get_config_json(self
, key
):
284 Helper for getting json-serialized config
289 raw
= self
.get_config(key
)
293 return json
.loads(raw
)
297 Run a self-test on the module. Override this function and implement
298 a best as possible self-test for (automated) testing of the module