Module: check_mk
Branch: master
Commit: d216eaa87d4aa7be5d43c5abf96798ad0392a8cb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d216eaa87d4aa7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Feb 19 14:34:10 2018 +0100
Minor refactoring: Cleanup host/folder attribute transformations
Change-Id: I687ae606c20c55e668eca48f63c9dd9eada771b9
---
web/htdocs/watolib.py | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index a1ed619..f6c8845 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -1279,11 +1279,7 @@ class CREFolder(BaseFolder):
if host_name in variables["host_attributes"]:
attributes = variables["host_attributes"][host_name]
- attributes = self._transform_old_agent_type_in_attributes(attributes)
-
- # Old WATO was saving "site" attribute with value of None. Skip
this key.
- if "site" in attributes and attributes["site"] == None:
- del attributes["site"]
+ attributes = self._transform_old_attributes(attributes)
else:
host_tags = self._transform_old_agent_type_in_tag_list(host_tags)
@@ -1333,6 +1329,13 @@ class CREFolder(BaseFolder):
return host_tags
+ def _transform_old_attributes(self, attributes):
+ """Mangle all attribute structures read from the disk to prepare
it for the current logic"""
+ attributes = self._transform_old_agent_type_in_attributes(attributes)
+ attributes = self._transform_none_value_site_attribute(attributes)
+ return attributes
+
+
# Old tag group trans:
#('agent', u'Agent type',
# [
@@ -1375,6 +1378,13 @@ class CREFolder(BaseFolder):
return attributes
+ def _transform_none_value_site_attribute(self, attributes):
+ # Old WATO was saving "site" attribute with value of None. Skip this
key.
+ if "site" in attributes and attributes["site"] == None:
+ del attributes["site"]
+ return attributes
+
+
def _load_hosts_file(self):
variables = {
"FOLDER_PATH" : "",
@@ -1582,7 +1592,7 @@ class CREFolder(BaseFolder):
def _load(self):
wato_info = self._load_wato_info()
self._title = wato_info.get("title",
self._fallback_title())
- self._attributes =
self._transform_old_agent_type_in_attributes(wato_info.get("attributes", {}))
+ self._attributes =
self._transform_old_attributes(wato_info.get("attributes", {}))
self._locked = wato_info.get("lock", False)
self._locked_subfolders = wato_info.get("lock_subfolders", False)