diff options
Diffstat (limited to 'plugins')
11 files changed, 3703 insertions, 530 deletions
diff --git a/plugins/module_utils/network/vyos/argspec/bgp_global/bgp_global.py b/plugins/module_utils/network/vyos/argspec/bgp_global/bgp_global.py index b647ea91..42fb5abf 100644 --- a/plugins/module_utils/network/vyos/argspec/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/vyos/argspec/bgp_global/bgp_global.py @@ -36,44 +36,17 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "as_number": {"type": "int"}, - "aggregate_address": { - "type": "list", - "elements": "dict", - "options": { - "prefix": {"type": "str"}, - "as_set": {"type": "bool"}, - "summary_only": {"type": "bool"}, - }, - }, - "maximum_paths": { - "type": "list", - "elements": "dict", - "options": {"path": {"type": "str"}, "count": {"type": "int"}}, - }, "neighbor": { "type": "list", "elements": "dict", "options": { "address": {"type": "str"}, "advertisement_interval": {"type": "int"}, - "allowas_in": {"type": "int"}, - "as_override": {"type": "bool"}, - "attribute_unchanged": { - "type": "dict", - "options": { - "as_path": {"type": "bool"}, - "med": {"type": "bool"}, - "next_hop": {"type": "bool"}, - }, - }, "capability": { "type": "dict", "options": { "dynamic": {"type": "bool"}, - "orf": { - "type": "str", - "choices": ["send", "receive"], - }, + "extended_nexthop": {"type": "bool"}, }, }, "default_originate": {"type": "str"}, @@ -84,71 +57,18 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "type": "str", "choices": ["extended", "standard"], }, - "distribute_list": { - "type": "list", - "elements": "dict", - "options": { - "action": { - "type": "str", - "choices": ["export", "import"], - }, - "acl": {"type": "int"}, - }, - }, "ebgp_multihop": {"type": "int"}, - "filter_list": { - "type": "list", - "elements": "dict", - "options": { - "action": { - "type": "str", - "choices": ["export", "import"], - }, - "path_list": {"type": "str"}, - }, - }, "local_as": {"type": "int"}, - "maximum_prefix": {"type": "int"}, - "nexthop_self": {"type": "bool"}, "override_capability": {"type": "bool"}, "passive": {"type": "bool"}, "password": {"type": "str", "no_log": True}, "peer_group_name": {"type": "str"}, "peer_group": {"type": "bool"}, "port": {"type": "int"}, - "prefix_list": { - "type": "list", - "elements": "dict", - "options": { - "action": { - "type": "str", - "choices": ["export", "import"], - }, - "prefix_list": {"type": "str"}, - }, - }, "remote_as": {"type": "int"}, - "remove_private_as": {"type": "bool"}, - "route_map": { - "type": "list", - "elements": "dict", - "options": { - "action": { - "type": "str", - "choices": ["export", "import"], - }, - "route_map": {"type": "str"}, - }, - }, - "route_reflector_client": {"type": "bool"}, - "route_server_client": {"type": "bool"}, + "solo": {"type": "bool"}, "shutdown": {"type": "bool"}, - "soft_reconfiguration": {"type": "bool"}, "strict_capability_match": {"type": "bool"}, - "unsuppress_map": {"type": "str"}, - "update_source": {"type": "str"}, - "weight": {"type": "int"}, - "ttl_security": {"type": "int"}, "timers": { "type": "dict", "options": { @@ -157,33 +77,8 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "keepalive": {"type": "int"}, }, }, - }, - }, - "network": { - "type": "list", - "elements": "dict", - "options": { - "address": {"type": "str"}, - "backdoor": {"type": "bool"}, - "route_map": {"type": "str"}, - }, - }, - "redistribute": { - "type": "list", - "elements": "dict", - "options": { - "protocol": { - "type": "str", - "choices": [ - "connected", - "kernel", - "ospf", - "rip", - "static", - ], - }, - "route_map": {"type": "str"}, - "metric": {"type": "int"}, + "ttl_security": {"type": "int"}, + "update_source": {"type": "str"}, }, }, "timers": { diff --git a/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py b/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py index 1b075adb..0e6bec81 100644 --- a/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py +++ b/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py @@ -33,6 +33,14 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_template Bgp_address_familyTemplate, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family_14 import ( + Bgp_address_familyTemplate14, +) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion + class Bgp_address_family(ResourceModule): """ @@ -49,12 +57,30 @@ class Bgp_address_family(ResourceModule): ) self.parsers = [] + def _validate_template(self): + version = get_os_version(self._module) + if LooseVersion(version) >= LooseVersion("1.4"): + self._tmplt = Bgp_address_familyTemplate14() + else: + self._tmplt = Bgp_address_familyTemplate() + + def parse(self): + """ override parse to check template """ + self._validate_template() + return super().parse() + + def get_parser(self, name): + """get_parsers""" + self._validate_template() + return super().get_parser(name) + def execute_module(self): """Execute the module :rtype: A dictionary :returns: The result from module execution """ + self._validate_template() if self.state not in ["parsed", "gathered"]: self.generate_commands() self.run_commands() @@ -67,7 +93,9 @@ class Bgp_address_family(ResourceModule): wantd = {} haved = {} - if self.want.get("as_number") == self.have.get("as_number") or not self.have: + if (self.want.get("as_number") == self.have.get("as_number") or + not self.have or + LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4")): if self.want: wantd = {self.want["as_number"]: self.want} if self.have: @@ -103,6 +131,9 @@ class Bgp_address_family(ResourceModule): the `want` and `have` data with the `parsers` defined for the Bgp_address_family network resource. """ + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + self._compare_asn(want, have) + self._compare_af(want, have) self._compare_neighbors(want, have) # Do the negation first @@ -268,13 +299,21 @@ class Bgp_address_family(ResourceModule): def _compare_lists(self, want, have, as_number, afi): parsers = [ "aggregate_address", + "network", "network.backdoor", "network.path_limit", "network.route_map", + "redistribute", "redistribute.metric", "redistribute.route_map", "redistribute.table", ] + + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + delete_asn = "" + else: + delete_asn = " " + str(as_number) + for attrib in ["redistribute", "networks", "aggregate_address"]: wdict = want.pop(attrib, {}) hdict = have.pop(attrib, {}) @@ -300,8 +339,8 @@ class Bgp_address_family(ResourceModule): attrib = re.sub("_", "-", attrib) attrib = re.sub("networks", "network", attrib) self.commands.append( - "delete protocols bgp " - + str(as_number) + "delete protocols bgp" + + delete_asn + " " + "address-family " + afi @@ -318,6 +357,19 @@ class Bgp_address_family(ResourceModule): "address_family": {"afi": afi, attrib: entry}, }, ) + # de-duplicate child commands if parent command is present + for val in (self.commands): + for val2 in self.commands: + if val != val2 and val2.startswith(val): + self.commands.remove(val2) + + def _compare_asn(self, want, have): + if want.get("as_number") and not have.get("as_number"): + self.commands.append( + "set protocols bgp " + + "system-as " + + str(want.get("as_number")), + ) def _bgp_af_list_to_dict(self, entry): for name, proc in iteritems(entry): diff --git a/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py b/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py index c4a85020..91a5af12 100644 --- a/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py @@ -17,7 +17,6 @@ is compared to the provided configuration (as dict) and the command set necessary to bring the current configuration to its desired end-state is created. """ -import re from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( @@ -31,6 +30,13 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global import ( Bgp_globalTemplate, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global_14 import ( + Bgp_globalTemplate14, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import ( + LooseVersion, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version class Bgp_global(ResourceModule): @@ -48,12 +54,35 @@ class Bgp_global(ResourceModule): ) self.parsers = [] + def _validate_template(self): + version = get_os_version(self._module) + if LooseVersion(version) >= LooseVersion("1.4"): + self._tmplt = Bgp_globalTemplate14() + else: + self._tmplt = Bgp_globalTemplate() + + def parse(self): + """override parse to check template""" + self._validate_template() + return super().parse() + + def get_parser(self, name): + """get_parsers""" + self._validate_template() + return super().get_parser(name) + def execute_module(self): """Execute the module :rtype: A dictionary :returns: The result from module execution """ + version = get_os_version(self._module) + if LooseVersion(version) >= LooseVersion("1.4"): + self._asn_mod = "" + else: + self._asn_mod = " " + str(self.have.get("as_number")) + self._validate_template() if self.state not in ["parsed", "gathered"]: self.generate_commands() self.run_commands() @@ -66,7 +95,11 @@ class Bgp_global(ResourceModule): wantd = {} haved = {} - if self.want.get("as_number") == self.have.get("as_number") or not self.have: + if ( + self.want.get("as_number") == self.have.get("as_number") + or not self.have + or LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4") + ): if self.want: wantd = {self.want["as_number"]: self.want} if self.have: @@ -105,9 +138,11 @@ class Bgp_global(ResourceModule): the `want` and `have` data with the `parsers` defined for the Bgp_global network resource. """ + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + self._compare_asn(want, have) + parsers = ["maximum_paths", "timers"] self._compare_neighbor(want, have) - self._compare_lists(want, have) self._compare_bgp_params(want, have) for name, entry in iteritems(want): if name != "as_number": @@ -176,12 +211,12 @@ class Bgp_global(ResourceModule): "neighbor.weight", "neighbor.ttl_security", "neighbor.timers", - "network.backdoor", - "network.route_map", ] + wneigh = want.pop("neighbor", {}) hneigh = have.pop("neighbor", {}) self._compare_neigh_lists(wneigh, hneigh) + for name, entry in iteritems(wneigh): for k, v in entry.items(): if k == "address": @@ -207,7 +242,7 @@ class Bgp_global(ResourceModule): self._module.fail_json(msg=msg) else: self.commands.append( - "delete protocols bgp " + str(have["as_number"]) + " neighbor " + name, + "delete protocols bgp" + self._asn_mod + " neighbor " + name, ) continue for k, v in entry.items(): @@ -243,6 +278,7 @@ class Bgp_global(ResourceModule): "bgp_params.routerid", "bgp_params.scan_time", ] + wbgp = want.pop("bgp_params", {}) hbgp = have.pop("bgp_params", {}) for name, entry in iteritems(wbgp): @@ -287,12 +323,12 @@ class Bgp_global(ResourceModule): }, ) if not wbgp and hbgp: - self.commands.append("delete protocols bgp " + str(have["as_number"]) + " parameters") + self.commands.append("delete protocols bgp" + self._asn_mod + " parameters") hbgp = {} for name, entry in iteritems(hbgp): if name == "confederation": self.commands.append( - "delete protocols bgp " + str(have["as_number"]) + " parameters confederation", + "delete protocols bgp" + self._asn_mod + " parameters confederation", ) elif name == "distance": distance_parsers = [ @@ -317,39 +353,6 @@ class Bgp_global(ResourceModule): }, ) - def _compare_lists(self, want, have): - parsers = [ - "network.backdoor", - "network.route_map", - "redistribute.metric", - "redistribute.route_map", - "aggregate_address", - ] - for attrib in ["redistribute", "network", "aggregate_address"]: - wdict = want.pop(attrib, {}) - hdict = have.pop(attrib, {}) - for key, entry in iteritems(wdict): - if entry != hdict.get(key, {}): - self.compare( - parsers=parsers, - want={"as_number": want["as_number"], attrib: entry}, - have=hdict.pop(key, {}), - ) - hdict.pop(key, {}) - # remove remaining items in have for replaced - if not wdict and hdict: - attrib = re.sub("_", "-", attrib) - self.commands.append( - "delete protocols bgp " + str(have["as_number"]) + " " + attrib, - ) - hdict = {} - for key, entry in iteritems(hdict): - self.compare( - parsers=parsers, - want={}, - have={"as_number": have["as_number"], attrib: entry}, - ) - def _compare_neigh_lists(self, want, have): for attrib in [ "distribute_list", @@ -392,16 +395,23 @@ class Bgp_global(ResourceModule): redis_dict.update({entry["protocol"]: entry}) proc["redistribute"] = redis_dict + def _compare_asn(self, want, have): + if want.get("as_number") and not have.get("as_number"): + self.commands.append( + "set protocols bgp " + "system-as" + " " + str(want.get("as_number")), + ) + def _check_af(self, neighbor): af_present = False if self._connection: config_lines = self._get_config(self._connection).splitlines() for line in config_lines: - if "address-family" in line: - af_present = True + if neighbor in line: + if "address-family" in line: + af_present = True return af_present def _get_config(self, connection): return connection.get( - 'show configuration commands | match "set protocols bgp .* neighbor"', + 'show configuration commands | match "set protocols bgp .*neighbor"', ) diff --git a/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py b/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py index 629ffc50..3386bd66 100644 --- a/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py +++ b/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py @@ -25,6 +25,13 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family import ( Bgp_address_familyTemplate, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family_14 import ( + Bgp_address_familyTemplate14, +) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion class Bgp_address_familyFacts(object): @@ -55,11 +62,14 @@ class Bgp_address_familyFacts(object): data = self.get_device_data(connection) for resource in data.splitlines(): - if "address-family" in resource: + if "address-family" in resource or "system-as" in resource: config_lines.append(re.sub("'", "", resource)) - # parse native config using the Bgp_address_family template - bgp_address_family_parser = Bgp_address_familyTemplate(lines=config_lines) + # parse native config using the Bgp_address_family template based on version + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + bgp_address_family_parser = Bgp_address_familyTemplate14(lines=config_lines) + else: + bgp_address_family_parser = Bgp_address_familyTemplate(lines=config_lines) objs = bgp_address_family_parser.parse() if objs: if "address_family" in objs: diff --git a/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py b/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py index fe341357..dd793681 100644 --- a/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py @@ -26,6 +26,14 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_template Bgp_globalTemplate, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global_14 import ( + Bgp_globalTemplate14, +) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion + class Bgp_globalFacts(object): """The vyos bgp_global facts class""" @@ -58,7 +66,11 @@ class Bgp_globalFacts(object): if "address-family" not in resource: config_lines.append(re.sub("'", "", resource)) - bgp_global_parser = Bgp_globalTemplate(lines=config_lines, module=self._module) + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + bgp_global_parser = Bgp_globalTemplate14(lines=config_lines, module=self._module) + else: + bgp_global_parser = Bgp_globalTemplate(lines=config_lines, module=self._module) + objs = bgp_global_parser.parse() if "neighbor" in objs: diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py index c996a74a..f8f86cd2 100644 --- a/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py +++ b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py @@ -37,44 +37,31 @@ def _tmplt_bgp_af_aggregate_address(config_data): return command -def _tmplt_bgp_af_redistribute_metric(config_data): - if config_data["address_family"]["redistribute"].get("metric"): - afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format(**config_data) - if config_data["address_family"]["redistribute"].get("metric"): - command += afi + " redistribute {protocol} metric {metric}".format( - **config_data["address_family"]["redistribute"], - ) - return command - - -def _tmplt_bgp_af_redistribute_route_map(config_data): - if config_data["address_family"]["redistribute"].get("route_map"): - afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format(**config_data) - if config_data["address_family"]["redistribute"].get("route_map"): - command += afi + " redistribute {protocol} route-map {route_map}".format( - **config_data["address_family"]["redistribute"], - ) - return command - - -def _tmplt_bgp_af_redistribute_table(config_data): - if config_data["address_family"]["redistribute"].get("table"): - afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format(**config_data) - if config_data["address_family"]["redistribute"].get("table"): - command += afi + " table {table}".format( - **config_data["address_family"]["redistribute"], - ) - return command +def _tmplt_bgp_af_redistribute(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp {as_number} address-family ".format(**config_data) + config_data = config_data["address_family"]["redistribute"] + command += afi + " redistribute {protocol}".format(**config_data) + if config_data.get("metric"): + command += " metric {metric}".format(**config_data) + elif config_data.get("route_map"): + command += " route-map {route_map}".format(**config_data) + elif config_data.get("table"): + command += " table {table}".format(**config_data) + return command -def _tmplt_bgp_af_delete_redistribute(config_data): +def _tmplt_bgp_af_redistribute_delete(config_data): afi = config_data["address_family"]["afi"] + "-unicast" command = "protocols bgp {as_number} address-family ".format(**config_data) - config_data = config_data["address_family"] - command += afi + " redistribute {protocol}".format(**config_data["redistribute"]) + config_data = config_data["address_family"]["redistribute"] + command += afi + " redistribute {protocol}".format(**config_data) + if config_data.get("metric"): + command += " metric" + elif config_data.get("route_map"): + command += " route-map" + elif config_data.get("table"): + command += " table" return command @@ -234,6 +221,30 @@ def _tmplt_bgp_af_neighbor(config_data): return command +def _tmplt_bgp_af_network(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp {as_number} address-family ".format(**config_data) + config_data = config_data["address_family"]["networks"] + command += afi + " network {prefix}".format(**config_data) + if config_data.get("backdoor"): + command += " backdoor" + elif config_data.get("route_map"): + command += " route-map {route_map}".format(**config_data) + return command + + +def _tmplt_bgp_af_network_delete(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp {as_number} address-family ".format(**config_data) + config_data = config_data["address_family"]["networks"] + command += afi + " network {prefix}".format(**config_data) + if config_data.get("backdoor"): + command += " backdoor" + elif config_data.get("route_map"): + command += " route_map" + return command + + class Bgp_address_familyTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): prefix = {"set": "set", "remove": "delete"} @@ -308,6 +319,38 @@ class Bgp_address_familyTemplate(NetworkTemplate): }, }, { + "name": "network", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+(?P<as_num>\d+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+network + \s+(?P<address>\S+) + $""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_network, + "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }}", + "compval": "address_family.networks.prefix", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "networks": [ + { + "prefix": "{{ address }}", + }, + ], + }, + }, + }, + }, + { "name": "network.backdoor", "getval": re.compile( r""" @@ -323,8 +366,8 @@ class Bgp_address_familyTemplate(NetworkTemplate): *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }} backdoor", - "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }}", + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, "compval": "address_family.networks.backdoor", "result": { "as_number": "{{ as_num }}", @@ -358,9 +401,8 @@ class Bgp_address_familyTemplate(NetworkTemplate): *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network" + - "{{ address_family.networks.prefix }} path-limit {{ address_family.networks.path_limit }}", - "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.address }}", + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, "compval": "address_family.networks.path_limit", "result": { "as_number": "{{ as_num }}", @@ -394,9 +436,8 @@ class Bgp_address_familyTemplate(NetworkTemplate): *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network" + - " {{ address_family.networks.prefix }} route-map {{ address_family.networks.route_map }}", - "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }}", + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, "compval": "address_family.networks.route_map", "result": { "as_number": "{{ as_num }}", @@ -414,6 +455,38 @@ class Bgp_address_familyTemplate(NetworkTemplate): }, }, { + "name": "redistribute", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+(?P<as_num>\d+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+redistribute + \s+(?P<proto>\S+) + $""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_redistribute, + "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast redistribute {{ address_family.redistribute.protocol }}", + "compval": "address_family.redistribute.protocol", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "redistribute": [ + { + "protocol": "{{ proto }}", + }, + ], + }, + }, + }, + }, + { "name": "redistribute.metric", "getval": re.compile( r""" @@ -430,8 +503,8 @@ class Bgp_address_familyTemplate(NetworkTemplate): *$""", re.VERBOSE, ), - "setval": _tmplt_bgp_af_redistribute_metric, - "remval": _tmplt_bgp_af_delete_redistribute, + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, "compval": "address_family.redistribute.metric", "result": { "as_number": "{{ as_num }}", @@ -465,8 +538,8 @@ class Bgp_address_familyTemplate(NetworkTemplate): *$""", re.VERBOSE, ), - "setval": _tmplt_bgp_af_redistribute_route_map, - "remval": _tmplt_bgp_af_delete_redistribute, + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, "compval": "address_family.redistribute.route_map", "result": { "as_number": "{{ as_num }}", @@ -499,8 +572,8 @@ class Bgp_address_familyTemplate(NetworkTemplate): *$""", re.VERBOSE, ), - "setval": _tmplt_bgp_af_redistribute_table, - "remval": _tmplt_bgp_af_delete_redistribute, + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, "compval": "address_family.redistribute.table", "result": { "as_number": "{{ as_num }}", diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_address_family_14.py b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family_14.py new file mode 100644 index 00000000..fd4c9de9 --- /dev/null +++ b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family_14.py @@ -0,0 +1,1433 @@ +# -*- 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_address_family 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, +) + + +def _tmplt_bgp_af_aggregate_address(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp address-family ".format(**config_data) + config_data = config_data["address_family"] + if config_data["aggregate_address"].get("as_set"): + command += afi + " aggregate-address {prefix} as-set".format( + **config_data["aggregate_address"], + ) + if config_data["aggregate_address"].get("summary_only"): + command += afi + " aggregate-address {prefix} summary-only".format( + **config_data["aggregate_address"], + ) + return command + + +def _tmplt_bgp_af_redistribute(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp address-family ".format(**config_data) + config_data = config_data["address_family"]["redistribute"] + command += afi + " redistribute {protocol}".format(**config_data) + if config_data.get("metric"): + command += " metric {metric}".format(**config_data) + elif config_data.get("route_map"): + command += " route-map {route_map}".format(**config_data) + elif config_data.get("table"): + command += " table {table}".format(**config_data) + return command + + +def _tmplt_bgp_af_redistribute_delete(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp address-family ".format(**config_data) + config_data = config_data["address_family"]["redistribute"] + command += afi + " redistribute {protocol}".format(**config_data) + if config_data.get("metric"): + command += " metric" + elif config_data.get("route_map"): + command += " route-map" + elif config_data.get("table"): + command += " table" + return command + + +def _tmplt_bgp_af_neighbor_distribute_list(config_data): + command = [] + afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" + cmd = "protocols bgp neighbor ".format(**config_data) + cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) + config_data = config_data["neighbors"]["address_family"] + for list_el in config_data["distribute_list"]: + command.append( + cmd + afi + " distribute-list " + list_el["action"] + " " + str(list_el["acl"]), + ) + return command + + +def _tmplt_bgp_af_neighbor_route_map(config_data): + command = [] + afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" + cmd = "protocols bgp neighbor ".format(**config_data) + cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) + config_data = config_data["neighbors"]["address_family"] + for list_el in config_data["route_map"]: + command.append( + cmd + afi + " route-map " + list_el["action"] + " " + str(list_el["route_map"]), + ) + return command + + +def _tmplt_bgp_af_neighbor_prefix_list(config_data): + command = [] + afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" + cmd = "protocols bgp neighbor ".format(**config_data) + cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) + config_data = config_data["neighbors"]["address_family"] + for list_el in config_data["prefix_list"]: + command.append( + cmd + afi + " prefix-list " + list_el["action"] + " " + str(list_el["prefix_list"]), + ) + return command + + +def _tmplt_bgp_af_neighbor_filter_list(config_data): + command = [] + afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" + cmd = "protocols bgp neighbor ".format(**config_data) + cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) + config_data = config_data["neighbors"]["address_family"] + for list_el in config_data["filter_list"]: + command.append( + cmd + afi + " filter-list " + list_el["action"] + " " + str(list_el["path_list"]), + ) + return command + + +def _tmplt_bgp_af_neighbor_attribute(config_data): + command = [] + afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" + cmd = "protocols bgp neighbor ".format(**config_data) + cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) + config_data = config_data["neighbors"]["address_family"] + for k in config_data["attribute_unchanged"].keys(): + if config_data["attribute_unchanged"][k]: + k = re.sub("_", "-", k) + c = cmd + afi + " attribute-unchanged " + k + command.append(c) + return command + + +def _tmplt_bgp_af_neighbor_delete(config_data): + afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" + command = "protocols bgp ".format(**config_data) + command += ( + "neighbor {neighbor_address} address-family ".format(**config_data["neighbors"]) + afi + ) + config_data = config_data["neighbors"]["address_family"] + if config_data.get("allowas_in"): + command += " allowas-in" + elif config_data.get("as_override"): + command += " as-override" + elif config_data.get("attribute_unchanged"): + command += " attribute-unchanged" + elif config_data.get("capability"): + command += " capability" + elif config_data.get("default_originate"): + command += " default-originate" + elif config_data.get("maximum_prefix"): + command += " maximum-prefix" + elif config_data.get("nexthop_local"): + command += " nexthop-local" + elif config_data.get("nexthop_self"): + command += " nexthop-self" + elif config_data.get("peer_group"): + command += " peer-group" + elif config_data.get("remote_private_as"): + command += " remote-private-as" + elif config_data.get("route_reflector_client"): + command += " route-reflector-client" + elif config_data.get("route_server_client"): + command += " route-server-client" + elif config_data.get("soft_reconfiguration"): + command += " soft-reconfiguration" + elif config_data.get("unsuppress_map"): + command += " unsuppress-map" + elif config_data.get("weight"): + command += " weight" + elif config_data.get("filter_list"): + command += " filter-list" + elif config_data.get("prefix_list"): + command += " prefix-list" + elif config_data.get("distribute_list"): + command += " distribute-list" + elif config_data.get("route_map"): + command += " route-map" + return command + + +def _tmplt_bgp_af_neighbor(config_data): + afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" + command = "protocols bgp ".format(**config_data) + command += ( + "neighbor {neighbor_address} address-family ".format(**config_data["neighbors"]) + afi + ) + config_data = config_data["neighbors"]["address_family"] + if config_data.get("allowas_in"): + command += " allowas-in number {allowas_in}".format(**config_data) + elif config_data.get("as_override"): + command += " as-override" + elif config_data.get("capability"): + command += " capability " + if config_data["capability"].get("dynamic"): + command += "dynamic" + elif config_data["capability"].get("orf"): + command += " prefix-list {orf}".format(**config_data["capability"]) + elif config_data.get("default_originate"): + command += " default-originate route-map {default_originate}".format(**config_data) + elif config_data.get("maximum_prefix"): + command += " maximum-prefix {maximum_prefix}".format(**config_data) + elif config_data.get("nexthop_local"): + command += " nexthop-local" + elif config_data.get("nexthop_self"): + command += " nexthop-self" + elif config_data.get("peer_group"): + command += " peer-group {peer_group}".format(**config_data) + elif config_data.get("remote_private_as"): + command += " remote-private-as" + elif config_data.get("route_reflector_client"): + command += " route-reflector-client" + elif config_data.get("route_server_client"): + command += " route-server-client" + elif config_data.get("soft_reconfiguration"): + command += " soft-reconfiguration inbound" + elif config_data.get("unsuppress_map"): + command += " unsuppress-map {unsuppress_map}".format(**config_data) + elif config_data.get("weight"): + command += " weight {weight}".format(**config_data) + return command + + +def _tmplt_bgp_af_network(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp address-family ".format(**config_data) + config_data = config_data["address_family"]["networks"] + command += afi + " network {prefix}".format(**config_data) + if config_data.get("backdoor"): + command += " backdoor" + elif config_data.get("route_map"): + command += " route-map {route_map}".format(**config_data) + return command + + +def _tmplt_bgp_af_network_delete(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp address-family ".format(**config_data) + config_data = config_data["address_family"]["networks"] + command += afi + " network {prefix}".format(**config_data) + if config_data.get("backdoor"): + command += " backdoor" + elif config_data.get("route_map"): + command += " route_map" + return command + + +class Bgp_address_familyTemplate14(NetworkTemplate): + def __init__(self, lines=None, module=None): + prefix = {"set": "set", "remove": "delete"} + super(Bgp_address_familyTemplate14, self).__init__( + lines=lines, + tmplt=self, + prefix=prefix, + module=module, + ) + + # fmt: off + PARSERS = [ + { + "name": "system_as", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+system-as + \s+(?P<as_num>\d+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp system-as {{ as_number }}", + "compval": "as_number", + "result": { + "as_number": "{{ as_num }}", + }, + }, + { + "name": "address_family", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P<afi>\S+)-unicast + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp address-family {{ address_family.afi }}-unicast", + "compval": "as_number", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + }, + }, + }, + }, + { + "name": "aggregate_address", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+aggregate-address + \s+(?P<address>\S+) + \s*(?P<as_set>as-set)* + \s*(?P<summary_only>summary-only)* + $""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_aggregate_address, + "remval": "protocols bgp address-family {{ address_family.afi }}-unicast aggregate-address" + + " {{ address_family.aggregate_address.prefix }}", + "compval": "address_family.aggregate_address", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "aggregate_address": [ + { + "prefix": "{{ address }}", + "as_set": "{{ True if as_set is defined }}", + "summary_only": "{{ True if summary_only is defined }}", + }, + ], + }, + }, + }, + }, + { + "name": "network", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+network + \s+(?P<address>\S+) + $""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_network, + "remval": "protocols bgp address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }}", + "compval": "address_family.networks.prefix", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "networks": [ + { + "prefix": "{{ address }}", + }, + ], + }, + }, + }, + }, + { + "name": "network.backdoor", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+network + \s+(?P<address>\S+) + \s+backdoor + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, + "compval": "address_family.networks.backdoor", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "networks": [ + { + "prefix": "{{ address }}", + "backdoor": "{{ True }}", + }, + ], + }, + }, + }, + }, + { + "name": "network.path_limit", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+network + \s+(?P<address>\S+) + \s+path-limit + \s+(?P<limit>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, + "compval": "address_family.networks.path_limit", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "networks": [ + { + "prefix": "{{ address }}", + "path_limit": "{{ limit|int }}", + }, + ], + }, + }, + }, + }, + { + "name": "network.route_map", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+network + \s+(?P<address>\S+) + \s+route-map + \s+(?P<map>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, + "compval": "address_family.networks.route_map", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "networks": [ + { + "prefix": "{{ address }}", + "route_map": "{{ map }}", + }, + ], + }, + }, + }, + }, + { + "name": "redistribute", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+redistribute + \s+(?P<proto>\S+) + $""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_redistribute, + "remval": "protocols bgp address-family {{ address_family.afi }}-unicast redistribute {{ address_family.redistribute.protocol }}", + "compval": "address_family.redistribute.protocol", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "redistribute": [ + { + "protocol": "{{ proto }}", + }, + ], + }, + }, + }, + }, + { + "name": "redistribute.metric", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+redistribute + \s+(?P<proto>\S+) + \s+metric\s+(?P<val>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, + "compval": "address_family.redistribute.metric", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "redistribute": [ + { + "protocol": "{{ proto }}", + "metric": "{{ val }}", + }, + ], + }, + }, + }, + }, + { + "name": "redistribute.route_map", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+redistribute + \s+(?P<proto>\S+) + \s+route-map + \s+(?P<map>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, + "compval": "address_family.redistribute.route_map", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "redistribute": [ + { + "protocol": "{{ proto }}", + "route_map": "{{ map }}", + }, + ], + }, + }, + }, + }, + { + "name": "redistribute.table", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+redistribute + \s+table + \s+(?P<tab>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, + "compval": "address_family.redistribute.table", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "redistribute": [ + { + "table": "{{ tab }}", + }, + ], + }, + }, + }, + }, + { + "name": "neighbors", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbors.neighbor_address }} address-family", + "compval": "neighbors", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + }, + }, + }, + }, + { + "name": "neighbors.address_family", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbors.neighbor_address }} address-family {{ neighbors.address_family.afi }}-unicast", + "compval": "neighbors", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.allowas_in", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+allowas-in + \s+number + \s+(?P<num>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.allowas_in", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "allowas_in": "{{ num }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.as_override", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+as-override + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.as_override", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "as_override": "{{ True }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.attribute_unchanged.as_path", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+attribute-unchanged + \s+(?P<val>as-path) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor_attribute, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.attribute_unchanged.as_path", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "attribute_unchanged": { + "as_path": "{{ True }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.attribute_unchanged.med", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+attribute-unchanged + \s+(?P<val>med) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor_attribute, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.attribute_unchanged.med", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "attribute_unchanged": { + "med": "{{ True }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.attribute_unchanged.next_hop", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+attribute-unchanged + \s+(?P<val>next-hop) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor_attribute, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.attribute_unchanged.next_hop", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "attribute_unchanged": { + "next_hop": "{{ True }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.capability_dynamic", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+capability + \s+dynamic + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.capability.dynamic", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "capability": { + "dynamic": "{{ true }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.capability_orf", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+capability + \s+prefix-list + \s+(?P<orf>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.capability.orf", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "capability": { + "orf": "{{ orf }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.default_originate", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+default-originate + \s+route-map + \s+(?P<map>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.default_originate", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "default_originate": "{{ map }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.distribute_list", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+distribute-list + \s+(?P<action>export|import) + \s+(?P<list>\d+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor_distribute_list, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.distribute_list", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "distribute_list": [ + { + "action": "{{ action }}", + "acl": "{{ list }}", + }, + ], + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.prefix_list", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+prefix-list + \s+(?P<action>export|import) + \s+(?P<list>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor_prefix_list, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.prefix_list", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "prefix_list": [ + { + "action": "{{ action }}", + "prefix_list": "{{ list }}", + }, + ], + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.filter_list", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+filter-list + \s+(?P<action>export|import) + \s+(?P<list>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor_filter_list, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.filter_list", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "filter_list": [ + { + "action": "{{ action }}", + "path_list": "{{ list }}", + }, + ], + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.maximum_prefix", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+maximum-prefix + \s+(?P<num>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.maximum_prefix", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "maximum_prefix": "{{ num }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.nexthop_local", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+nexthop-local + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.nexthop_local", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "nexthop_local": "{{ True }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.nexthop_self", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+nexthop-self + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.nexthop_self", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "nexthop_self": "{{ True }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.peer_group", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+peer-group + \s+(?P<name>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.peer_group", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "peer_group": "{{ name }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.remove_private_as", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+remove-private-as + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.remove_private_as", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "remove_private_as": "{{ True }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.route_map", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+route-map + \s+(?P<action>export|import) + \s+(?P<map>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor_route_map, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.route_map", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "route_map": [ + { + "action": "{{ action }}", + "route_map": "{{ map }}", + }, + ], + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.route_reflector_client", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+route-reflector-client + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.route_reflector_client", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "route_reflector_client": "{{ True }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.route_server_client", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+route-server-client + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.route_server_client", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "route_server_client": "{{ True }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.soft_reconfiguration", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+soft-reconfiguration + \s+inbound + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.soft_reconfiguration", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "soft_reconfiguration": "{{ True }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.unsuppress_map", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+unsuppress-map + \s+(?P<map>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.unsuppress_map", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "unsuppress_map": "{{ map }}", + }, + }, + }, + }, + }, + }, + { + "name": "neighbors.weight", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+address-family + \s+(?P<afi>\S+)-unicast + \s+weight + \s+(?P<num>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_neighbor, + "remval": _tmplt_bgp_af_neighbor_delete, + "compval": "neighbors.address_family.weight", + "result": { + "as_number": "{{ as_num }}", + "neighbors": { + "{{ address }}": { + "neighbor_address": "{{ address }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "weight": "{{ num }}", + }, + }, + }, + }, + }, + }, + ] + # fmt: on diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_global.py b/plugins/module_utils/network/vyos/rm_templates/bgp_global.py index bd95e082..621f65ea 100644 --- a/plugins/module_utils/network/vyos/rm_templates/bgp_global.py +++ b/plugins/module_utils/network/vyos/rm_templates/bgp_global.py @@ -49,15 +49,6 @@ def _tmplt_bgp_maximum_paths(config_data): return command -def _tmplt_bgp_aggregate_address(config_data): - command = "protocols bgp {as_number} aggregate-address".format(**config_data) - if config_data["aggregate_address"].get("as_set"): - command += " {prefix} as-set".format(**config_data["aggregate_address"]) - if config_data["aggregate_address"].get("summary_only"): - command += " {prefix} summary-only".format(**config_data["aggregate_address"]) - return command - - def _tmplt_delete_bgp_maximum_paths(config_data): command = "protocols bgp {as_number} maximum-paths".format(**config_data) return command @@ -72,14 +63,6 @@ def _tmplt_bgp_params_default(config_data): return command -def _tmplt_bgp_delete_redistribute(config_data): - command = ( - "protocols bgp {as_number} redistribute ".format(**config_data) - + config_data["redistribute"]["protocol"] - ) - return command - - def _tmplt_bgp_neighbor_timers(config_data): command = [] for k, v in iteritems(config_data["neighbor"]["timers"]): @@ -218,35 +201,6 @@ class Bgp_globalTemplate(NetworkTemplate): }, }, { - "name": "aggregate_address", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P<as_num>\d+) - \s+aggregate-address - \s+(?P<address>\S+) - \s*(?P<as_set>as-set)* - \s*(?P<summary_only>summary-only)* - $""", - re.VERBOSE, - ), - "setval": _tmplt_bgp_aggregate_address, - "remval": "protocols bgp {{ as_number }} aggregate-address {{ aggregate_address.prefix }}", - "compval": "aggregate_address", - "result": { - "as_number": "{{ as_num }}", - "aggregate_address": [ - { - "prefix": "{{ address }}", - "as_set": "{{ True if as_set is defined }}", - "summary_only": "{{ True if summary_only is defined }}", - }, - ], - }, - }, - { "name": "maximum_paths", "getval": re.compile( r""" @@ -850,7 +804,7 @@ class Bgp_globalTemplate(NetworkTemplate): *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} nexthop-self", + "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} passive", "compval": "neighbor.passive", "result": { "as_number": "{{ as_num }}", @@ -1333,117 +1287,6 @@ class Bgp_globalTemplate(NetworkTemplate): }, }, { - "name": "network.backdoor", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P<as_num>\d+) - \s+network - \s+(?P<address>\S+) - \s+backdoor - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} network {{ network.address }} backdoor", - "remval": "protocols bgp {{ as_number }} network {{ network.address }}", - "compval": "network.backdoor", - "result": { - "as_number": "{{ as_num }}", - "network": [ - { - "address": "{{ address }}", - "backdoor": "{{ True }}", - }, - ], - }, - }, - { - "name": "network.route_map", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P<as_num>\d+) - \s+network - \s+(?P<address>\S+) - \s+route-map - \s+(?P<map>\S+) - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} network {{ network.address }} route-map {{ network.route_map }}", - "remval": "protocols bgp {{ as_number }} network {{ network.address }}", - "compval": "network.route_map", - "result": { - "as_number": "{{ as_num }}", - "network": [ - { - "address": "{{ address }}", - "route_map": "{{ map }}", - }, - ], - }, - }, - { - "name": "redistribute.metric", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P<as_num>\d+) - \s+redistribute - \s+(?P<proto>\S+) - \s+metric - \s+(?P<val>\S+) - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} redistribute {{ redistribute.protocol }} metric {{ redistribute.metric }}", - "remval": _tmplt_bgp_delete_redistribute, - "compval": "redistribute", - "result": { - "as_number": "{{ as_num }}", - "redistribute": [ - { - "protocol": "{{ proto }}", - "metric": "{{ val|int }}", - }, - ], - }, - }, - { - "name": "redistribute.route_map", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P<as_num>\d+) - \s+redistribute - \s+(?P<proto>\S+) - \s+route-map - \s+(?P<val>\S+) - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} redistribute {{ redistribute.protocol }} route-map {{ redistribute.route_map }}", - "remval": _tmplt_bgp_delete_redistribute, - "compval": "redistribute", - "result": { - "as_number": "{{ as_num }}", - "redistribute": [ - { - "protocol": "{{ proto }}", - "route_map": "{{ val }}", - }, - ], - }, - }, - { "name": "timers", "getval": re.compile( r""" diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_global_14.py b/plugins/module_utils/network/vyos/rm_templates/bgp_global_14.py new file mode 100644 index 00000000..b8beb923 --- /dev/null +++ b/plugins/module_utils/network/vyos/rm_templates/bgp_global_14.py @@ -0,0 +1,1799 @@ +# -*- 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, +) + + +def _tmplt_bgp_params_confederation(config_data): + command = [] + for list_el in config_data["bgp_params"]["confederation"]: + for k, v in iteritems(list_el): + command.append( + "protocols bgp parameters confederation ".format(**config_data) + + k + + " " + + str(v), + ) + + return command + + +def _tmplt_bgp_maximum_paths(config_data): + command = [] + for list_el in config_data["maximum_paths"]: + command.append( + "protocols bgp maximum-paths ".format(**config_data) + + list_el["path"] + + " " + + str(list_el["count"]), + ) + return command + + +def _tmplt_delete_bgp_maximum_paths(config_data): + command = "protocols bgp maximum-paths".format(**config_data) + return command + + +def _tmplt_bgp_params_default(config_data): + command = "protocols bgp parameters default".format(**config_data) + if config_data["bgp_params"]["default"].get("no_ipv4_unicast"): + command += " no-ipv4-unicast" + if config_data["bgp_params"]["default"].get("local_pref"): + command += " local-pref {local_pref}".format(**config_data["bgp_params"]["default"]) + return command + + +def _tmplt_bgp_neighbor_timers(config_data): + command = [] + for k, v in iteritems(config_data["neighbor"]["timers"]): + command.append( + "protocols bgp neighbor ".format(**config_data) + + config_data["neighbor"]["address"] + + " timers " + + k + + " " + + str(v), + ) + + return command + + +def _tmplt_bgp_timers(config_data): + command = [] + for k, v in iteritems(config_data["timers"]): + command.append( + "protocols bgp ".format(**config_data) + "timers " + k + " " + str(v), + ) + + return command + + +def _tmplt_bgp_neighbor_attribute_unchanged_as_path(config_data): + command = "protocols bgp ".format( + **config_data, + ) + "neighbor {address} attribute-unchanged as-path".format(**config_data["neighbor"]) + return command + + +def _tmplt_bgp_neighbor_attribute_unchanged_med(config_data): + command = "protocols bgp ".format( + **config_data, + ) + "neighbor {address} attribute-unchanged med".format(**config_data["neighbor"]) + return command + + +def _tmplt_bgp_neighbor_attribute_unchanged_next_hop(config_data): + command = "protocols bgp ".format( + **config_data, + ) + "neighbor {address} attribute-unchanged next-hop".format(**config_data["neighbor"]) + return command + + +def _tmplt_bgp_neighbor_distribute_list(config_data): + command = [] + for list_el in config_data["neighbor"]["distribute_list"]: + command.append( + "protocols bgp ".format(**config_data) + + "neighbor {address} distribute-list ".format(**config_data["neighbor"]) + + list_el["action"] + + " " + + str(list_el["acl"]), + ) + return command + + +def _tmplt_bgp_neighbor_route_map(config_data): + command = [] + for list_el in config_data["neighbor"]["route_map"]: + command.append( + "protocols bgp ".format(**config_data) + + "neighbor {address} route-map ".format(**config_data["neighbor"]) + + list_el["action"] + + " " + + str(list_el["route_map"]), + ) + return command + + +def _tmplt_bgp_neighbor_prefix_list(config_data): + command = [] + for list_el in config_data["neighbor"]["prefix_list"]: + command.append( + "protocols bgp ".format(**config_data) + + "neighbor {address} prefix-list ".format(**config_data["neighbor"]) + + list_el["action"] + + " " + + str(list_el["prefix_list"]), + ) + return command + + +def _tmplt_bgp_neighbor_filter_list(config_data): + command = [] + for list_el in config_data["neighbor"]["filter_list"]: + command.append( + "protocols bgp ".format(**config_data) + + "neighbor {address} filter-list ".format(**config_data["neighbor"]) + + list_el["action"] + + " " + + str(list_el["path_list"]), + ) + return command + + +def _tmplt_bgp_params_distance(config_data): + command = ( + "protocols bgp parameters distance global ".format(**config_data) + + config_data["bgp_params"]["distance"]["type"] + + " " + + str(config_data["bgp_params"]["distance"]["value"]) + ) + return command + + +class Bgp_globalTemplate14(NetworkTemplate): + def __init__(self, lines=None, module=None): + prefix = {"set": "set", "remove": "delete"} + super(Bgp_globalTemplate14, self).__init__( + lines=lines, + tmplt=self, + prefix=prefix, + module=module, + ) + + # fmt: off + PARSERS = [ + { + "name": "router", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s*system-as + \s+(?P<as_num>\d+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp system-as {{ as_number }}", + "remval": "protocols bgp", + "compval": "as_number", + "result": { + "as_number": "{{ as_num }}", + }, + }, + { + "name": "maximum_paths", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+maximum-paths + \s+(?P<path>ebgp|ibgp) + \s+(?P<count>\d+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_maximum_paths, + "remval": _tmplt_delete_bgp_maximum_paths, + "compval": "maximum_paths", + "result": { + "as_number": "{{ as_num }}", + "maximum_paths": [ + { + "path": "{{ path }}", + "count": "{{ count }}", + }, + ], + }, + }, + { + "name": "neighbor.advertisement_interval", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+advertisement-interval + \s+(?P<interval>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} advertisement-interval {{ neighbor.advertisement_interval }}", + "remval": "protocols bgp neighbor {{ neighbor.address }} advertisement-interval", + "compval": "neighbor.advertisement_interval", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "advertisement_interval": "{{ interval }}", + }, + }, + }, + }, + { + "name": "neighbor.allowas_in", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+allowas-in + \s+number + \s+(?P<num>\'\d+\') + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} allowas-in number {{ neighbor.allowas_in }}", + "compval": "neighbor.allowas_in", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "allowas_in": "{{ count }}", + }, + }, + }, + }, + { + "name": "neighbor.as_override", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+as-override + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} as-override", + "compval": "neighbor.as_override", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "as_override": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.attribute_unchanged.as_path", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+attribute-unchanged + \s+(?P<val>as-path) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_neighbor_attribute_unchanged_as_path, + "compval": "neighbor.attribute_unchanged", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "attribute_unchanged": { + "{{ 'as_path' }}": "{{ True }}", + }, + }, + }, + }, + }, + { + "name": "neighbor.attribute_unchanged.med", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+attribute-unchanged + \s+(?P<val>med) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_neighbor_attribute_unchanged_med, + "compval": "neighbor.attribute_unchanged", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "attribute_unchanged": { + "{{ 'med' }}": "{{ True }}", + }, + }, + }, + }, + }, + { + "name": "neighbor.attribute_unchanged.next_hop", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+attribute-unchanged + \s+(?P<val>next-hop) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_neighbor_attribute_unchanged_next_hop, + "compval": "neighbor.attribute_unchanged", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "attribute_unchanged": { + "{{ 'next_hop' }}": "{{ True }}", + }, + }, + }, + }, + }, + { + "name": "neighbor.capability_dynamic", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+capability + \s+(?P<dynamic>dynamic) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} capability dynamic", + "compval": "neighbor.capability.dynamic", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "capability": { + "dynamic": "{{ True if dynamic is defined}}", + }, + }, + }, + }, + }, + { + "name": "neighbor.capability_orf", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+capability + \s+orf + \s+prefix-list + \s+(?P<orf>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} capability orf prefix-list {{ neighbor.capability.orf }}", + "compval": "neighbor.capability.orf", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "capability": { + "orf": "{{ orf }}", + }, + }, + }, + }, + }, + { + "name": "neighbor.default_originate", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+default-originate + \s+route-map + \s+(?P<map>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} default-originate route-map {{ neighbor.default_originate }}", + "compval": "neighbor.advertisement_interval", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "default_originate": "{{ map }}", + }, + }, + }, + }, + { + "name": "neighbor.description", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+description + \s+(?P<desc>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} description {{ neighbor.description }}", + "compval": "neighbor.description", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "description": "{{ desc }}", + }, + }, + }, + }, + { + "name": "neighbor.disable_capability_negotiation", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+disable-capability-negotiation + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} disable-capability-negotiation", + "compval": "neighbor.disable_capability_negotiation", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "disable_capability_negotiation": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.disable_connected_check", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+disable-connected-check + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} disable-connected-check", + "compval": "neighbor.disable_connected_check", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "disable_connected_check": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.disable_send_community", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+disable-send-community + \s+(?P<comm>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} disable-send-community {{ neighbor.disable_send_community }}", + "compval": "neighbor.disable_send_community", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "disable_send_community": "{{ comm }}", + }, + }, + }, + }, + { + "name": "neighbor.distribute_list", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+distribute-list + \s+(?P<action>export|import) + \s+(?P<list>\d+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_neighbor_distribute_list, + "compval": "neighbor.distribute_list", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "distribute_list": [ + { + "action": "{{ action }}", + "acl": "{{ list }}", + }, + ], + }, + }, + }, + }, + { + "name": "neighbor.ebgp_multihop", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+ebgp-multihop + \s+(?P<hop>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} ebgp-multihop {{ neighbor.ebgp_multihop }}", + "compval": "neighbor.ebgp_multihop", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "ebgp_multihop": "{{ hop|int }}", + }, + }, + }, + }, + { + "name": "neighbor.filter_list", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+filter-list + \s+(?P<action>export|import) + \s+(?P<list>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_neighbor_filter_list, + "compval": "neighbor.filter_list", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "filter_list": [ + { + "action": "{{ action }}", + "path_list": "{{ list }}", + }, + ], + }, + }, + }, + }, + { + "name": "neighbor.local_as", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+local-as + \s+(?P<as>\S+) + \s+no-prepend + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} local-as {{ neighbor.local_as }} no-prepend", + "compval": "neighbor.local_as", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "local_as": "{{ as }}", + }, + }, + }, + }, + { + "name": "neighbor.maximum_prefix", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+maximum-prefix + \s+(?P<num>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} maximum-prefix {{ neighbor.maximum_prefix }}", + "compval": "neighbor.maximum_prefix", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "maximum_prefix": "{{ num }}", + }, + }, + }, + }, + { + "name": "neighbor.nexthop_self", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+nexthop-self + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} nexthop-self", + "compval": "neighbor.nexthop_self", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "nexthop_self": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.override_capability", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+override-capability + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} override-capability", + "compval": "neighbor.override_capability", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "override_capability": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.passive", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+passive + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} passive", + "compval": "neighbor.passive", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "passive": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.password", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+password + \s+(?P<pwd>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} password {{ neighbor.password }}", + "compval": "neighbor.password", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "password": "{{ pwd }}", + }, + }, + }, + }, + { + "name": "neighbor.peer_group_name", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+peer-group + \s+(?P<name>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} peer-group {{ neighbor.peer_group_name }}", + "compval": "neighbor.peer_group_name", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "peer_group_name": "{{ name }}", + }, + }, + }, + }, + { + "name": "neighbor.port", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+port + \s+(?P<num>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} port {{ neighbor.port }}", + "compval": "neighbor.port", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "port": "{{ num|int }}", + }, + }, + }, + }, + { + "name": "neighbor.prefix_list", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+prefix-list + \s+(?P<action>export|import) + \s+(?P<list>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_neighbor_prefix_list, + "compval": "neighbor.prefix_list", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "prefix_list": [ + { + "action": "{{ action }}", + "prefix_list": "{{ list }}", + }, + ], + }, + }, + }, + }, + { + "name": "neighbor.remote_as", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+remote-as + \s+(?P<num>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} remote-as {{ neighbor.remote_as }}", + "compval": "neighbor.remote_as", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "remote_as": "{{ num|int }}", + }, + }, + }, + }, + { + "name": "neighbor.remove_private_as", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+remote-private-as + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} remote-private-as", + "compval": "neighbor.remove_private_as", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "remove_private_as": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.route_map", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+route-map + \s+(?P<action>export|import) + \s+(?P<map>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_neighbor_route_map, + "compval": "neighbor.route_map", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "route_map": [ + { + "action": "{{ action }}", + "route_map": "{{ map }}", + }, + ], + }, + }, + }, + }, + { + "name": "neighbor.route_reflector_client", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+route-reflector-client + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} router-reflector-client", + "compval": "neighbor.route_reflector_client", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "route_reflector_client": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.route_server_client", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+route-server-client + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} route-server-client", + "compval": "neighbor.route_server_client", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "route_server_client": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.shutdown", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+shutdown + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} shutdown", + "compval": "neighbor.shutdown", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "shutdown": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.soft_reconfiguration", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+soft-reconfiguration + \s+inbound + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} soft-reconfiguration", + "compval": "neighbor.soft_reconfiguration", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "soft_reconfiguration": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.strict_capability_match", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+strict-capability-match + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} strict-capability-match", + "compval": "neighbor.strict_capability_match", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "strict_capability_match": "{{ True }}", + }, + }, + }, + }, + { + "name": "neighbor.unsuppress_map", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+unsuppress-map + \s+(?P<map>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} unsuppress-map {{ neighbor.unsuppress_map }}", + "compval": "neighbor.unsuppress_map", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "unsuppress_map": "{{ map }}", + }, + }, + }, + }, + { + "name": "neighbor.update_source", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+update-source + \s+(?P<src>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} update-source {{ neighbor.update_source }}", + "compval": "neighbor.update_source", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "update_source": "{{ src }}", + }, + }, + }, + }, + { + "name": "neighbor.weight", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+weight + \s+(?P<num>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} weight {{ neighbor.weight }}", + "compval": "neighbor.weight", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "weight": "{{ num }}", + }, + }, + }, + }, + { + "name": "neighbor.ttl_security", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+ttl-security + \s+(?P<ttl>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp neighbor {{ neighbor.address }} ttl-security {{ neighbor.ttl_security }}", + "compval": "neighbor.ttl_security", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "ttl_security": "{{ ttl|int }}", + }, + }, + }, + }, + { + "name": "neighbor.timers", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+neighbor + \s+(?P<address>\S+) + \s+timers + \s+(?P<type>connect|holdtime|keepalive) + \s+(?P<sec>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_neighbor_timers, + "remval": "protocols bgp neighbor {{ neighbor.address }} timers", + "compval": "neighbor.timers", + "result": { + "as_number": "{{ as_num }}", + "neighbor": { + "{{ address }}": { + "address": "{{ address }}", + "timers": { + "{{ type }}": "{{ sec }}", + }, + }, + }, + }, + }, + { + "name": "timers", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+timers + \s+(?P<type>\S+) + \s+(?P<val>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_timers, + "remval": "protocols bgp timers", + "compval": "timers", + "result": { + "as_number": "{{ as_num }}", + "timers": { + "{{ type }}": "{{ val }}", + }, + }, + }, + { + "name": "bgp_params.always_compare_med", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+always-compare-med + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters always-compare-med", + "compval": "bgp_params.always_compare_med", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "always_compare_med": "{{ True }}", + }, + }, + }, + { + "name": "bgp_params.bestpath.as_path", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+bestpath + \s+as-path + \s+(?P<path>confed|ignore) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters bestpath as-path {{ bgp_params.bestpath.as_path }}", + "compval": "bgp_params.bestpath.as_path", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "bestpath": { + "as_path": "{{ path }}", + }, + }, + }, + }, + { + "name": "bgp_params.bestpath.compare_routerid", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+bestpath + \s+compare-routerid + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters bestpath compare-routerid", + "compval": "bgp_params.bestpath.compare_routerid", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "bestpath": { + "compare_routerid": "{{ True }}", + }, + }, + }, + }, + { + "name": "bgp_params.bestpath.med", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+bestpath + \s+med + \s+(?P<path>confed|missing-as-worst) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters bestpath med {{ bestpath.med }}", + "compval": "bgp_params.bestpath.med", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "bestpath": { + "med": "{{ path }}", + }, + }, + }, + }, + { + "name": "bgp_params.cluster_id", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+cluster-id + \s+(?P<id>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters cluster-id {{ bgp_params.cluster_id }}", + "compval": "bgp_params.cluster_id", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "cluster_id": "{{ id }}", + }, + }, + }, + { + "name": "bgp_params.confederation", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+confederation + \s+(?P<type>identifier|peers) + \s+(?P<val>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_params_confederation, + "compval": "bgp_params.always_compare_med", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "confederation": [ + { + "peers": "{{ val if type == 'peers' }}", + "identifier": "{{ val if type == 'identifier' }}", + }, + ], + }, + }, + }, + { + "name": "bgp_params.dampening_half_life", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+dampening + \s+half-life + \s+(?P<val>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters dampening half-life {{ bgp_params.dampening.half_life}}", + "compval": "bgp_params.dampening.half_life", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "dampening": { + "half_life": "{{ val }}", + }, + }, + }, + }, + { + "name": "bgp_params.dampening_max_suppress_time", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+dampening + \s+max-suppress-time + \s+(?P<val>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters dampening max-suppress-time {{ bgp_params.dampening.max_suppress_time}}", + "compval": "bgp_params.dampening.max_suppress_time", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "dampening": { + "max_suppress_time": "{{ val }}", + }, + }, + }, + }, + { + "name": "bgp_params.dampening_re_use", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+dampening + \s+re-use + \s+(?P<val>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters dampening re-use {{ bgp_params.dampening.re_use}}", + "compval": "bgp_params.dampening.re_use", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "dampening": { + "re_use": "{{ val }}", + }, + }, + }, + }, + { + "name": "bgp_params.dampening_start_suppress_time", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+dampening + \s+start-suppress-time + \s+(?P<val>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters dampening start-suppress-time {{ bgp_params.dampening.start_suppress_time}}", + "compval": "bgp_params.dampening.start_suppress_time", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "dampening": { + "start_suppress_time": "{{ val }}", + }, + }, + }, + }, + { + "name": "bgp_params.default", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+default + \s*(?P<no_ipv4_unicast>no-ipv4-unicast)* + \s*(?P<local_pref>local-pref\s\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_params_default, + "remval": "protocols bgp parameters default", + "compval": "bgp_params.default", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "default": { + "no_ipv4_unicast": "{{ True if no_ipv4_unicast is defined }}", + "local_pref": "{{ local_pref.split(" " )[1] if local_pref is defined }}", + }, + }, + }, + }, + { + "name": "bgp_params.deterministic_med", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+deterministic-med + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters deterministic-med", + "compval": "bgp_params.deterministic_med", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "deterministic_med": "{{ True }}", + }, + }, + }, + { + "name": "bgp_params.disbale_network_import_check", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+disable-network-import-check + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters disable-network-import-check", + "compval": "bgp_params.disable_network_import_check", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "disable_network_import_check": "{{ True }}", + }, + }, + }, + { + "name": "bgp_params.distance.prefix", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+distance\sprefix + \s+(?P<prefix>\S+) + \s+distance + \s+(?P<val>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters distance prefix {{ bgp_params.distance.prefix }} distance {{ bgp_params.distance.value }}", + "compval": "bgp_params.distance.prefix", + "remval": "protocols bgp parameters distance prefix", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "distance": [ + { + "prefix": "{{ prefix }}", + "value": "{{ val }}", + }, + ], + }, + }, + }, + { + "name": "bgp_params.distance.global", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+distance\sglobal + \s+(?P<type>\S+) + \s+(?P<val>\S+) + *$""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_params_distance, + "remval": "protocols bgp parameters distance global", + "compval": "bgp_params.distance", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "distance": [ + { + "type": "{{ type }}", + "value": "{{ val }}", + }, + ], + }, + }, + }, + { + "name": "bgp_params.enforce_first_as", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+enforce-first-as + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters enforce-first-as", + "compval": "bgp_params.enforce_first_as", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "enforce_first_as": "{{ True }}", + }, + }, + }, + { + "name": "bgp_params.graceful_restart", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+graceful-restart\s+stalepath-time + \s+(?P<val>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters graceful-restart stalepath-time {{ bgp_params.graceful_restart }}", + "compval": "bgp_params.graceful_restart", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "graceful_restart": "{{ val }}", + }, + }, + }, + { + "name": "bgp_params.log_neighbor_changes", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+log-neighbor-changes + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters log-neighbor-changes", + "compval": "bgp_params.log_neighbor_changes", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "log_neighbor_changes": "{{ True }}", + }, + }, + }, + { + "name": "bgp_params.no_client_to_client_reflection", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+no-client-to-client-reflection + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters no-client-to-client-reflection", + "compval": "bgp_params.log_neighbor_changes", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "no_client_to_client_reflection": "{{ True }}", + }, + }, + }, + { + "name": "bgp_params.no_fast_external_failover", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+no-fast-external-failover + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters no-fast-external-failover", + "compval": "bgp_params.no_fast_external_failover", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "no_fast_external_failover": "{{ True }}", + }, + }, + }, + { + "name": "bgp_params.routerid", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+router-id + \s+(?P<id>\S+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters router-id {{ bgp_params.router_id }}", + "compval": "bgp_params.router_id", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "router_id": "{{ id }}", + }, + }, + }, + { + "name": "bgp_params.scan_time", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+parameters + \s+scan-time + \s+(?P<sec>\d+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp parameters scan-time {{ bgp_params.scan_time }}", + "compval": "bgp_params.scan_time", + "result": { + "as_number": "{{ as_num }}", + "bgp_params": { + "scan_time": "{{ val }}", + }, + }, + }, + ] + # fmt: on diff --git a/plugins/modules/vyos_bgp_address_family.py b/plugins/modules/vyos_bgp_address_family.py index b3756e2e..14c3605d 100644 --- a/plugins/modules/vyos_bgp_address_family.py +++ b/plugins/modules/vyos_bgp_address_family.py @@ -19,6 +19,7 @@ version_added: 1.0.0 short_description: BGP Address Family resource module description: - This module manages BGP address family configuration of interfaces on devices running VYOS. +- Tested against VYOS 1.3, 1.4 author: Gomathi Selvi Srinivasan (@GomathiselviS) options: config: diff --git a/plugins/modules/vyos_bgp_global.py b/plugins/modules/vyos_bgp_global.py index 7d47e4ad..4d7db472 100644 --- a/plugins/modules/vyos_bgp_global.py +++ b/plugins/modules/vyos_bgp_global.py @@ -19,6 +19,7 @@ version_added: 1.0.0 short_description: BGP global resource module description: - This module manages BGP global configuration of interfaces on devices running VYOS. +- Tested against VYOS 1.3, 1.4 author: - Gomathi Selvi Srinivasan (@GomathiselviS) options: @@ -30,35 +31,35 @@ options: description: - AS number. type: int - aggregate_address: - description: - - BGP aggregate network. - type: list - elements: dict - suboptions: - prefix: - description: - - BGP aggregate network. - type: str - as_set: - description: - - Generate AS-set path information for this aggregate address. - type: bool - summary_only: - description: - - Announce the aggregate summary network only. - type: bool - maximum_paths: - description: BGP multipaths - type: list - elements: dict - suboptions: - path: - description: BGP multipaths - type: str - count: - description: No. of paths. - type: int + # aggregate_address: + # description: + # - BGP aggregate network. + # type: list + # elements: dict + # suboptions: + # prefix: + # description: + # - BGP aggregate network. + # type: str + # as_set: + # description: + # - Generate AS-set path information for this aggregate address. + # type: bool + # summary_only: + # description: + # - Announce the aggregate summary network only. + # type: bool + #maximum_paths: --> moved to address-family before 1.3 + # description: BGP multipaths + # type: list + # elements: dict + # suboptions: + # path: + # description: BGP multipaths + # type: str + # count: + # description: No. of paths. + # type: int neighbor: description: BGP neighbor type: list @@ -72,28 +73,37 @@ options: description: - Minimum interval for sending routing updates. type: int - allowas_in: - description: - - Number of occurrences of AS number. - type: int - as_override: - description: - - AS for routes sent to this neighbor to be the local AS. - type: bool - attribute_unchanged: - description: - - BGP attributes are sent unchanged. - type: dict - suboptions: - as_path: - description: as_path - type: bool - med: - description: med - type: bool - next_hop: - description: next_hop - type: bool + # bfd: # <-- added in 1.3 + # description: Enable Bidirectional Forwarding Detection (BFD) support + # type: dict + # suboptions: + # check-control-plane-failure: + # description: + # - Allow to write CBIT independence in BFD outgoing packets + # and read both C-BIT value of BFD and lookup BGP peer status + # type: bool + # allowas_in: --> Moved to address-family before 1.3 + # description: + # - Number of occurrences of AS number. + # type: int + # as_override: --> Moved to address-family before 1.3 + # description: + # - AS for routes sent to this neighbor to be the local AS. + # type: bool + # attribute_unchanged: --> Moved to address-family before 1.3 + # description: + # - BGP attributes are sent unchanged. + # type: dict + # suboptions: + # as_path: + # description: as_path + # type: bool + # med: + # description: med + # type: bool + # next_hop: + # description: next_hop + # type: bool capability: description: - Advertise capabilities to this neighbor. @@ -103,13 +113,17 @@ options: description: - Advertise dynamic capability to this neighbor. type: bool - orf: + extended_nexthop: description: - - Advertise ORF capability to this neighbor. - type: str - choices: - - send - - receive + - Advertise extended nexthop capability to this neighbor. + type: bool + # orf: --> Removed before 1.3 + # description: + # - Advertise ORF capability to this neighbor. + # type: str + # choices: + # - send + # - receive default_originate: description: - Send default route to this neighbor @@ -131,45 +145,70 @@ options: - Disable sending community attributes to this neighbor. type: str choices: ['extended', 'standard'] - distribute_list: - description: Access-list to filter route updates to/from this neighbor. - type: list - elements: dict - suboptions: - action: - description: Access-list to filter outgoing/incoming route updates to this neighbor - type: str - choices: ['export', 'import'] - acl: - description: Access-list number. - type: int + # distribute_list: --> Moved to address-family before 1.3 + # description: Access-list to filter route updates to/from this neighbor. + # type: list + # elements: dict + # suboptions: + # action: + # description: Access-list to filter outgoing/incoming route updates to this neighbor + # type: str + # choices: ['export', 'import'] + # acl: + # description: Access-list number. + # type: int ebgp_multihop: description: - Allow this EBGP neighbor to not be on a directly connected network. Specify the number hops. type: int - filter_list: - description: As-path-list to filter route updates to/from this neighbor. - type: list - elements: dict - suboptions: - action: - description: filter outgoing/incoming route updates - type: str - choices: ['export', 'import'] - path_list: - description: As-path-list to filter - type: str + # interface: # <-- added in 1.3 + # description: interface parameters + # type: dict + # suboptions: + # peer_group: + # description: Peer group for this neighbor + # type: str + # remote_as: + # description: + # - Remote AS number + # - Or 'external' for any number except this AS number + # - or 'internal' for this AS number + # type: str + # v6only: + # description: Enable BGP with v6 link-local only + # type: dict + # suboptions: + # peer_group: + # description: Peer group for this neighbor + # type: str + # remote_as: + # description: + # - Remote AS number + # - Or 'external' for any number except this AS number + # - or 'internal' for this AS number + # filter_list: --> Moved to address-family before 1.3 + # description: As-path-list to filter route updates to/from this neighbor. + # type: list + # elements: dict + # suboptions: + # action: + # description: filter outgoing/incoming route updates + # type: str + # choices: ['export', 'import'] + # path_list: + # description: As-path-list to filter + # type: str local_as: description: local as number not to be prepended to updates from EBGP peers type: int - maximum_prefix: - description: Maximum number of prefixes to accept from this neighbor - nexthop-self Nexthop for routes sent to this neighbor to be the local router. - type: int - nexthop_self: - description: Nexthop for routes sent to this neighbor to be the local router. - type: bool + # maximum_prefix: --> Moved to address-family before 1.3 + # description: Maximum number of prefixes to accept from this neighbor + # nexthop-self Nexthop for routes sent to this neighbor to be the local router. + # type: int + # nexthop_self: --> Moved to address-family before 1.3 + # description: Nexthop for routes sent to this neighbor to be the local router. + # type: bool override_capability: description: Ignore capability negotiation with specified neighbor. type: bool @@ -188,63 +227,61 @@ options: port: description: Neighbor's BGP port type: int - prefix_list: - description: Prefix-list to filter route updates to/from this neighbor. - type: list - elements: dict - suboptions: - action: - description: filter outgoing/incoming route updates - type: str - choices: ['export', 'import'] - prefix_list: - description: Prefix-list to filter - type: str + # prefix_list: --> Moved to address-family before 1.3 + # description: Prefix-list to filter route updates to/from this neighbor. + # type: list + # elements: dict + # suboptions: + # action: + # description: filter outgoing/incoming route updates + # type: str + # choices: ['export', 'import'] + # prefix_list: + # description: Prefix-list to filter + # type: str remote_as: description: Neighbor BGP AS number type: int - remove_private_as: - description: Remove private AS numbers from AS path in outbound route updates - type: bool - route_map: - description: Route-map to filter route updates to/from this neighbor. - type: list - elements: dict - suboptions: - action: - description: filter outgoing/incoming route updates - type: str - choices: ['export', 'import'] - route_map: - description: route-map to filter - type: str - route_reflector_client: - description: Neighbor as a route reflector client - type: bool - route_server_client: - description: Neighbor is route server client - type: bool + # remove_private_as: --> Moved to address-family before 1.3 + # description: Remove private AS numbers from AS path in outbound route updates + # type: bool + # route_map: --> Moved to address-family before 1.3 + # description: Route-map to filter route updates to/from this neighbor. + # type: list + # elements: dict + # suboptions: + # action: + # description: filter outgoing/incoming route updates + # type: str + # choices: ['export', 'import'] + # route_map: + # description: route-map to filter + # type: str + # route_reflector_client: --> Moved to address-family before 1.3 + # description: Neighbor as a route reflector client + # type: bool + # route_server_client: --> Removed prior to 1.3 + # description: Neighbor is route server client + # type: bool shutdown: description: Administratively shut down neighbor type: bool - soft_reconfiguration: - description: Soft reconfiguration for neighbor + # soft_reconfiguration: --> Moved to address-family before 1.3 + # description: Soft reconfiguration for neighbor + # type: bool + solo: # <-- added in 1.3 + description: Do not send back prefixes learned from the neighbor type: bool strict_capability_match: description: Enable strict capability negotiation type: bool - unsuppress_map: - description: Route-map to selectively unsuppress suppressed routes - type: str - update_source: - description: Source IP of routing updates - type: str - weight: - description: Default weight for routes from this neighbor - type: int - ttl_security: - description: Ttl security mechanism for this BGP peer - type: int + # unsuppress_map: --> Moved to address-family before 1.3 + # description: Route-map to selectively unsuppress suppressed routes + # type: str + + # weight: --> Moved to address-family before 1.3 + # description: Default weight for routes from this neighbor + # type: int timers: description: Neighbor timers type: dict @@ -258,35 +295,41 @@ options: keepalive: description: BGP keepalive interval for this neighbor type: int - network: - description: BGP network - type: list - elements: dict - suboptions: - address: - description: BGP network address - type: str - backdoor: - description: Network as a backdoor route - type: bool - route_map: - description: Route-map to modify route attributes - type: str - redistribute: - description: Redistribute routes from other protocols into BGP - type: list - elements: dict - suboptions: - protocol: - description: types of routes to be redistributed. - type: str - choices: ['connected', 'kernel', 'ospf', 'rip', 'static'] - route_map: - description: Route map to filter redistributed routes - type: str - metric: - description: Metric for redistributed routes. + ttl_security: + description: Number of the maximum number of hops to the BGP peer type: int + update_source: + description: Source IP of routing updates + type: str + # network: + # description: BGP network + # type: list + # elements: dict + # suboptions: + # address: + # description: BGP network address + # type: str + # backdoor: + # description: Network as a backdoor route + # type: bool + # route_map: + # description: Route-map to modify route attributes + # type: str + # redistribute: + # description: Redistribute routes from other protocols into BGP + # type: list + # elements: dict + # suboptions: + # protocol: + # description: types of routes to be redistributed. + # type: str + # choices: ['connected', 'kernel', 'ospf', 'rip', 'static'] + # route_map: + # description: Route map to filter redistributed routes + # type: str + # metric: + # description: Metric for redistributed routes. + # type: int timers: description: BGP protocol timers type: dict @@ -357,7 +400,9 @@ options: description: Default local preference type: int no_ipv4_unicast: - description: Deactivate IPv4 unicast for a peer by default + description: | + Deactivate IPv4 unicast for a peer by default + Deprecated: Unavailable after 1.4 type: bool deterministic_med: description: Compare MEDs between different peers in the same AS |