Module: check_mk
Branch: master
Commit: 206cb6195cfc458b4bb34701ba176e76e47501ea
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=206cb6195cfc45…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jul 16 20:32:44 2018 +0200
More plugin registry refactoring
* Refactored remaining plugin registries to explicit registration
* Quicksearch match plugins
* User connector plugins
* SLA computation and painter plugins
* Dropped load_plugins method from Registry class
Change-Id: I6d61b4339a86619a77a6fa7e6062704d6c631f8f
---
cmk/gui/plugin_registry.py | 31 ++++++-------------------------
cmk/gui/plugins/sidebar/quicksearch.py | 18 +++++++++++++-----
cmk/gui/plugins/userdb/htpasswd.py | 3 ++-
cmk/gui/plugins/userdb/ldap_connector.py | 3 ++-
cmk/gui/plugins/userdb/utils.py | 1 -
5 files changed, 23 insertions(+), 33 deletions(-)
diff --git a/cmk/gui/plugin_registry.py b/cmk/gui/plugin_registry.py
index ce29a44..961f1c8 100644
--- a/cmk/gui/plugin_registry.py
+++ b/cmk/gui/plugin_registry.py
@@ -29,6 +29,9 @@ import abc
# TODO: We decided to change this plugin registry from automatically finding
# it's childs to explicit registration.
# TODO: In the moment we have this, we can drop the auto_register stuff.
+# TODO: Think about the different registry types. For which cases do we need the
+# object registry for which the class registry? Does it make sense to consolidate
+# both?
class Registry(object):
"""The management object for all available plugins of a component.
@@ -52,44 +55,22 @@ class Registry(object):
raise NotImplementedError()
- def load_plugins(self):
- self._entries.clear()
-
- def _all_subclasses_of(base_class):
- l = []
- for plugin_class in base_class.__subclasses__(): # pylint: disable=no-member
- l += _all_subclasses_of(plugin_class)
- l.append(plugin_class)
- return l
-
- for plugin_class in _all_subclasses_of(self.plugin_base_class()):
- if plugin_class.__subclasses__(): # pylint: disable=no-member
- continue # Only use leaf classes
-
- # TODO: Create one base class for all plugin classes to provide a default for
this
- if hasattr(plugin_class, "auto_register") and not
plugin_class.auto_register():
- return
-
- self.register(self._instanciate(plugin_class))
-
-
@abc.abstractmethod
def _instanciate(self, cls):
raise NotImplementedError()
- @abc.abstractmethod
def register(self, plugin_class):
"""Decorator to register a class with the
registry"""
- self._register(plugin_class)
+ self._register(self._instanciate(plugin_class))
+ return plugin_class
- @abc.abstractmethod
def register_plugin(self, plugin_class):
"""Method for registering a plugin with the registry.
Result is equal to use the register() decorator"""
- self._register(plugin_class)
+ self._register(self._instanciate(plugin_class))
@abc.abstractmethod
diff --git a/cmk/gui/plugins/sidebar/quicksearch.py
b/cmk/gui/plugins/sidebar/quicksearch.py
index d6870a7..1a08d06 100644
--- a/cmk/gui/plugins/sidebar/quicksearch.py
+++ b/cmk/gui/plugins/sidebar/quicksearch.py
@@ -713,10 +713,14 @@ class MatchPluginRegistry(cmk.gui.plugin_registry.ObjectRegistry):
return QuicksearchMatchPlugin
- def register(self, obj):
+ def _register(self, obj):
self._entries[obj.__class__.__name__] = obj
+match_plugin_registry = MatchPluginRegistry()
+
+
+(a)match_plugin_registry.register
class GroupMatchPlugin(QuicksearchMatchPlugin):
def __init__(self, group_type = None, filter_shortname = None):
super(GroupMatchPlugin, self).__init__(["%sgroups" % group_type,
"%ss" % group_type, "services"],
@@ -795,6 +799,7 @@ class GroupMatchPlugin(QuicksearchMatchPlugin):
+(a)match_plugin_registry.register
class ServiceMatchPlugin(QuicksearchMatchPlugin):
def __init__(self):
super(ServiceMatchPlugin, self).__init__(["services"],
"services", "s")
@@ -833,6 +838,7 @@ class ServiceMatchPlugin(QuicksearchMatchPlugin):
+(a)match_plugin_registry.register
class HostMatchPlugin(QuicksearchMatchPlugin):
def __init__(self, livestatus_field = None, filter_shortname = None):
super(HostMatchPlugin, self).__init__(["hosts", "services"],
"hosts", filter_shortname)
@@ -910,6 +916,7 @@ class HostMatchPlugin(QuicksearchMatchPlugin):
+(a)match_plugin_registry.register
class HosttagMatchPlugin(QuicksearchMatchPlugin):
def __init__(self):
super(HosttagMatchPlugin, self).__init__(["hosts",
"services"], "hosts", "tg")
@@ -971,30 +978,31 @@ class HosttagMatchPlugin(QuicksearchMatchPlugin):
return "", url_infos
+(a)match_plugin_registry.register
class ServiceGroupMatchPlugin(GroupMatchPlugin):
def __init__(self):
super(ServiceGroupMatchPlugin, self).__init__(group_type = "service",
filter_shortname = "sg")
+(a)match_plugin_registry.register
class HostGroupMatchPlugin(GroupMatchPlugin):
def __init__(self):
super(HostGroupMatchPlugin, self).__init__(group_type = "host",
filter_shortname = "hg")
+(a)match_plugin_registry.register
class HostNameMatchPlugin(HostMatchPlugin):
def __init__(self):
super(HostNameMatchPlugin, self).__init__(livestatus_field = "name",
filter_shortname = "h")
+(a)match_plugin_registry.register
class HostAliasMatchPlugin(HostMatchPlugin):
def __init__(self):
super(HostAliasMatchPlugin, self).__init__(livestatus_field = "alias",
filter_shortname = "al")
+(a)match_plugin_registry.register
class HostAddressMatchPlugin(HostMatchPlugin):
def __init__(self):
super(HostAddressMatchPlugin, self).__init__(livestatus_field =
"address", filter_shortname = "ad")
-
-
-match_plugin_registry = MatchPluginRegistry()
-match_plugin_registry.load_plugins()
diff --git a/cmk/gui/plugins/userdb/htpasswd.py b/cmk/gui/plugins/userdb/htpasswd.py
index 9472554..958a5b5 100644
--- a/cmk/gui/plugins/userdb/htpasswd.py
+++ b/cmk/gui/plugins/userdb/htpasswd.py
@@ -34,7 +34,7 @@ import cmk.paths
from cmk.gui.i18n import _
from cmk.gui.globals import html
from cmk.gui.exceptions import MKUserError
-from . import UserConnector
+from . import UserConnector, user_connector_registry
def encrypt_password(password, salt=None, prefix="1"):
import cmk.gui.md5crypt
@@ -43,6 +43,7 @@ def encrypt_password(password, salt=None, prefix="1"):
return cmk.gui.md5crypt.md5crypt(password, salt, '$%s$' % prefix)
+(a)user_connector_registry.register
class HtpasswdUserConnector(UserConnector):
@classmethod
def type(cls):
diff --git a/cmk/gui/plugins/userdb/ldap_connector.py
b/cmk/gui/plugins/userdb/ldap_connector.py
index 12da8f4..f4a834f 100644
--- a/cmk/gui/plugins/userdb/ldap_connector.py
+++ b/cmk/gui/plugins/userdb/ldap_connector.py
@@ -65,7 +65,7 @@ from cmk.gui.valuespec import *
from cmk.gui.i18n import _
from cmk.gui.globals import html
from cmk.gui.exceptions import MKGeneralException, MKUserError
-from . import UserConnector
+from . import UserConnector, user_connector_registry
# LDAP attributes are case insensitive, we only use lower case!
# Please note: This are only default values. The user might override this
@@ -132,6 +132,7 @@ def ldap_test_module():
# | This class realizes the ldap connection and communication |
# '----------------------------------------------------------------------'
+(a)user_connector_registry.register
class LDAPUserConnector(UserConnector):
# stores the ldap connection suffixes of all connections
connection_suffixes = {}
diff --git a/cmk/gui/plugins/userdb/utils.py b/cmk/gui/plugins/userdb/utils.py
index 39e17f6..9314b70 100644
--- a/cmk/gui/plugins/userdb/utils.py
+++ b/cmk/gui/plugins/userdb/utils.py
@@ -216,7 +216,6 @@ class UserConnectorRegistry(cmk.gui.plugin_registry.ClassRegistry):
user_connector_registry = UserConnectorRegistry()
-user_connector_registry.load_plugins()
class UserAttributeRegistry(cmk.gui.plugin_registry.ObjectRegistry):