diff --git a/plugins/module_utils/network/vyos/rm_templates/vrrp.py b/plugins/module_utils/network/vyos/rm_templates/vrrp.py index f2f00570..d4730e5b 100644 --- a/plugins/module_utils/network/vyos/rm_templates/vrrp.py +++ b/plugins/module_utils/network/vyos/rm_templates/vrrp.py @@ -1,833 +1,752 @@ # -*- 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 + # 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": "vg_gp_version", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sglobal-parameters - \sversion - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp global-parameters version {{version}}", - "compval": "global_parameters.version", - "result": { - "global_parameters": { - "version": "{{ version }}", - }, - }, - }, - { - "name": "gp_startup_delay", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sglobal-parameters - \sstartup-delay - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp global-parameters startup-delay {{startup_delay}}", - "compval": "global_parameters.startup_delay", - "result": { - "global_parameters": { - "startup_delay": "{{ startup_delay }}", - }, - }, - }, - { - "name": "gp_garp_interval", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sglobal-parameters - \sgarp - \sinterval - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp global-parameters garp interval {{interval}}", - "compval": "global_parameters.garp.interval", - "result": { - "global_parameters": { - "garp": { - "interval": "{{ interval }}", - }, - }, - }, - }, - { - "name": "gp_garp_master_delay", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sglobal-parameters - \sgarp - \smaster-delay - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp global-parameters garp master-delay {{master_delay}}", - "compval": "global_parameters.garp.master_delay", - "result": { - "global_parameters": { - "garp": { - "master_delay": "{{ master_delay }}", - }, - }, - }, - }, - { - "name": "gp_garp_master_refresh", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sglobal-parameters - \sgarp - \smaster-refresh - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp global-parameters garp master-refresh {{master_refresh}}", - "compval": "global_parameters.garp.master_refresh", - "result": { - "global_parameters": { - "garp": { - "master_refresh": "{{ master_refresh }}", - }, - }, - }, - }, - { - "name": "gp_garp_master_refresh_repeat", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sglobal-parameters - \sgarp - \smaster-refresh-repeat - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp global-parameters garp master-refresh_repeat {{master_refresh_repeat}}", - "compval": "global_parameters.garp.master_refersh_repeat", - "result": { - "global_parameters": { - "garp": { - "master_refresh_repeat": "{{ master_refresh_repeat }}", - }, - }, - }, - }, - { - "name": "gp_garp_master_repeat", - "getval": re.compile( - r""" - ^set - \shigh-availability - \svrrp - \sglobal-parameters - \sgarp - \smaster-refresh-repeat - \s(?P\S+) - $""", - re.VERBOSE, - ), - "setval": "high-availability vrrp global-parameters garp master-refresh-repeat {{master_refresh_repeat}}", - "compval": "global_parameters.garp.master_refersh_repeat", - "result": { - "global_parameters": { - "garp": { - "master_refresh_repeat": "{{ master_refresh_repeat }}", - }, - }, - }, - }, { "name": "virtual_servers", "getval": re.compile( r""" ^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+)* $""", 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 }}", }, }, }, }, { "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