diff --git a/plugins/module_utils/network/vyos/rm_templates/vrf.py b/plugins/module_utils/network/vyos/rm_templates/vrf.py index 644386be..0e646c92 100644 --- a/plugins/module_utils/network/vyos/rm_templates/vrf.py +++ b/plugins/module_utils/network/vyos/rm_templates/vrf.py @@ -1,174 +1,163 @@ # -*- 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 Ntp 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 VrfTemplate(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(VrfTemplate, self).__init__(lines=lines, tmplt=self, prefix=prefix, module=module) - # def set_ntp_path(self, path: str): - # """set_ntp_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(VrfTemplate, self).render(data, parser_name, negate) - # fmt: off PARSERS = [ - - # set system ntp allow_clients address
{ - "name": "set_table", + "name": "table", "getval": re.compile( r""" ^set \svrf + \sname \s(?P\S+) \stable \s(?P\S+) $""", re.VERBOSE, ), - "setval": "{{_path}} ntp {{_ac}} address {{allow_clients}}", + "setval": "vrf name {{name}} table {{tid}}", + "compval": "tid", "result": { "name": "{{ name }}", "tid": "{{ tid }}", }, }, - - # set system ntp allow_clients { - "name": "allow_clients_delete", + "name": "vni", "getval": re.compile( r""" - ^set\s(?Psystem|service)\sntp\s(?Pallow-clients|allow-client) + ^set + \svrf + \sname + \s(?P\S+) + \svni + \s(?P\S+) $""", re.VERBOSE, ), - "setval": "{{_path}} ntp {{_ac}}", + "setval": "vrf name {{name}} vni {{tid}}", + "compval": "vni", "result": { - + "name": "{{ name }}", + "vni": "{{ vni }}", }, - }, - - # set system ntp listen_address
{ - "name": "listen_addresses", + "name": "description", "getval": re.compile( r""" - ^set\s(?Psystem|service)\sntp\slisten-address (\s(?P\S+))? - $""", - re.VERBOSE, - ), - "setval": "{{_path}} ntp listen-address {{listen_addresses}}", - "result": { - "listen_addresses": ["{{ip_address}}"], - }, - }, - - # set system ntp listen_address - { - "name": "listen_addresses_delete", - "getval": re.compile( - r""" - ^set\s(?Psystem|service)\sntp\slisten-address + ^set + \svrf + \sname + \s(?P\S+) + \sdescription + \s(?P\S+) $""", re.VERBOSE, ), - "setval": "{{_path}} ntp listen-address", + "setval": "vrf name {{name}} description {{desc}}", + "compval": "desc", "result": { + "name": "{{ name }}", + "description": "{{ desc }}", }, }, - - # set {{path}} ntp - for deleting the ntp configuration { - "name": "service_delete", + "name": "disable_vrf", "getval": re.compile( r""" - ^set\s(?Psystem|service)\sntp$ + ^set + \svrf + \sname + \s(?P\S+) + \s(?Pdisable) $""", re.VERBOSE, ), - "setval": "{{_path}} ntp", + "setval": "vrf name {{name}} description disable", + "compval": "desc", "result": { + "name": "{{ name }}", + "disable": "{{ True if disable is defined }}", }, }, - - # set system ntp server { - "name": "server", + "name": "disable_forwarding", "getval": re.compile( r""" - ^set\s(?Psystem|service)\sntp\sserver (\s(?P\S+)) + ^set + \svrf + \sname + \s(?P\S+) + \s(?P\S+) + \s(?Pdisable-forwarding) $""", re.VERBOSE, ), - "setval": "{{_path}} ntp server {{server}}", + "setval": "vrf name {{name}} {{ af }} disable-forwarding", + "compval": "address_family.disable_forwarding", "result": { - "servers": { - "{{name}}": { - "server": "{{name}}", + "name": "{{ name }}", + "address_family": { + '{{ "ipv4" if af == "ip" else "ipv6" }}': { + "afi": '{{ "ipv4" if af == "ip" else "ipv6" }}', + "disable_forwarding": "{{ True if df is defined }}", }, }, - }, }, - - # set system ntp server { - "name": "options", + "name": "disable_nht", "getval": re.compile( r""" - ^set\s(?Psystem|service)\sntp\sserver + ^set + \svrf + \sname \s(?P\S+) - \s(?Pdynamic|preempt|pool|noselect|prefer|nts|interleave|ptp) + \s(?P\S+) + \snht + \s(?Pno-resolve-via-default) $""", re.VERBOSE, ), - "setval": "{{_path}} ntp server {{server}} {{options}}", + "setval": "vrf name {{name}} {{ af }} nht no-resolve-via-default", + "compval": "address_family.no_resolve_via_default", "result": { - "servers": { - "{{name}}": { - "server": "{{name}}", - "options": ["{{options}}"], + "name": "{{ name }}", + "address_family": { + '{{ "ipv4" if af == "ip" else "ipv6" }}': { + "afi": '{{ "ipv4" if af == "ip" else "ipv6" }}', + "no_resolve_via_default": "{{ True if nht is defined }}", }, }, }, }, ] # fmt: on