From ac9a0c2fd95edc93753b5f4c236991fb3634750a Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Mon, 23 May 2022 12:03:58 -0400 Subject: Add support for icmpv6 type-name in firewall_rules (#258) Add support for icmpv6 type-name in firewall_rules Signed-off-by: GomathiselviS gomathiselvi@gmail.com SUMMARY Fixes #257 ISSUE TYPE Feature Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Sagar Paul --- .../vyos/config/firewall_rules/firewall_rules.py | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'plugins/module_utils/network') diff --git a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py index 2920878c..ca47652f 100644 --- a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py +++ b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py @@ -29,6 +29,7 @@ from ansible.module_utils.six import iteritems from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( list_diff_want_only, ) +import re class Firewall_rules(ConfigBase): @@ -575,10 +576,27 @@ class Firewall_rules(ConfigBase): and not (h_icmp and self._is_w_same(w[attr], h_icmp, item)) ): if item == "type_name": + os_version = self._get_os_version() + ver = re.search( + "vyos ([\\d\\.]+)-?.*", # noqa: W605 + os_version, + re.IGNORECASE, + ) + if ver.group(1) >= "1.4": + param_name = "type-name" + else: + param_name = "type" if "ipv6-name" in cmd: commands.append( cmd - + (" " + "icmpv6" + " " + "type" + " " + val) + + ( + " " + + "icmpv6" + + " " + + param_name + + " " + + val + ) ) else: commands.append( @@ -1040,3 +1058,11 @@ class Firewall_rules(ConfigBase): "enable_default_log", ) return True if key in r_set else False + + def _get_os_version(self): + os_version = "1.2" + if self._connection: + os_version = self._connection.get_device_info()[ + "network_os_version" + ] + return os_version -- cgit v1.2.3