]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/plugins/debug.py
1 # -*- coding: utf-8 -*-
2 from __future__
import absolute_import
7 from . import PLUGIN_MANAGER
as PM
8 from . import interfaces
as I
# noqa: E741,N812
9 from .plugin
import SimplePlugin
as SP
12 from typing
import no_type_check
14 no_type_check
= object() # Just for type checking
23 @PM.add_plugin
# pylint: disable=too-many-ancestors
24 class Debug(SP
, I
.CanCherrypy
, I
.ConfiguresCherryPy
, # pylint: disable=too-many-ancestors
25 I
.Setupable
, I
.ConfigNotify
):
33 desc
="Enable/disable debug options"
37 @no_type_check # https://github.com/python/mypy/issues/7806
38 def _refresh_health_checks(self
):
39 debug
= self
.get_option(self
.NAME
)
41 self
.mgr
.health_checks
.update({'DASHBOARD_DEBUG': {
42 'severity': 'warning',
43 'summary': 'Dashboard debug mode is enabled',
45 'Please disable debug mode in production environments using '
46 '"ceph dashboard {} {}"'.format(self
.NAME
, Actions
.DISABLE
.value
)
50 self
.mgr
.health_checks
.pop('DASHBOARD_DEBUG', None)
51 self
.mgr
.refresh_health_checks()
55 self
._refresh
_health
_checks
()
58 def handler(self
, action
):
61 if action
in [Actions
.ENABLE
.value
, Actions
.DISABLE
.value
]:
62 self
.set_option(self
.NAME
, action
== Actions
.ENABLE
.value
)
63 self
.mgr
.update_cherrypy_config({})
64 self
._refresh
_health
_checks
()
66 debug
= self
.get_option(self
.NAME
)
67 msg
= "Debug: '{}'".format('enabled' if debug
else 'disabled')
72 prefix
="dashboard {name}".format(name
=NAME
),
73 args
="name=action,type=CephChoices,strings={states}".format(
74 states
="|".join(a
.value
for a
in Actions
)),
75 desc
="Control and report debug status in Ceph-Dashboard",
80 def custom_error_response(self
, status
, message
, traceback
, version
):
81 self
.response
.headers
['Content-Type'] = 'application/json'
82 error_response
= dict(status
=status
, detail
=message
, request_id
=str(self
.request
.unique_id
))
84 if self
.get_option(self
.NAME
):
85 error_response
.update(dict(traceback
=traceback
, version
=version
))
87 return json
.dumps(error_response
)
90 def configure_cherrypy(self
, config
):
92 'environment': 'test_suite' if self
.get_option(self
.NAME
) else 'production',
93 'error_page.default': self
.custom_error_response
,
97 def config_notify(self
):
98 self
._refresh
_health
_checks
()