From bdf835a5151f1ba2860ac103115d594e8b01be97 Mon Sep 17 00:00:00 2001 From: rohitthakur2590 Date: Thu, 16 Jan 2025 18:01:47 +0530 Subject: [PATCH] Add deprecation warning Signed-off-by: rohitthakur2590 --- .../fragments/deprecate_parsing_filter_plugins.yaml | 8 ++++++++ plugins/filter/parse_cli.py | 11 ++++++++--- plugins/filter/parse_cli_textfsm.py | 11 ++++++++--- plugins/filter/parse_xml.py | 10 ++++++++-- 4 files changed, 32 insertions(+), 8 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..febdb38ba --- /dev/null +++ b/changelogs/fragments/deprecate_parsing_filter_plugins.yaml @@ -0,0 +1,8 @@ +--- +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/plugins/filter/parse_cli.py b/plugins/filter/parse_cli.py index d9a3bb675..eb1736e20 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 @@ -135,17 +136,21 @@ from ansible_collections.ansible.netcommon.plugins.plugin_utils.parse_cli import parse_cli - try: from jinja2.filters import pass_environment 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..005ca53a6 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: @@ -92,17 +93,21 @@ parse_cli_textfsm, ) - try: from jinja2.filters import pass_environment 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..d40409a37 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: @@ -166,17 +167,22 @@ from ansible_collections.ansible.netcommon.plugins.plugin_utils.parse_xml import parse_xml - try: from jinja2.filters import pass_environment 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)