From 3185a944a82ee9ed6c3e77076239542369b4e4bd Mon Sep 17 00:00:00 2001 From: Rohit Thakur Date: Fri, 17 Jan 2025 10:55:12 +0530 Subject: [PATCH] Deprecate Parser filter plugins (#682) * Add deprecation warning Signed-off-by: rohitthakur2590 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: rohitthakur2590 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../fragments/deprecate_parsing_filter_plugins.yaml | 6 ++++++ docs/ansible.netcommon.parse_cli_filter.rst | 1 + docs/ansible.netcommon.parse_cli_textfsm_filter.rst | 1 + docs/ansible.netcommon.parse_xml_filter.rst | 1 + plugins/filter/parse_cli.py | 11 +++++++++-- plugins/filter/parse_cli_textfsm.py | 11 +++++++++-- plugins/filter/parse_xml.py | 10 +++++++++- 7 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/deprecate_parsing_filter_plugins.yaml diff --git a/changelogs/fragments/deprecate_parsing_filter_plugins.yaml b/changelogs/fragments/deprecate_parsing_filter_plugins.yaml new file mode 100644 index 000000000..e1040cee1 --- /dev/null +++ b/changelogs/fragments/deprecate_parsing_filter_plugins.yaml @@ -0,0 +1,6 @@ +--- +deprecated_features: + - "`parse_cli` filter plugin is deprecated and will be removed in a future release after 2027-02-01. Use `ansible.utils.cli_parse` as a replacement." + - "`parse_cli_textfsm` filter plugin is deprecated and will be removed in a future release after 2027-02-01. Use `ansible.utils.cli_parse` with the `ansible.utils.textfsm_parser` parser as a replacement." + - "`parse_xml` filter plugin is deprecated and will be removed in a future release after 2027-02-01. Use `ansible.utils.cli_parse` with the `ansible.utils.xml_parser` parser as a replacement." + - "Added deprecation warnings for the above plugins, displayed when running respective filter plugins." diff --git a/docs/ansible.netcommon.parse_cli_filter.rst b/docs/ansible.netcommon.parse_cli_filter.rst index 0c0069af1..6c3ba8f8b 100644 --- a/docs/ansible.netcommon.parse_cli_filter.rst +++ b/docs/ansible.netcommon.parse_cli_filter.rst @@ -19,6 +19,7 @@ Synopsis -------- - The filter plugins converts the output of a network device CLI command into structured JSON output. - Using the parameters below - ``xml_data | ansible.netcommon.parse_cli(template.yml``) +- This plugin is deprecated and will be removed in a future release after 2027-02-01, please Use ansible.utils.cli_parse instead. diff --git a/docs/ansible.netcommon.parse_cli_textfsm_filter.rst b/docs/ansible.netcommon.parse_cli_textfsm_filter.rst index 56a07e315..cdbd548e1 100644 --- a/docs/ansible.netcommon.parse_cli_textfsm_filter.rst +++ b/docs/ansible.netcommon.parse_cli_textfsm_filter.rst @@ -19,6 +19,7 @@ Synopsis -------- - The network filters also support parsing the output of a CLI command using the TextFSM library. To parse the CLI output with TextFSM use this filter. - Using the parameters below - ``data | ansible.netcommon.parse_cli_textfsm(template.yml``) +- This plugin is deprecated and will be removed in a future release after 2027-02-01, please Use ansible.utils.cli_parse instead. diff --git a/docs/ansible.netcommon.parse_xml_filter.rst b/docs/ansible.netcommon.parse_xml_filter.rst index 487d79b82..7d01cc550 100644 --- a/docs/ansible.netcommon.parse_xml_filter.rst +++ b/docs/ansible.netcommon.parse_xml_filter.rst @@ -19,6 +19,7 @@ Synopsis -------- - This filter will load the spec file and pass the command output through it, returning JSON output. - The YAML spec file defines how to parse the CLI output. +- This plugin is deprecated and will be removed in a future release after 2027-02-01, please Use ansible.utils.cli_parse instead. diff --git a/plugins/filter/parse_cli.py b/plugins/filter/parse_cli.py index d9a3bb675..041f0222b 100644 --- a/plugins/filter/parse_cli.py +++ b/plugins/filter/parse_cli.py @@ -22,6 +22,7 @@ - The filter plugins converts the output of a network device CLI command into structured JSON output. - Using the parameters below - C(xml_data | ansible.netcommon.parse_cli(template.yml)) + - This plugin is deprecated and will be removed in a future release after 2027-02-01, please Use ansible.utils.cli_parse instead. notes: - The parse_cli filter will load the spec file and pass the command output through it, returning JSON output. The YAML spec file defines how to parse the CLI output @@ -141,11 +142,17 @@ except ImportError: from jinja2.filters import environmentfilter as pass_environment +from ansible.utils.display import Display + @pass_environment def _parse_cli(*args, **kwargs): - """Extend vlan data""" - + """parse cli""" + display = Display() + display.warning( + "The 'parse_cli' filter is deprecated and will be removed in a future release " + "after 2027-02-01. Use 'ansible.utils.cli_parse' instead." + ) keys = ["output", "tmpl"] data = dict(zip(keys, args[1:])) data.update(kwargs) diff --git a/plugins/filter/parse_cli_textfsm.py b/plugins/filter/parse_cli_textfsm.py index 1319c0c8a..4c623bf75 100644 --- a/plugins/filter/parse_cli_textfsm.py +++ b/plugins/filter/parse_cli_textfsm.py @@ -22,6 +22,7 @@ - The network filters also support parsing the output of a CLI command using the TextFSM library. To parse the CLI output with TextFSM use this filter. - Using the parameters below - C(data | ansible.netcommon.parse_cli_textfsm(template.yml)) + - This plugin is deprecated and will be removed in a future release after 2027-02-01, please Use ansible.utils.cli_parse instead. notes: - Use of the TextFSM filter requires the TextFSM library to be installed. options: @@ -98,11 +99,17 @@ except ImportError: from jinja2.filters import environmentfilter as pass_environment +from ansible.utils.display import Display + @pass_environment def _parse_cli_textfsm(*args, **kwargs): - """Extend vlan data""" - + """parse textfsm""" + display = Display() + display.warning( + "The 'parse_cli_textfsm' filter is deprecated and will be removed in a future release " + "after 2027-02-01. Use 'ansible.utils.cli_parse' instead." + ) keys = ["value", "template"] data = dict(zip(keys, args[1:])) data.update(kwargs) diff --git a/plugins/filter/parse_xml.py b/plugins/filter/parse_xml.py index 0932971c7..657b44975 100644 --- a/plugins/filter/parse_xml.py +++ b/plugins/filter/parse_xml.py @@ -22,6 +22,7 @@ - This filter will load the spec file and pass the command output through it, returning JSON output. - The YAML spec file defines how to parse the CLI output. + - This plugin is deprecated and will be removed in a future release after 2027-02-01, please Use ansible.utils.cli_parse instead. notes: - To convert the XML output of a network device command into structured JSON output. options: @@ -172,11 +173,18 @@ except ImportError: from jinja2.filters import environmentfilter as pass_environment +from ansible.utils.display import Display + @pass_environment def _parse_xml(*args, **kwargs): - """Extend vlan data""" + """parse xml""" + display = Display() + display.warning( + "The 'parse_xml' filter is deprecated and will be removed in a future release " + "after 2027-02-01. Use 'ansible.utils.cli_parse' instead." + ) keys = ["output", "tmpl"] data = dict(zip(keys, args[1:])) data.update(kwargs)