Module: check_mk
Branch: master
Commit: 961a714bdc628bef65aaf9cde06b6fbfb83bd1fa
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=961a714bdc628b…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Jun 11 14:33:21 2018 +0200
Removed two import cycles related to inventory plugins.
This brings the number of cycles down to 6 (from 8).
Change-Id: I75a703fa39827c01fdf4f1bcca9ab5342273ae02
---
cmk_base/checking.py | 2 +-
cmk_base/inventory.py | 20 ++++++++++++++++++++
cmk_base/inventory_plugins.py | 30 ++++--------------------------
cmk_base/modes/check_mk.py | 4 ++--
4 files changed, 27 insertions(+), 29 deletions(-)
diff --git a/cmk_base/checking.py b/cmk_base/checking.py
index fee5656..03160c0 100644
--- a/cmk_base/checking.py
+++ b/cmk_base/checking.py
@@ -394,7 +394,7 @@ def _do_status_data_inventory(sources, multi_host_sections, hostname,
ipaddress)
import cmk_base.inventory as inventory
import cmk_base.inventory_plugins as inventory_plugins
do_inv = False
- inventory_plugins.load()
+ inventory_plugins.load_plugins(inventory.get_inventory_context)
for section_name, plugin in inventory_plugins.inv_info.items():
section_content = multi_host_sections.get_section_content(hostname,
ipaddress,
section_name,
for_discovery=False)
diff --git a/cmk_base/inventory.py b/cmk_base/inventory.py
index 1238b61..a1a4619 100644
--- a/cmk_base/inventory.py
+++ b/cmk_base/inventory.py
@@ -369,3 +369,23 @@ def _run_inventory_export_hooks(hostname, inventory_tree):
raise
raise MKGeneralException("Failed to execute export hook %s: %s" %
(
hookname, e))
+
+#.
+# .--Plugin API----------------------------------------------------------.
+# | ____ _ _ _ ____ ___ |
+# | | _ \| |_ _ __ _(_)_ __ / \ | _ \_ _| |
+# | | |_) | | | | |/ _` | | '_ \ / _ \ | |_) | | |
+# | | __/| | |_| | (_| | | | | | / ___ \| __/| | |
+# | |_| |_|\__,_|\__, |_|_| |_| /_/ \_\_| |___| |
+# | |___/ |
+# +----------------------------------------------------------------------+
+# | Helper API for being used in inventory plugins. Plugins have access |
+# | to all things defined by the regular Check_MK check API and all the |
+# | things declared here. |
+# '----------------------------------------------------------------------'
+
+def get_inventory_context():
+ return [
+ ("inv_tree_list", inv_tree_list),
+ ("inv_tree", inv_tree),
+ ]
diff --git a/cmk_base/inventory_plugins.py b/cmk_base/inventory_plugins.py
index c2de150..c9465dd 100644
--- a/cmk_base/inventory_plugins.py
+++ b/cmk_base/inventory_plugins.py
@@ -32,7 +32,6 @@ from cmk.exceptions import MKGeneralException
import cmk_base.checks as checks
import cmk_base.check_api as check_api
import cmk_base.console as console
-import cmk_base.inventory
import cmk_base.check_utils
# Inventory plugins have dependencies to check plugins and the inventory
@@ -48,7 +47,7 @@ _plugin_contexts = {} # The checks are loaded into this dictionary.
Each check
_include_contexts = {} # These are the contexts of the check include files
-def load(): # pylint: disable=function-redefined
+def load_plugins(get_inventory_context):
loaded_files = set()
filelist = checks.get_plugin_paths(cmk.paths.local_inventory_dir,
cmk.paths.inventory_dir)
@@ -62,7 +61,7 @@ def load(): # pylint: disable=function-redefined
continue # skip already loaded files (e.g. from local)
try:
- plugin_context = _new_inv_context()
+ plugin_context = _new_inv_context(get_inventory_context)
known_plugins = inv_info.keys()
_load_plugin_includes(f, plugin_context)
@@ -81,7 +80,7 @@ def load(): # pylint: disable=function-redefined
_plugin_contexts[check_plugin_name] = plugin_context
-def _new_inv_context():
+def _new_inv_context(get_inventory_context):
# Add the data structures where the inventory plugins register with Check_MK
context = {
"inv_info" : inv_info,
@@ -92,7 +91,7 @@ def _new_inv_context():
#
# For better separation it would be better to copy the check API objects, but
# this might consume too much memory. So we simply reference it.
- for k, v in check_api._get_check_context() + _get_inventory_context():
+ for k, v in check_api._get_check_context() + get_inventory_context():
context[k] = v
return context
@@ -133,24 +132,3 @@ def is_snmp_plugin(plugin_type):
section_name = cmk_base.check_utils.section_name_of(plugin_type)
return "snmp_info" in inv_info.get(section_name, {}) \
or cmk_base.check_utils.is_snmp_check(plugin_type)
-
-
-#.
-# .--Plugin API----------------------------------------------------------.
-# | ____ _ _ _ ____ ___ |
-# | | _ \| |_ _ __ _(_)_ __ / \ | _ \_ _| |
-# | | |_) | | | | |/ _` | | '_ \ / _ \ | |_) | | |
-# | | __/| | |_| | (_| | | | | | / ___ \| __/| | |
-# | |_| |_|\__,_|\__, |_|_| |_| /_/ \_\_| |___| |
-# | |___/ |
-# +----------------------------------------------------------------------+
-# | Helper API for being used in inventory plugins. Plugins have access |
-# | to all things defined by the regular Check_MK check API and all the |
-# | things declared here. |
-# '----------------------------------------------------------------------'
-
-def _get_inventory_context():
- return [
- ("inv_tree_list", cmk_base.inventory.inv_tree_list),
- ("inv_tree", cmk_base.inventory.inv_tree),
- ]
diff --git a/cmk_base/modes/check_mk.py b/cmk_base/modes/check_mk.py
index 695796b..243d8e5 100644
--- a/cmk_base/modes/check_mk.py
+++ b/cmk_base/modes/check_mk.py
@@ -1208,7 +1208,7 @@ def mode_inventory(options, args):
import cmk_base.inventory as inventory
import cmk_base.data_sources as data_sources
import cmk_base.inventory_plugins as inventory_plugins
- inventory_plugins.load()
+ inventory_plugins.load_plugins(inventory.get_inventory_context)
if args:
hostnames = modes.parse_hostname_list(args, with_clusters=True)
@@ -1259,7 +1259,7 @@ modes.register(Mode(
def mode_inventory_as_check(options, hostname):
import cmk_base.inventory as inventory
import cmk_base.inventory_plugins as inventory_plugins
- inventory_plugins.load()
+ inventory_plugins.load_plugins(inventory.get_inventory_context)
return inventory.do_inv_check(hostname, options)