]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/plugins/plugin.py
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / plugins / plugin.py
1 from typing import no_type_check
2
3 from mgr_module import Command, Option
4
5 from . import PLUGIN_MANAGER as PM
6 from . import interfaces as I # noqa: E741,N812
7
8
9 class SimplePlugin(I.CanMgr, I.HasOptions, I.HasCommands):
10 """
11 Helper class that provides simplified creation of plugins:
12 - Default Mixins/Interfaces: CanMgr, HasOptions & HasCommands
13 - Options are defined by OPTIONS class variable, instead from get_options hook
14 - Commands are created with by COMMANDS list of Commands() and handlers
15 (less compact than CLICommand, but allows using method instances)
16 """
17 Option = Option
18 Command = Command
19
20 @PM.add_hook
21 def get_options(self):
22 return self.OPTIONS # type: ignore
23
24 @PM.final
25 @no_type_check # https://github.com/python/mypy/issues/7806
26 def get_option(self, option):
27 return self.mgr.get_module_option(option)
28
29 @PM.final
30 @no_type_check # https://github.com/python/mypy/issues/7806
31 def set_option(self, option, value):
32 self.mgr.set_module_option(option, value)
33
34 @PM.add_hook
35 @no_type_check # https://github.com/python/mypy/issues/7806
36 def register_commands(self):
37 for cmd in self.COMMANDS:
38 cmd.register(instance=self)