]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/plugins/debug.py
1 # -*- coding: utf-8 -*-
6 from typing
import no_type_check
8 from . import PLUGIN_MANAGER
as PM
9 from . import interfaces
as I
# noqa: E741,N812
10 from .plugin
import SimplePlugin
as SP
19 @PM.add_plugin
# pylint: disable=too-many-ancestors
20 class Debug(SP
, I
.CanCherrypy
, I
.ConfiguresCherryPy
, # pylint: disable=too-many-ancestors
21 I
.Setupable
, I
.ConfigNotify
):
29 desc
="Enable/disable debug options"
33 @no_type_check # https://github.com/python/mypy/issues/7806
34 def _refresh_health_checks(self
):
35 debug
= self
.get_option(self
.NAME
)
37 self
.mgr
.health_checks
.update({'DASHBOARD_DEBUG': {
38 'severity': 'warning',
39 'summary': 'Dashboard debug mode is enabled',
41 'Please disable debug mode in production environments using '
42 '"ceph dashboard {} {}"'.format(self
.NAME
, Actions
.DISABLE
.value
)
46 self
.mgr
.health_checks
.pop('DASHBOARD_DEBUG', None)
47 self
.mgr
.refresh_health_checks()
51 self
._refresh
_health
_checks
()
54 def handler(self
, action
: Actions
):
56 Control and report debug status in Ceph-Dashboard
60 if action
in [Actions
.ENABLE
, Actions
.DISABLE
]:
61 self
.set_option(self
.NAME
, action
== Actions
.ENABLE
)
62 self
.mgr
.update_cherrypy_config({})
63 self
._refresh
_health
_checks
()
65 debug
= self
.get_option(self
.NAME
)
66 msg
= "Debug: '{}'".format('enabled' if debug
else 'disabled')
71 prefix
="dashboard {name}".format(name
=NAME
),
76 def custom_error_response(self
, status
, message
, traceback
, version
):
77 self
.response
.headers
['Content-Type'] = 'application/json'
78 error_response
= dict(status
=status
, detail
=message
, request_id
=str(self
.request
.unique_id
))
80 if self
.get_option(self
.NAME
):
81 error_response
.update(dict(traceback
=traceback
, version
=version
))
83 return json
.dumps(error_response
)
86 def configure_cherrypy(self
, config
):
88 'environment': 'test_suite' if self
.get_option(self
.NAME
) else 'production',
89 'error_page.default': self
.custom_error_response
,
93 def config_notify(self
):
94 self
._refresh
_health
_checks
()