Esempio n. 1
0
    def do_execute(
        self,
        diagnostics_parameters: DiagnosticsParameters,
        job_interface: BackgroundProcessInterface,
    ) -> None:
        job_interface.send_progress_update(_("Diagnostics dump started..."))

        site = diagnostics_parameters["site"]
        timeout = request.request_timeout - 2
        result = create_diagnostics_dump(
            site,
            serialize_wato_parameters(diagnostics_parameters),
            timeout,
        )

        job_interface.send_progress_update(result.output)

        if result.tarfile_created:
            tarfile_path = result.tarfile_path
            download_url = makeuri_contextless(
                request,
                [("site", site), ("tarfile_name", str(Path(tarfile_path).name))],
                filename="download_diagnostics_dump.py",
            )
            button = html.render_icon_button(download_url, _("Download"), "diagnostics_dump_file")

            job_interface.send_progress_update(_("Dump file: %s") % tarfile_path)
            job_interface.send_result_message(_("%s Retrieve created dump file") % button)

        else:
            job_interface.send_result_message(_("Creating dump file failed"))
Esempio n. 2
0
    def do_execute(
        self,
        diagnostics_parameters: DiagnosticsParameters,
        job_interface: BackgroundProcessInterface,
    ) -> None:
        job_interface.send_progress_update(_("Diagnostics dump started..."))

        chunks = serialize_wato_parameters(diagnostics_parameters)

        # TODO: Currently, selecting multiple sites is not possible.
        # sites = diagnostics_parameters["sites"][1]
        site = diagnostics_parameters["site"]

        timeout = request.request_timeout - 2
        results = []
        for chunk in chunks:
            chunk_result = create_diagnostics_dump(
                site,
                chunk,
                timeout,
            )
            results.append(chunk_result)

        # for site in sites:
        #    for chunk in chunks:

        #        chunk_result = create_diagnostics_dump(
        #            site,
        #            chunk,
        #            timeout,
        #        )
        #        results.append(chunk_result)

        if len(results) > 1:
            result = _merge_results(results)
        elif len(results) == 1:
            result = results[0]
        else:
            job_interface.send_result_message(
                _("Got no result to create dump file"))
            return

        job_interface.send_progress_update(result.output)

        if result.tarfile_created:
            tarfile_path = result.tarfile_path
            download_url = makeuri_contextless(
                request,
                [("site", site),
                 ("tarfile_name", str(Path(tarfile_path).name))],
                filename="download_diagnostics_dump.py",
            )
            button = html.render_icon_button(download_url, _("Download"),
                                             "diagnostics_dump_file")

            job_interface.send_progress_update(
                _("Dump file: %s") % tarfile_path)
            job_interface.send_result_message(
                _("%s Retrieve created dump file") % button)

        else:
            job_interface.send_result_message(_("Creating dump file failed"))