Module: check_mk
Branch: master
Commit: 02518d01059d53e4d6774337343411b6da52709b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=02518d01059d53…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jul 27 23:38:35 2018 +0200
Moved host/cluster implementation specific things out of abstract CreateHostMode()
Change-Id: I3a993c47a8e5541f91c6f15ba756bb41650a682a
---
cmk/gui/wato/__init__.py | 63 ++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 56 insertions(+), 7 deletions(-)
diff --git a/cmk/gui/wato/__init__.py b/cmk/gui/wato/__init__.py
index a55e748..c8354ee 100644
--- a/cmk/gui/wato/__init__.py
+++ b/cmk/gui/wato/__init__.py
@@ -1675,6 +1675,24 @@ class ModeEditHost(HostMode):
class CreateHostMode(HostMode):
+ @classmethod
+ @abc.abstractmethod
+ def _init_new_host_object(cls):
+ raise NotImplementedError()
+
+
+ @classmethod
+ @abc.abstractmethod
+ def _host_type_name(cls):
+ raise NotImplementedError()
+
+
+ @classmethod
+ @abc.abstractmethod
+ def _verify_host_type(cls, host):
+ raise NotImplementedError()
+
+
def _from_vars(self):
if html.var("clone") and self._init_host():
self._mode = "clone"
@@ -1692,21 +1710,17 @@ class CreateHostMode(HostMode):
raise MKAuthException(_("Sorry, you are not allowed to clone
hosts."))
host = watolib.Folder.current().host(clonename)
-
- if isinstance(self, ModeCreateCluster) != host.is_cluster():
- raise MKGeneralException(_("Can not clone a cluster host as regular
host or vice versa"))
-
+ self._verify_host_type(host)
return host
else:
- return watolib.Host(folder=watolib.Folder.current(),
host_name=html.var("host"), attributes={},
- cluster_nodes=[] if isinstance(self, ModeCreateCluster)
else None)
+ return self._init_new_host_object()
def action(self):
if not html.transaction_valid():
return "folder"
- attributes = watolib.collect_attributes("host" if not
self._is_cluster() else "cluster")
+ attributes = watolib.collect_attributes(self._host_type_name())
cluster_nodes = self._get_cluster_nodes()
hostname = html.var("host")
@@ -1760,6 +1774,24 @@ class ModeCreateHost(CreateHostMode):
return _("Create new host")
+ @classmethod
+ def _init_new_host_object(cls):
+ return watolib.Host(folder=watolib.Folder.current(),
host_name=html.var("host"),
+ attributes={}, cluster_nodes=None)
+
+
+ @classmethod
+ def _host_type_name(cls):
+ return "host"
+
+
+ @classmethod
+ def _verify_host_type(cls, host):
+ if host.is_cluster():
+ raise MKGeneralException(_("Can not clone a cluster host as regular
host"))
+
+
+
@mode_registry.register
class ModeCreateCluster(CreateHostMode):
@@ -1784,6 +1816,23 @@ class ModeCreateCluster(CreateHostMode):
return _("Create new cluster")
+ @classmethod
+ def _init_new_host_object(cls):
+ return watolib.Host(folder=watolib.Folder.current(),
host_name=html.var("host"),
+ attributes={}, cluster_nodes=[])
+
+
+ @classmethod
+ def _host_type_name(cls):
+ return "cluster"
+
+
+ @classmethod
+ def _verify_host_type(cls, host):
+ if not host.is_cluster():
+ raise MKGeneralException(_("Can not clone a regular host as cluster
host"))
+
+
#.
# .--Rename Host---------------------------------------------------------.
# | ____ _ _ _ |