diff --git a/plugins/module_utils/network/vyos/argspec/nat/nat.py b/plugins/module_utils/network/vyos/argspec/nat/nat.py index dff309ae..a8e5cd41 100644 --- a/plugins/module_utils/network/vyos/argspec/nat/nat.py +++ b/plugins/module_utils/network/vyos/argspec/nat/nat.py @@ -1,179 +1,182 @@ # -*- coding: utf-8 -*- # Copyright 2024 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type ############################################# # WARNING # ############################################# # # This file is auto generated by the # cli_rm_builder. # # Manually editing this file is not advised. # # To update the argspec make the desired changes # in the module docstring and re-run # cli_rm_builder. # ############################################# """ The arg spec for the vyos_nat module """ class NatArgs(object): # pylint: disable=R0903 """The arg spec for the vyos_nat module""" argument_spec = { "config": { "type": "dict", "options": { "cgnat": { "type": "dict", "options": { "log_allocation": { "type": "bool", }, "pool": { "type": "dict", "options": { "external": { "type": "list", "elements": "dict", "options": { "name": { "type": "str", "required": True, }, "external_port_range": { "type": "str", }, "per_user_limit_port": { "type": "int", }, "ranges": { "type": "list", "elements": "str", }, }, }, "internal": { "type": "list", "elements": "dict", "options": { "name": { "type": "str", "required": True, }, "ranges": { "type": "list", "elements": "str", }, }, }, }, }, "rule": { "type": "list", "elements": "dict", "options": { "id": { "type": "int", "required": True, }, "source": { "type": "dict", "options": { "pool": { "type": "str", }, }, }, "translation": { "type": "dict", "options": { "pool": { "type": "str", }, }, }, }, }, }, }, "destination": { "type": "dict", "options": { "rule": { "type": "list", "elements": "dict", "options": { "id": { "type": "int", "required": True, }, "description": { "type": "str", }, "destination": { "type": "dict", "options": { "address": { "type": "str", }, "fqdn": { "type": "str", }, "group": { "type": "dict", "options": { "address-group": { "type": "str", }, "domain-group": { "type": "str", }, "mac-group": { "type": "str", }, "network-group": { "type": "str", }, "port-group": { "type": "str", }, }, }, "port": { "type": "str", }, + "protocol": { + "type": "str", + }, }, }, }, }, }, }, }, }, "running_config": {"type": "str"}, "state": { "type": "str", "choices": [ "deleted", "merged", "overridden", "replaced", "gathered", "rendered", "parsed", ], "default": "merged", }, } # pylint: disable=C0301 diff --git a/plugins/module_utils/network/vyos/rm_templates/nat.py b/plugins/module_utils/network/vyos/rm_templates/nat.py index bad4a343..f5d2d133 100644 --- a/plugins/module_utils/network/vyos/rm_templates/nat.py +++ b/plugins/module_utils/network/vyos/rm_templates/nat.py @@ -1,457 +1,454 @@ # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type """ The Nat parser templates file. This contains a list of parser definitions and associated functions that facilitates both facts gathering and native command generation for the given network resource. """ import re from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) class NatTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): prefix = {"set": "set", "remove": "delete"} self._overrides = { # 1.4+ by default "_path": "service", # 1.4 or greater, "system" for 1.3 or less "_ac": "allow-client", # 1.4 or greater, "allow-clients" for 1.3 or less } super(NatTemplate, self).__init__(lines=lines, tmplt=self, prefix=prefix, module=module) # def set_nat_path(self, path: str): # """set_nat_path""" # self._overrides["_path"] = path # def set_ntp_ac(self, ac: str): # """set_ntp_ac""" # self._overrides["_ac"] = ac # def render(self, data, parser_name, negate=False): # """render""" # # add path to the data before rendering # data = data.copy() # data.update(self._overrides) # # call the original method # return super(NtpTemplate, self).render(data, parser_name, negate) # fmt: off PARSERS = [ - - - - # set nat cgnat log-allocation { "name": "log_allocation", "getval": re.compile( r""" ^set\s nat\s cgnat\s log-allocation $ """, re.VERBOSE, ), "setval": "nat cgnat log-allocation", "result": { "cgnat": { "log_allocation": True, }, }, }, - - # set nat cgnat pool external external-port-range { "name": "external_port_range", "getval": re.compile( r""" ^set\s nat\s cgnat\s pool\s external\s (?P\S+)\s external-port-range\s ['"]?(?P\S+)['"]? $ """, re.VERBOSE, ), "setval": "nat cgnat pool external {{name}} external-port-range '{{external_port_range}}'", "result": { "cgnat": { "pool": { "external": [ { "name": "{{name}}", "external_port_range": "{{range}}", }, ], }, }, }, }, - - # set nat cgnat pool external per-user-limit port { "name": "per_user_limit_port", "getval": re.compile( r""" ^set\s nat\s cgnat\s pool\s external\s (?P\S+)\s per-user-limit\s port\s ['"]?(?P\d+)['"]? $ """, re.VERBOSE, ), "setval": "nat cgnat pool external {{name}} per-user-limit port '{{per_user_limit_port}}'", "result": { "cgnat": { "pool": { "external": [ { "name": "{{name}}", "per_user_limit_port": "{{limit}}", }, ], }, }, }, }, - - # set nat cgnat pool external range { "name": "external_range", "getval": re.compile( r""" ^set\s nat\s cgnat\s pool\s external\s (?P\S+)\s range\s ['"]?(?P\S+)['"]? $ """, re.VERBOSE, ), "setval": "nat cgnat pool external {{name}} range '{{range}}'", "result": { "cgnat": { "pool": { "external": [ { "name": "{{name}}", "ranges": ["{{range}}"], }, ], }, }, }, }, - - # set nat cgnat pool external range seq { "name": "external_range_seq", "getval": re.compile( r""" ^set\s nat\s cgnat\s pool\s external\s (?P\S+)\s range\s ['"]?(?P\S+)['"]?\s seq\s ['"]?(?P\d+)['"]? $ """, re.VERBOSE, ), "setval": "nat cgnat pool external {{name}} range '{{range}}' seq '{{seq}}'", "result": { "cgnat": { "pool": { "external": [ { "name": "{{name}}", "ranges": ["{{range}}"], "seq": "{{seq}}", }, ], }, }, }, }, - - # set nat cgnat pool internal range { "name": "internal_range", "getval": re.compile( r""" ^set\s nat\s cgnat\s pool\s internal\s (?P\S+)\s range\s ['"]?(?P\S+)['"]? $ """, re.VERBOSE, ), "setval": "nat cgnat pool internal {{name}} range '{{range}}'", "result": { "cgnat": { "pool": { "internal": [ { "name": "{{name}}", "ranges": ["{{range}}"], }, ], }, }, }, }, - - # set nat cgnat rule source pool { "name": "rule_source_pool", "getval": re.compile( r""" ^set\s nat\s cgnat\s rule\s (?P\d+)\s source\s pool\s ['"]?(?P\S+)['"]? $ """, re.VERBOSE, ), "setval": "nat cgnat rule {{id}} source pool '{{source_pool}}'", "result": { "cgnat": { "rule": [ { "id": "{{id}}", "source": { "pool": "{{pool}}", }, }, ], }, }, }, - - # set nat cgnat rule translation pool { "name": "rule_translation_pool", "getval": re.compile( r""" ^set\s nat\s cgnat\s rule\s (?P\d+)\s translation\s pool\s ['"]?(?P\S+)['"]? $ """, re.VERBOSE, ), "setval": "nat cgnat rule {{id}} translation pool '{{translation_pool}}'", "result": { "cgnat": { "rule": [ { "id": "{{id}}", "translation": { "pool": "{{pool}}", }, }, ], }, }, }, - - # set nat destination rule description { - "name": "nat_destination_description", + "name": "nat_type_description", "getval": re.compile( r""" ^set\s nat\s - destination\s + (?Pdestination|source|static)\s rule\s (?P\d+)\s description\s (?P.+) $ """, re.VERBOSE, ), - "setval": "nat destination rule {{ rule }} description {{ description }}", + "setval": "nat {{ type }} rule {{ rule }} description {{ description }}", "result": { - "destination": { + "{{ type }}": { "rule": { "{{ rule }}": { "description": "{{ description }}", }, }, }, }, }, - - # set nat destination rule destination address { - "name": "nat_destination_dest_address", + "name": "nat_type_protocol", "getval": re.compile( r""" ^set\s nat\s - destination\s + (?Pdestination|source|static)\s rule\s (?P\d+)\s - destination\s + protocol\s + (?P\S+) + $ + """, + re.VERBOSE, + ), + "setval": "nat {{ type }} rule {{ rule }} protocol {{ protocol }}", + "result": { + "{{ type }}": { + "rule": { + "{{ rule }}": { + "protocol": "{{ protocol }}", + }, + }, + }, + }, + }, + { + "name": "nat_type_dest_address", + "getval": re.compile( + r""" + ^set\s + nat\s + (?Pdestination|source|static)\s + rule\s + (?P\d+)\s + (?Pdestination|source|static)\s address\s (?P\S+) $ """, re.VERBOSE, ), - "setval": "nat destination rule {{ rule }} destination address {{ dest_address }}", + "setval": "nat {{ type }} rule {{ rule }} {{ atype }} address {{ dest_address }}", "result": { - "destination": { + "{{ type }}": { "rule": { "{{ rule }}": { - "destination": { + "{{ atype }}": { "address": "{{ dest_address }}", }, }, }, }, }, }, - - # set nat destination rule destination port { - "name": "nat_destination_dest_port", + "name": "nat_type_dest_port", "getval": re.compile( r""" ^set\s nat\s - destination\s + (?Pdestination|source|static)\s rule\s (?P\d+)\s - destination\s + (?Pdestination|source|static)\s port\s (?P\d+) $ """, re.VERBOSE, ), - "setval": "nat destination rule {{ rule }} destination port {{ dest_port }}", + "setval": "nat {{ type }} rule {{ rule }} {{ atype }} port {{ dest_port }}", "result": { - "destination": { + "{{ type }}": { "rule": { "{{ rule }}": { - "destination": { + "{{ atype }}": { "port": "{{ dest_port }}", }, }, }, }, }, }, - - # set nat destination rule translation address { - "name": "nat_destination_translation_address", + "name": "nat_type_translation_address", "getval": re.compile( r""" ^set\s nat\s - destination\s + (?Pdestination|source|static)\s rule\s (?P\d+)\s translation\s address\s (?P\S+) $ """, re.VERBOSE, ), - "setval": "nat destination rule {{ rule }} translation address {{ trans_address }}", + "setval": "nat {{ type }} rule {{ rule }} translation address {{ trans_address }}", "result": { - "destination": { + "{{ type }}": { "rule": { "{{ rule }}": { "translation": { "address": "{{ trans_address }}", }, }, }, }, }, }, - - # set nat destination rule translation port { - "name": "nat_destination_translation_port", + "name": "nat_type_translation_port", "getval": re.compile( r""" ^set\s nat\s - destination\s + (?Pdestination|source|static)\s rule\s (?P\d+)\s translation\s port\s (?P\d+) $ """, re.VERBOSE, ), - "setval": "nat destination rule {{ rule }} translation port {{ trans_port }}", + "setval": "nat {{ type }} rule {{ rule }} translation port {{ trans_port }}", "result": { - "destination": { + "{{ type }}": { "rule": { "{{ rule }}": { "translation": { "port": "{{ trans_port }}", }, }, }, }, }, }, - ] # fmt: on