Module: check_mk
Branch: master
Commit: b2dfc9159442a3feb73d01d652783a84f0388ccc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b2dfc9159442a3…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Wed Apr 11 19:09:49 2018 +0200
Remove _what from CustomAttrMode._save_attributes in wato.py
Change-Id: Ie8fd91d1733b62ed6c6b6b786c9848e779ea71b2
---
web/htdocs/wato.py | 49 +++++++++++++++++++++++++++++++++++++------------
1 file changed, 37 insertions(+), 12 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 103ed30..e3bbe0e 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -15521,6 +15521,18 @@ class ModePatternEditor(WatoMode):
# | Mange custom attributes of users (in future hosts etc.) |
# '----------------------------------------------------------------------'
+
+def update_user_custom_attrs():
+ userdb.declare_custom_user_attrs()
+ userdb.rewrite_users()
+
+
+def update_host_custom_attrs():
+ declare_custom_host_attrs()
+ watolib.Folder.invalidate_caches()
+ watolib.Folder.root_folder().rewrite_hosts_files()
+
+
class CustomAttrMode(WatoMode):
def __init__(self, what):
# TODO: move _what to the subclasses.
@@ -15544,6 +15556,7 @@ class CustomAttrMode(WatoMode):
def _load(self, lock):
+ # TODO: cleanup that the method knows the subclasses 'user' and
'host' implicitely
filename = os.path.join(multisite_dir, "custom_attrs.mk")
vars = store.load_mk_file(filename, {
'wato_user_attrs': [],
@@ -15556,23 +15569,17 @@ class CustomAttrMode(WatoMode):
return attrs
- def _save_attributes(self):
- self._save(self._all_attrs)
- if self._what == "user":
- userdb.declare_custom_user_attrs()
- userdb.rewrite_users()
- else:
- declare_custom_host_attrs()
- watolib.Folder.invalidate_caches()
- watolib.Folder.root_folder().rewrite_hosts_files()
+ def _update_config(self):
+ raise NotImplementedError()
- def _save(self, attrs):
+ def _save_attributes(self):
+ # TODO: cleanup that the method knows the subclasses 'user' and
'host' implicitely
output = watolib.wato_fileheader()
for what in [ "user", "host" ]:
- if what in attrs and len(attrs[what]) > 0:
+ if what in self._all_attrs and len(self._all_attrs[what]) > 0:
output += "if type(wato_%s_attrs) != list:\n wato_%s_attrs =
[]\n" % (what, what)
- output += "wato_%s_attrs += %s\n\n" % (what,
pprint.pformat(attrs[what]))
+ output += "wato_%s_attrs += %s\n\n" % (what,
pprint.pformat(self._all_attrs[what]))
make_nagios_directory(multisite_dir)
store.save_file(multisite_dir + "custom_attrs.mk", output)
@@ -15660,6 +15667,7 @@ class ModeEditCustomAttr(CustomAttrMode):
self._attr['user_editable'] = user_editable
self._save_attributes()
+ self._update_config()
return self._what + "_attrs"
@@ -15749,6 +15757,10 @@ class ModeEditCustomUserAttr(ModeEditCustomAttr):
def __init__(self):
super(ModeEditCustomUserAttr, self).__init__('user')
+
+ def _update_config(self):
+ update_user_custom_attrs()
+
def title(self):
if self._new:
return _("Create User Attribute")
@@ -15765,6 +15777,10 @@ class ModeEditCustomHostAttr(ModeEditCustomAttr):
def __init__(self):
super(ModeEditCustomHostAttr, self).__init__('host')
+
+ def _update_config(self):
+ update_host_custom_attrs()
+
def title(self):
if self._new:
return _("Create Host Attribute")
@@ -15806,6 +15822,7 @@ class ModeCustomAttrs(CustomAttrMode):
if attr['name'] == delname:
self._attrs.pop(index)
self._save_attributes()
+ self._update_config()
add_change("edit-%sattrs" % self._what, _("Deleted
attribute %s") % (delname))
elif c == False:
return ""
@@ -15840,6 +15857,10 @@ class ModeCustomUserAttrs(ModeCustomAttrs):
super(ModeCustomUserAttrs, self).__init__('user')
+ def _update_config(self):
+ update_user_custom_attrs()
+
+
def title(self):
return _("Custom User Attributes")
@@ -15855,6 +15876,10 @@ class ModeCustomHostAttrs(ModeCustomAttrs):
super(ModeCustomHostAttrs, self).__init__('host')
+ def _update_config(self):
+ update_host_custom_attrs()
+
+
def title(self):
return _("Custom Host Attributes")