]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/plugins/debug.py
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / plugins / debug.py
CommitLineData
92f5a8d4
TL
1# -*- coding: utf-8 -*-
2from __future__ import absolute_import
3
4from enum import Enum
5import json
6
7from . import PLUGIN_MANAGER as PM
8from . import interfaces as I # noqa: E741,N812
9from .plugin import SimplePlugin as SP
10
9f95a23c
TL
11try:
12 from typing import no_type_check
13except ImportError:
14 no_type_check = object() # Just for type checking
15
92f5a8d4
TL
16
17class Actions(Enum):
18 ENABLE = 'enable'
19 DISABLE = 'disable'
20 STATUS = 'status'
21
22
23@PM.add_plugin # pylint: disable=too-many-ancestors
24class Debug(SP, I.CanCherrypy, I.ConfiguresCherryPy):
25 NAME = 'debug'
26
27 OPTIONS = [
28 SP.Option(
29 name=NAME,
30 default=False,
31 type='bool',
32 desc="Enable/disable debug options"
33 )
34 ]
35
9f95a23c 36 @no_type_check
92f5a8d4
TL
37 def handler(self, action):
38 ret = 0
39 msg = ''
40 if action in [Actions.ENABLE.value, Actions.DISABLE.value]:
41 self.set_option(self.NAME, action == Actions.ENABLE.value)
42 self.mgr.update_cherrypy_config({})
43 else:
44 debug = self.get_option(self.NAME)
45 msg = "Debug: '{}'".format('enabled' if debug else 'disabled')
46 return (ret, msg, None)
47
48 COMMANDS = [
49 SP.Command(
50 prefix="dashboard {name}".format(name=NAME),
51 args="name=action,type=CephChoices,strings={states}".format(
52 states="|".join(a.value for a in Actions)),
53 desc="Control and report debug status in Ceph-Dashboard",
54 handler=handler
55 )
56 ]
57
58 def custom_error_response(self, status, message, traceback, version):
59 self.response.headers['Content-Type'] = 'application/json'
60 error_response = dict(status=status, detail=message, request_id=str(self.request.unique_id))
61
62 if self.get_option(self.NAME):
63 error_response.update(dict(traceback=traceback, version=version))
64
65 return json.dumps(error_response)
66
67 @PM.add_hook
68 def configure_cherrypy(self, config):
69 config.update({
70 'environment': 'test_suite' if self.get_option(self.NAME) else 'production',
71 'error_page.default': self.custom_error_response,
72 })