Exemple #1
0
    def _add(self, request):
        folder_path = request["folder"]
        watolib.check_wato_foldername(None,
                                      os.path.basename(folder_path),
                                      just_name=True)

        folder_attributes = request.get("attributes", {})
        if "alias" in folder_attributes:
            folder_alias = folder_attributes.pop("alias") or os.path.basename(
                folder_path)
        else:
            folder_alias = os.path.basename(folder_path)

        # Validates host and folder attributes, since there are no real folder attributes, at all...
        validate_host_attributes(folder_attributes, new=True)

        # Check existance of parent folder, create it when configured
        create_parent_folders = bool(
            int(request.get("create_parent_folders", "1")))
        if create_parent_folders or watolib.Folder.folder_exists(
                os.path.dirname(folder_path)):
            watolib.Folder.root_folder().create_missing_folders(folder_path)
            watolib.Folder.folder(folder_path).edit(folder_alias,
                                                    folder_attributes)
        else:
            raise MKUserError(None, _("Unable to create parent folder(s)."))
Exemple #2
0
    def _save(self, title, attributes):
        if not config.wato_hide_filenames:
            name = html.request.var("name", "").strip()
            watolib.check_wato_foldername("name", name)
        else:
            name = _create_wato_foldername(title)

        watolib.Folder.current().create_subfolder(name, title, attributes)
Exemple #3
0
    def _add(self, request):
        create_parent_folders_var = request.get(
            "create_parent_folders", request.get("create_folders", "1"))
        create_parent_folders = bool(int(create_parent_folders_var))

        # Werk #10863: In 1.6 some hosts / rulesets were saved as unicode
        # strings.  After reading the config into the GUI ensure we really
        # process the host names as str. TODO: Can be removed with Python 3.
        hostname = str(request.get("hostname"))
        folder_path = str(request.get("folder"))
        attributes = request.get("attributes", {})
        cluster_nodes = request.get("nodes")

        check_hostname(hostname, should_exist=False)

        # Validate folder
        if folder_path not in ('', '/'):
            folders = folder_path.split("/")
            for foldername in folders:
                watolib.check_wato_foldername(None, foldername, just_name=True)
        else:
            folder_path = ""
            folders = [""]

        # Deprecated, but still supported
        # Nodes are now specified in an extra key
        if ".nodes" in attributes:
            cluster_nodes = attributes[".nodes"]
            del attributes[".nodes"]
        validate_host_attributes(attributes, new=True)

        # Create folder(s)
        if not watolib.Folder.folder_exists(folder_path):
            if not create_parent_folders:
                raise MKUserError(None,
                                  _("Unable to create parent folder(s)."))
            watolib.Folder.create_missing_folders(folder_path)

        # Add host
        if cluster_nodes:
            cluster_nodes = list(map(str, cluster_nodes))
        watolib.Folder.folder(folder_path).create_hosts([(hostname, attributes,
                                                          cluster_nodes)])
Exemple #4
0
    def _add(self, request, bake_hosts=True):
        create_parent_folders_var = request.get(
            "create_parent_folders", request.get("create_folders", "1")
        )
        create_parent_folders = bool(int(create_parent_folders_var))

        hostname = request["hostname"]
        folder_path = request.get("folder", "")
        attributes = request.get("attributes", {})
        cluster_nodes = request.get("nodes")

        check_hostname(hostname, should_exist=False)

        # Validate folder
        if folder_path not in ("", "/"):
            folders = folder_path.split("/")
            for foldername in folders:
                watolib.check_wato_foldername(None, foldername, just_name=True)
        else:
            folder_path = ""
            folders = [""]

        # Deprecated, but still supported
        # Nodes are now specified in an extra key
        if ".nodes" in attributes:
            cluster_nodes = attributes[".nodes"]
            del attributes[".nodes"]
        validate_host_attributes(attributes, new=True)

        # Create folder(s)
        if not watolib.Folder.folder_exists(folder_path):
            if not create_parent_folders:
                raise MKUserError(None, _("Unable to create parent folder(s)."))
            watolib.Folder.create_missing_folders(folder_path)

        # Add host
        if cluster_nodes:
            cluster_nodes = list(map(str, cluster_nodes))
        watolib.Folder.folder(folder_path).create_hosts(
            [(hostname, attributes, cluster_nodes)], bake_hosts=bake_hosts
        )