diff --git a/plugins/module_utils/network/vyos/rm_templates/vrrp.py b/plugins/module_utils/network/vyos/rm_templates/vrrp.py index d4730e5b..8147e487 100644 --- a/plugins/module_utils/network/vyos/rm_templates/vrrp.py +++ b/plugins/module_utils/network/vyos/rm_templates/vrrp.py @@ -1,752 +1,717 @@ # -*- 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 Bgp_global 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.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) class VrrpTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): prefix = {"set": "set", "remove": "delete"} super(VrrpTemplate, self).__init__( lines=lines, tmplt=self, prefix=prefix, module=module, ) def _tmplt_vsrvs(config_data): config_data = config_data["virtual-server"] command = [] # cmd = "service snmp v3 group {group}".format(**config_data) # if "mode" in config_data: # mode_cmd = cmd + " mode {mode}".format(**config_data) # command.append(mode_cmd) # if "seclevel" in config_data: # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) # command.append(sec_cmd) # if "view" in config_data: # view_cmd = cmd + " view {view}".format(**config_data) # command.append(view_cmd) return command def _tmplt_vsrvs_rsrv(config_data): config_data = config_data["virtual-server"]["real_servers"] command = [] # cmd = "service snmp v3 group {group}".format(**config_data) # if "mode" in config_data: # mode_cmd = cmd + " mode {mode}".format(**config_data) # command.append(mode_cmd) # if "seclevel" in config_data: # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) # command.append(sec_cmd) # if "view" in config_data: # view_cmd = cmd + " view {view}".format(**config_data) # command.append(view_cmd) return command def _tmplt_sgroup_hc(config_data): config_data = config_data["sync-group"]["health-check"] command = [] # cmd = "service snmp v3 group {group}".format(**config_data) # if "mode" in config_data: # mode_cmd = cmd + " mode {mode}".format(**config_data) # command.append(mode_cmd) # if "seclevel" in config_data: # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) # command.append(sec_cmd) # if "view" in config_data: # view_cmd = cmd + " view {view}".format(**config_data) # command.append(view_cmd) return command def _tmplt_sgroup_ts(config_data): config_data = config_data["sync-group"]["transition-script"] command = [] # cmd = "service snmp v3 group {group}".format(**config_data) # if "mode" in config_data: # mode_cmd = cmd + " mode {mode}".format(**config_data) # command.append(mode_cmd) # if "seclevel" in config_data: # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) # command.append(sec_cmd) # if "view" in config_data: # view_cmd = cmd + " view {view}".format(**config_data) # command.append(view_cmd) return command def _tmplt_vrrp_gp(config_data): config_data = config_data["vrrp"]["global-parameters"] command = [] # cmd = "service snmp v3 group {group}".format(**config_data) # if "mode" in config_data: # mode_cmd = cmd + " mode {mode}".format(**config_data) # command.append(mode_cmd) # if "seclevel" in config_data: # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) # command.append(sec_cmd) # if "view" in config_data: # view_cmd = cmd + " view {view}".format(**config_data) # command.append(view_cmd) return command def _tmplt_vrrp_gp_garp(config_data): config_data = config_data["vrrp"]["global-parameters"]["garp"] command = [] # cmd = "service snmp v3 group {group}".format(**config_data) # if "mode" in config_data: # mode_cmd = cmd + " mode {mode}".format(**config_data) # command.append(mode_cmd) # if "seclevel" in config_data: # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) # command.append(sec_cmd) # if "view" in config_data: # view_cmd = cmd + " view {view}".format(**config_data) # command.append(view_cmd) return command + def _tmplt_vrrp_group(config_data): + config_data = config_data["vrrp"]["group"] + command = [] + # cmd = "service snmp v3 group {group}".format(**config_data) + # if "mode" in config_data: + # mode_cmd = cmd + " mode {mode}".format(**config_data) + # command.append(mode_cmd) + # if "seclevel" in config_data: + # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) + # command.append(sec_cmd) + # if "view" in config_data: + # view_cmd = cmd + " view {view}".format(**config_data) + # command.append(view_cmd) + return command + + def _tmplt_vrrp_group_track(config_data): + config_data = config_data["vrrp"]["group"]["track"] + command = [] + # cmd = "service snmp v3 group {group}".format(**config_data) + # if "mode" in config_data: + # mode_cmd = cmd + " mode {mode}".format(**config_data) + # command.append(mode_cmd) + # if "seclevel" in config_data: + # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) + # command.append(sec_cmd) + # if "view" in config_data: + # view_cmd = cmd + " view {view}".format(**config_data) + # command.append(view_cmd) + return command + + def _tmplt_vrrp_group_hc(config_data): + config_data = config_data["vrrp"]["group"]["health-check"] + command = [] + # cmd = "service snmp v3 group {group}".format(**config_data) + # if "mode" in config_data: + # mode_cmd = cmd + " mode {mode}".format(**config_data) + # command.append(mode_cmd) + # if "seclevel" in config_data: + # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) + # command.append(sec_cmd) + # if "view" in config_data: + # view_cmd = cmd + " view {view}".format(**config_data) + # command.append(view_cmd) + return command + + def _tmplt_vrrp_group_ts(config_data): + config_data = config_data["vrrp"]["group"]["transcription-script"] + command = [] + # cmd = "service snmp v3 group {group}".format(**config_data) + # if "mode" in config_data: + # mode_cmd = cmd + " mode {mode}".format(**config_data) + # command.append(mode_cmd) + # if "seclevel" in config_data: + # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) + # command.append(sec_cmd) + # if "view" in config_data: + # view_cmd = cmd + " view {view}".format(**config_data) + # command.append(view_cmd) + return command + + def _tmplt_vrrp_group_garp(config_data): + config_data = config_data["vrrp"]["group"]["garp"] + command = [] + # cmd = "service snmp v3 group {group}".format(**config_data) + # if "mode" in config_data: + # mode_cmd = cmd + " mode {mode}".format(**config_data) + # command.append(mode_cmd) + # if "seclevel" in config_data: + # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) + # command.append(sec_cmd) + # if "view" in config_data: + # view_cmd = cmd + " view {view}".format(**config_data) + # command.append(view_cmd) + return command + + def _tmplt_vrrp_group_auth(config_data): + config_data = config_data["vrrp"]["group"]["authentication"] + command = [] + # cmd = "service snmp v3 group {group}".format(**config_data) + # if "mode" in config_data: + # mode_cmd = cmd + " mode {mode}".format(**config_data) + # command.append(mode_cmd) + # if "seclevel" in config_data: + # sec_cmd = cmd + " seclevel {seclevel}".format(**config_data) + # command.append(sec_cmd) + # if "view" in config_data: + # view_cmd = cmd + " view {view}".format(**config_data) + # command.append(view_cmd) + return command + # fmt: off PARSERS = [ { "name": "disable", "getval": re.compile( r""" ^set \shigh-availability \s(?Pdisable) $""", re.VERBOSE, ), "setval": "high-availability disable", "result": { "disable": "{{ True if disable is defined }}", }, }, { "name": "vg_addr", "getval": re.compile( r""" ^set \shigh-availability \svrrp \sgroup \s(?P\S+) \saddress \s(?P
\S+) $""", re.VERBOSE, ), "setval": "high-availability vrrp group {{group}} address {{address}}", "compval": "address", "result": { "group": "{{ group }}", "address": "{{ address }}", }, }, { "name": "vg_addr_addr_int", "getval": re.compile( r""" ^set \shigh-availability \svrrp \sgroup \s(?P\S+) \saddress \s(?P
\S+) \sinterface \s(?P\S+) $""", re.VERBOSE, ), "setval": "high-availability vrrp group {{group}} address {{address}} interface {{interface}}", "compval": "interface", "result": { "group": "{{ group }}", "address": "{{ address }}", "interface": "{{ interface }}", }, }, { "name": "vg_excluded_addr", "getval": re.compile( r""" ^set \shigh-availability \svrrp \sgroup \s(?P\S+) \sexcluded-address \s(?P\S+) $""", re.VERBOSE, ), "setval": "high-availability vrrp group {{group}} excluded-address {{excluded_addr}}", "compval": "excluded_address", "result": { "group": "{{ group }}", "excluded_address": "{{ excluded_addr }}", }, }, { "name": "vg_excluded_addr_int", "getval": re.compile( r""" ^set \shigh-availability \svrrp \sgroup \s(?P\S+) \sexcluded-address \s(?P\S+) \sinterface \s(?P\S+) $""", re.VERBOSE, ), "setval": "high-availability vrrp group {{group}} excluded-address {{excluded_addr}} interface {{excluded_addr_interface}}", "compval": "excluded_address_interface", "result": { "group": "{{ group }}", "excluded_address_interface": "{{ excluded_address_int }}", }, }, - { - "name": "vg_priority", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \spriority - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} priority {{priority}}", - "compval": "priority", - "result": { - "group": "{{ group }}", - "priority": "{{ priority }}", - }, - }, - { - "name": "vg_advertise_interval", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \sadvertise-interval - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} advertise-interval {{adv_int}}", - "compval": "advertise_interval", - "result": { - "group": "{{ group }}", - "advertise_interval": "{{ adv_int }}", - }, - }, - { - "name": "vg_description", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \sdescription - \s(?P.*) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} description {{description}}", - "compval": "description", - "result": { - "group": "{{ group }}", - "description": "{{ description }}", - }, - }, - { - "name": "vg_vrid", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \svrid - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} vrid {{vrid}}", - "compval": "vrid", - "result": { - "group": "{{ group }}", - "vrid": "{{ vrid }}", - }, - }, - { - "name": "vg_no_preempt", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \s(?Pno-preempt) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} no-preempt", - "compval": "no_preempt", - "result": { - "group": "{{ group }}", - "no_preempt": "{{ True if np is defined }}", - }, - }, - { - "name": "vg_preempt_delay", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \spreempt-delay - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} preempt-delay {{prd}}", - "compval": "preempt_delay", - "result": { - "group": "{{ group }}", - "preempt-delay": "{{ prd }}", - }, - }, - { - "name": "vg_authentication_password", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \sauthentication - \spassword - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} authentication password {{pass}}", - "compval": "pass", - "result": { - "group": "{{ group }}", - "authentication": { - "password": "{{ pass }}", - }, - }, - }, - { - "name": "vg_authentication_type", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \sauthentication - \stype - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} authentication type {{type}}", - "compval": "type", - "result": { - "group": "{{ group }}", - "authentication": { - "password": "{{ type }}", - }, - }, - }, - { - "name": "vg_rfc3768", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \srfc3768-compatibility - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} rfc3768-compatibility {{rfc3768}}", - "compval": "rfc3768_compatibility", - "result": { - "group": "{{ group }}", - "rfc3768_compatibility": "{{ True if rfc3768 is defined }}", - }, - }, - { - "name": "vg_garp_interval", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \sgarp - \sinterval - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} garp interval {{garp_int}}", - "compval": "interval", - "result": { - "group": "{{ group }}", - "garp": { - "interval": "{{ garp_int}}", - }, - }, - }, - { - "name": "vg_garp_master_delay", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \sgarp - \smaster-delay - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} garp master-delay {{garp_mdelay}}", - "compval": "master_delay", - "result": { - "group": "{{ group }}", - "garp": { - "master_delay": "{{ garp_mdelay }}", - }, - }, - }, - { - "name": "vg_garp_master_refresh", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \sgarp - \smaster-refresh - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} garp master-refresh {{garp_mrefresh}}", - "compval": "master_refresh", - "result": { - "group": "{{ group }}", - "garp": { - "master_refresh": "{{ garp_mrefresh }}", - }, - }, - }, - { - "name": "vg_garp_master_refresh_repeat", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \sgarp - \smaster-refresh-repeat - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} garp master-refresh-repeat {{garp_mrefresh_repeat}}", - "compval": "master_refresh_repeat", - "result": { - "group": "{{ group }}", - "garp": { - "master_refresh_repeat": "{{ garp_mrefresh_repeat }}", - }, - }, - }, - { - "name": "vg_garp_master_repeat", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sgroup - \s(?P\S+) - \sgarp - \smaster-repeat - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp group {{group}} garp master-repeat {{garp_mrepeat}}", - "compval": "master_repeat", - "result": { - "group": "{{ group }}", - "garp": { - "master_repeat": "{{ garp_mrepeat }}", - }, - }, - }, { "name": "virtual_servers", "getval": re.compile( r""" - ^set - \shigh-availability\svirtual-server + ^set\shigh-availability\svirtual-server \s+(?P\S+) - \s*(?P
address\s\S+)* - \s*(?Palgorithm\s\S+)* - \s*(?Pdelay-loop\s\S+)* - \s*(?Pforward-method\s\S+)* - \s*(?Pfwmark\s\S+)* - \s*(?Ppersistence-timeout\s\S+)* - \s*(?Pport\s\S+)* - \s*(?Pprotocol\s\S+)* - $""", + (?:\s+address\s+(?P
\S+))? + (?:\s+algorithm\s+(?P\S+))? + (?:\s+delay-loop\s+(?P\S+))? + (?:\s+forward-method\s+(?P\S+))? + (?:\s+fwmark\s+(?P\S+))? + (?:\s+persistence-timeout\s+(?P\S+))? + (?:\s+port\s+(?P\S+))? + (?:\s+protocol\s+(?P\S+))? + $ + """, re.VERBOSE, ), "setval": _tmplt_vsrvs, - # "compval": "global_parameters.garp.master_refersh_repeat", "result": { "virtual_servers": { "{{ alias }}": { "alias": "{{ alias }}", - "address": "{{ address.split(" ")[1] if address is defined else None }}", - "algorithm": "{{ alg.split(" ")[1] if alo is defined else None }}", - "delay_loop": "{{ delay_loop.split(" ")[1] if delay_loop is defined else None }}", - "forward_method": "{{ fwmet.split(" ")[1] if fwmet is defined else None }}", - "fwmark": "{{ fwmark.split(" ")[1] if fwmark is defined else None }}", - "persistence_timeout": "{{ ptime.split(" ")[1] if ptime is defined else None }}", - "port": "{{ port.split(" ")[1] if port is defined else None }}", - "protocol": "{{ proto.split(" ")[1] if proto is defined else None }}", + "address": "{{ address if address is defined else None }}", + "algorithm": "{{ algorithm if algorithm is defined else None }}", + "delay_loop": "{{ delay_loop if delay_loop is defined else None }}", + "forward_method": "{{ forward_method if forward_method is defined else None }}", + "fwmark": "{{ fwmark if fwmark is defined else None }}", + "persistence_timeout": "{{ persistence_timeout if persistence_timeout is defined else None }}", + "port": "{{ port if port is defined else None }}", + "protocol": "{{ protocol if protocol is defined else None }}", }, }, }, }, { "name": "virtual_servers.real_servers", "getval": re.compile( r""" ^set\shigh-availability\svirtual-server \s+(?P\S+) \sreal-server \s+(?P\S+) (?:\s+port\s+(?P\S+))? (?:\s+health-check\sscript\s+(?P\S+))? (?:\s+connection-timeout\s+(?P\S+))? $ """, re.VERBOSE, ), "setval": _tmplt_vsrvs_rsrv, # "compval": "global_parameters.garp.master_refersh_repeat", "result": { "virtual_servers": { "{{ alias }}": { "alias": "{{ alias }}", "real_servers": { "{{ name }}": { "name": "{{ name }}", "port": "{{ portif port is defined else None }}", "health_check_script": "{{ hcscript f hcscript is defined else None }}", "connection_timeout": "{{ cont if cont is defined else None }}", }, }, }, }, }, }, { "name": "sync_group.member", "getval": re.compile( r""" ^set\shigh-availability\svrrp\ssync-group \s+(?P\S+) \smember \s+(?P\S+) $ """, re.VERBOSE, ), "setval": "set high-availability vrrp sync-group {{sgname}} member {{member}}", "compval": "sync_groups.member", "result": { "sync_groups": { "{{ sgname }}": { "name": "{{ sgname }}", "member": "{{ member }}", }, }, }, }, { "name": "sync_group.health_check", "getval": re.compile( r""" ^set\shigh-availability\svrrp\ssync-group \s+(?P\S+) \shealth-check (?:\s+failure-count\s+(?P\S+)) ?(?:\s+interval\s+(?P\S+)) ?(?:\s+ping\s+(?P\S+)) ?(?:\s+script\s+(?P