summaryrefslogtreecommitdiff
path: root/plugins/module_utils/network
diff options
context:
space:
mode:
authorGomathiselviS <gomathiselvi@gmail.com>2021-02-24 12:16:02 -0500
committerGitHub <noreply@github.com>2021-02-24 17:16:02 +0000
commita679a918cb0474a0eb5db73f925e612b4863c177 (patch)
tree14756d2a168b6fadc3ed8289acabc33ac565fe39 /plugins/module_utils/network
parentdf81f31331b2b1b4ab894da44532cb3ea245f83a (diff)
downloadvyos-ansible-collection-a679a918cb0474a0eb5db73f925e612b4863c177.tar.gz
vyos-ansible-collection-a679a918cb0474a0eb5db73f925e612b4863c177.zip
Add vyos_bgp_global resource module (#125)
Add vyos_bgp_global resource module Reviewed-by: https://github.com/apps/ansible-zuul
Diffstat (limited to 'plugins/module_utils/network')
-rw-r--r--plugins/module_utils/network/vyos/argspec/bgp_global/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/argspec/bgp_global/bgp_global.py290
-rw-r--r--plugins/module_utils/network/vyos/config/bgp_global/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py426
-rw-r--r--plugins/module_utils/network/vyos/facts/bgp_global/__init__.py0
-rw-r--r--plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py88
-rw-r--r--plugins/module_utils/network/vyos/facts/facts.py4
-rw-r--r--plugins/module_utils/network/vyos/rm_templates/bgp_global.py2043
8 files changed, 2851 insertions, 0 deletions
diff --git a/plugins/module_utils/network/vyos/argspec/bgp_global/__init__.py b/plugins/module_utils/network/vyos/argspec/bgp_global/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plugins/module_utils/network/vyos/argspec/bgp_global/__init__.py
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
new file mode 100644
index 0000000..4192a84
--- /dev/null
+++ b/plugins/module_utils/network/vyos/argspec/bgp_global/bgp_global.py
@@ -0,0 +1,290 @@
+# -*- 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
+
+#############################################
+# WARNING #
+#############################################
+#
+# This file is auto generated by the resource
+# module builder playbook.
+#
+# Do not edit this file manually.
+#
+# Changes to this file will be over written
+# by the resource module builder.
+#
+# Changes should be made in the model used to
+# generate this file or in the resource module
+# builder template.
+#
+#############################################
+
+"""
+The arg spec for the vyos_bgp_global module
+"""
+
+
+class Bgp_globalArgs(object): # pylint: disable=R0903
+ """The arg spec for the vyos_bgp_global module"""
+
+ def __init__(self, **kwargs):
+ pass
+
+ argument_spec = {
+ "running_config": {"type": "str"},
+ "state": {
+ "default": "merged",
+ "type": "str",
+ "choices": [
+ "merged",
+ "replaced",
+ "deleted",
+ "gathered",
+ "parsed",
+ "rendered",
+ "purged",
+ ],
+ },
+ "config": {
+ "type": "dict",
+ "options": {
+ "redistribute": {
+ "elements": "dict",
+ "type": "list",
+ "options": {
+ "route_map": {"type": "str"},
+ "metric": {"type": "int"},
+ "protocol": {
+ "type": "str",
+ "choices": [
+ "connected",
+ "kernel",
+ "ospf",
+ "rip",
+ "static",
+ ],
+ },
+ },
+ },
+ "network": {
+ "elements": "dict",
+ "type": "list",
+ "options": {
+ "backdoor": {"type": "bool"},
+ "route_map": {"type": "str"},
+ "address": {"type": "str"},
+ },
+ },
+ "maximum_paths": {
+ "type": "list",
+ "elements": "dict",
+ "options": {
+ "path": {"type": "str"},
+ "count": {"type": "int"},
+ },
+ },
+ "aggregate_address": {
+ "elements": "dict",
+ "type": "list",
+ "options": {
+ "summary_only": {"type": "bool"},
+ "as_set": {"type": "bool"},
+ "prefix": {"type": "str"},
+ },
+ },
+ "timers": {
+ "type": "dict",
+ "options": {
+ "holdtime": {"type": "int"},
+ "keepalive": {"type": "int"},
+ },
+ },
+ "neighbor": {
+ "type": "list",
+ "elements": "dict",
+ "options": {
+ "shutdown": {"type": "bool"},
+ "weight": {"type": "int"},
+ "default_originate": {"type": "str"},
+ "peer_group_name": {"type": "str"},
+ "route_reflector_client": {"type": "bool"},
+ "strict_capability_match": {"type": "bool"},
+ "remove_private_as": {"type": "bool"},
+ "as_override": {"type": "bool"},
+ "port": {"type": "int"},
+ "soft_reconfiguration": {"type": "bool"},
+ "nexthop_self": {"type": "bool"},
+ "remote_as": {"type": "int"},
+ "ebgp_multihop": {"type": "int"},
+ "route_map": {
+ "elements": "dict",
+ "type": "list",
+ "options": {
+ "action": {
+ "type": "str",
+ "choices": ["export", "import"],
+ },
+ "route_map": {"type": "str"},
+ },
+ },
+ "distribute_list": {
+ "elements": "dict",
+ "type": "list",
+ "options": {
+ "action": {
+ "type": "str",
+ "choices": ["export", "import"],
+ },
+ "acl": {"type": "int"},
+ },
+ },
+ "allowas_in": {"type": "int"},
+ "passive": {"type": "bool"},
+ "ttl_security": {"type": "int"},
+ "peer_group": {"type": "bool"},
+ "maximum_prefix": {"type": "int"},
+ "prefix_list": {
+ "elements": "dict",
+ "type": "list",
+ "options": {
+ "action": {
+ "type": "str",
+ "choices": ["export", "import"],
+ },
+ "prefix_list": {"type": "str"},
+ },
+ },
+ "update_source": {"type": "str"},
+ "description": {"type": "str"},
+ "local_as": {"type": "int"},
+ "route_server_client": {"type": "bool"},
+ "attribute_unchanged": {
+ "type": "dict",
+ "options": {
+ "as_path": {"type": "bool"},
+ "med": {"type": "bool"},
+ "next_hop": {"type": "bool"},
+ },
+ },
+ "disable_connected_check": {"type": "bool"},
+ "address": {"type": "str"},
+ "password": {"type": "str"},
+ "disable_send_community": {
+ "type": "str",
+ "choices": ["extended", "standard"],
+ },
+ "unsuppress_map": {"type": "str"},
+ "override_capability": {"type": "bool"},
+ "filter_list": {
+ "elements": "dict",
+ "type": "list",
+ "options": {
+ "action": {
+ "type": "str",
+ "choices": ["export", "import"],
+ },
+ "path_list": {"type": "str"},
+ },
+ },
+ "capability": {
+ "type": "dict",
+ "options": {
+ "orf": {
+ "type": "str",
+ "choices": ["send", "receive"],
+ },
+ "dynamic": {"type": "bool"},
+ },
+ },
+ "timers": {
+ "type": "dict",
+ "options": {
+ "holdtime": {"type": "int"},
+ "connect": {"type": "int"},
+ "keepalive": {"type": "int"},
+ },
+ },
+ "disable_capability_negotiation": {"type": "bool"},
+ "advertisement_interval": {"type": "int"},
+ },
+ },
+ "bgp_params": {
+ "type": "dict",
+ "options": {
+ "router_id": {"type": "str"},
+ "distance": {
+ "elements": "dict",
+ "type": "list",
+ "options": {
+ "prefix": {"type": "int"},
+ "type": {
+ "type": "str",
+ "choices": [
+ "external",
+ "internal",
+ "local",
+ ],
+ },
+ "value": {"type": "int"},
+ },
+ },
+ "dampening": {
+ "type": "dict",
+ "options": {
+ "half_life": {"type": "int"},
+ "start_suppress_time": {"type": "int"},
+ "max_suppress_time": {"type": "int"},
+ "re_use": {"type": "int"},
+ },
+ },
+ "graceful_restart": {"type": "int"},
+ "scan_time": {"type": "int"},
+ "always_compare_med": {"type": "bool"},
+ "no_fast_external_failover": {"type": "bool"},
+ "bestpath": {
+ "type": "dict",
+ "options": {
+ "med": {
+ "type": "str",
+ "choices": ["confed", "missing-as-worst"],
+ },
+ "as_path": {
+ "type": "str",
+ "choices": ["confed", "ignore"],
+ },
+ "compare_routerid": {"type": "bool"},
+ },
+ },
+ "enforce_first_as": {"type": "bool"},
+ "default": {
+ "type": "dict",
+ "options": {
+ "local_pref": {"type": "int"},
+ "no_ipv4_unicast": {"type": "bool"},
+ },
+ },
+ "cluster_id": {"type": "str"},
+ "no_client_to_client_reflection": {"type": "bool"},
+ "deterministic_med": {"type": "bool"},
+ "log_neighbor_changes": {"type": "bool"},
+ "disable_network_import_check": {"type": "bool"},
+ "confederation": {
+ "type": "list",
+ "elements": "dict",
+ "options": {
+ "peers": {"type": "int"},
+ "identifier": {"type": "int"},
+ },
+ },
+ },
+ },
+ "as_number": {"type": "int"},
+ },
+ },
+ } # pylint: disable=C0301
diff --git a/plugins/module_utils/network/vyos/config/bgp_global/__init__.py b/plugins/module_utils/network/vyos/config/bgp_global/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plugins/module_utils/network/vyos/config/bgp_global/__init__.py
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
new file mode 100644
index 0000000..0a5f15d
--- /dev/null
+++ b/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py
@@ -0,0 +1,426 @@
+#
+# -*- 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 vyos_bgp_global config file.
+It is in this file where the current configuration (as dict)
+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.utils import (
+ dict_merge,
+)
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module import (
+ ResourceModule,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
+ Facts,
+)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global import (
+ Bgp_globalTemplate,
+)
+
+
+class Bgp_global(ResourceModule):
+ """
+ The vyos_bgp_global config class
+ """
+
+ def __init__(self, module):
+ super(Bgp_global, self).__init__(
+ empty_fact_val={},
+ facts_module=Facts(module),
+ module=module,
+ resource="bgp_global",
+ tmplt=Bgp_globalTemplate(),
+ )
+ self.parsers = []
+
+ def execute_module(self):
+ """Execute the module
+
+ :rtype: A dictionary
+ :returns: The result from module execution
+ """
+ if self.state not in ["parsed", "gathered"]:
+ self.generate_commands()
+ self.run_commands()
+ return self.result
+
+ def generate_commands(self):
+ """Generate configuration commands to send based on
+ want, have and desired state.
+ """
+ wantd = {}
+ haved = {}
+
+ if (
+ self.want.get("as_number") == self.have.get("as_number")
+ or not self.have
+ ):
+ if self.want:
+ wantd = {self.want["as_number"]: self.want}
+ if self.have:
+ haved = {self.have["as_number"]: self.have}
+ else:
+ self._module.fail_json(
+ msg="Only one bgp instance is allowed per device"
+ )
+
+ # turn all lists of dicts into dicts prior to merge
+ for entry in wantd, haved:
+ self._bgp_global_list_to_dict(entry)
+
+ # if state is merged, merge want onto have and then compare
+ if self.state == "merged":
+ wantd = dict_merge(haved, wantd)
+
+ # if state is deleted, empty out wantd and set haved to wantd
+ if self.state == "purged":
+ h_del = {}
+ for k, v in iteritems(haved):
+ if k in wantd or not wantd:
+ h_del.update({k: v})
+ for num, entry in iteritems(h_del):
+ self.commands.append(
+ self._tmplt.render({"as_number": num}, "router", True)
+ )
+ wantd = {}
+
+ if self.state == "deleted":
+ self._compare(want={}, have=self.have)
+ wantd = {}
+
+ for k, want in iteritems(wantd):
+ self._compare(want=want, have=haved.pop(k, {}))
+
+ def _compare(self, want, have):
+ """Leverages the base class `compare()` method and
+ populates the list of commands to be run by comparing
+ the `want` and `have` data with the `parsers` defined
+ for the Bgp_global network resource.
+ """
+ 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":
+ self.compare(
+ parsers=parsers,
+ want={"as_number": want["as_number"], name: entry},
+ have={
+ "as_number": want["as_number"],
+ name: have.pop(name, {}),
+ },
+ )
+ for name, entry in iteritems(have):
+ if name != "as_number":
+ self.compare(
+ parsers=parsers,
+ want={},
+ have={"as_number": have["as_number"], name: entry},
+ )
+ # Do the negation first
+ command_set = []
+ for cmd in self.commands:
+ if cmd not in command_set:
+ if "delete" in cmd:
+ command_set.insert(0, cmd)
+ else:
+ command_set.append(cmd)
+ self.commands = command_set
+
+ def _compare_neighbor(self, want, have):
+
+ parsers = [
+ "neighbor.advertisement_interval",
+ "neighbor.allowas_in",
+ "neighbor.as_override",
+ "neighbor.attribute_unchanged.as_path",
+ "neighbor.attribute_unchanged.med",
+ "neighbor.attribute_unchanged.next_hop",
+ "neighbor.capability_dynamic",
+ "neighbor.capability_orf",
+ "neighbor.default_originate",
+ "neighbor.description",
+ "neighbor.disable_capability_negotiation",
+ "neighbor.disable_connected_check",
+ "neighbor.disable_send_community",
+ "neighbor.distribute_list",
+ "neighbor.ebgp_multihop",
+ "neighbor.filter_list",
+ "neighbor.local_as",
+ "neighbor.maximum_prefix",
+ "neighbor.nexthop_self",
+ "neighbor.override_capability",
+ "neighbor.passive",
+ "neighbor.password",
+ "neighbor.peer_group_name",
+ "neighbor.port",
+ "neighbor.prefix_list",
+ "neighbor.remote_as",
+ "neighbor.remove_private_as",
+ "neighbor.route_map",
+ "neighbor.route_reflector_client",
+ "neighbor.route_server_client",
+ "neighbor.shutdown",
+ "neighbor.soft_reconfiguration",
+ "neighbor.strict_capability_match",
+ "neighbor.unsuppress_map",
+ "neighbor.update_source",
+ "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":
+ continue
+ if hneigh.get(name):
+ h = {"address": name, k: hneigh[name].pop(k, {})}
+ else:
+ h = {}
+ self.compare(
+ parsers=parsers,
+ want={
+ "as_number": want["as_number"],
+ "neighbor": {"address": name, k: v},
+ },
+ have={"as_number": want["as_number"], "neighbor": h},
+ )
+ for name, entry in iteritems(hneigh):
+ if name not in wneigh.keys():
+ if self._check_af(name):
+ msg = "Use the _bgp_address_family module to delete the address_family under neighbor {0}, before replacing/deleting the neighbor.".format(
+ name
+ )
+ self._module.fail_json(msg=msg)
+ else:
+ self.commands.append(
+ "delete protocols bgp "
+ + str(have["as_number"])
+ + " neighbor "
+ + name
+ )
+ continue
+ for k, v in entry.items():
+ self.compare(
+ parsers=parsers,
+ want={},
+ have={
+ "as_number": have["as_number"],
+ "neighbor": {"address": name, k: v},
+ },
+ )
+
+ def _compare_bgp_params(self, want, have):
+ parsers = [
+ "bgp_params.always_compare_med",
+ "bgp_params.bestpath.as_path",
+ "bgp_params.bestpath.compare_routerid",
+ "bgp_params.bestpath.med",
+ "bgp_params.cluster_id",
+ "bgp_params.confederation",
+ "bgp_params.dampening_half_life",
+ "bgp_params.dampening_max_suppress_time",
+ "bgp_params.dampening_re_use",
+ "bgp_params.dampening_start_suppress_time",
+ "bgp_params.default",
+ "bgp_params.deterministic_med",
+ "bgp_params.disbale_network_import_check",
+ "bgp_params.enforce_first_as",
+ "bgp_params.graceful_restart",
+ "bgp_params.log_neighbor_changes",
+ "bgp_params.no_client_to_client_reflection",
+ "bgp_params.no_fast_external_failover",
+ "bgp_params.routerid",
+ "bgp_params.scan_time",
+ ]
+ wbgp = want.pop("bgp_params", {})
+ hbgp = have.pop("bgp_params", {})
+ for name, entry in iteritems(wbgp):
+ if name == "confederation":
+ if entry != hbgp.pop(name, {}):
+ self.addcmd(
+ {
+ "as_number": want["as_number"],
+ "bgp_params": {name: entry},
+ },
+ "bgp_params.confederation",
+ False,
+ )
+ elif name == "distance":
+ if entry != hbgp.pop(name, {}):
+ distance_parsers = [
+ "bgp_params.distance.global",
+ "bgp_params.distance.prefix",
+ ]
+ for distance_type in entry:
+ self.compare(
+ parsers=distance_parsers,
+ want={
+ "as_number": want["as_number"],
+ "bgp_params": {name: distance_type},
+ },
+ have={
+ "as_number": want["as_number"],
+ "bgp_params": {name: hbgp.pop(name, {})},
+ },
+ )
+ else:
+ self.compare(
+ parsers=parsers,
+ want={
+ "as_number": want["as_number"],
+ "bgp_params": {name: entry},
+ },
+ have={
+ "as_number": want["as_number"],
+ "bgp_params": {name: hbgp.pop(name, {})},
+ },
+ )
+ if not wbgp and hbgp:
+ self.commands.append(
+ "delete protocols bgp "
+ + str(have["as_number"])
+ + " parameters"
+ )
+ hbgp = {}
+ for name, entry in iteritems(hbgp):
+ if name == "confederation":
+ self.commands.append(
+ "delete protocols bgp "
+ + str(have["as_number"])
+ + " parameters confederation"
+ )
+ elif name == "distance":
+ distance_parsers = [
+ "bgp_params.distance.global",
+ "bgp_params.distance.prefix",
+ ]
+ self.compare(
+ parsers=distance_parsers,
+ want={},
+ have={
+ "as_number": have["as_number"],
+ "bgp_params": {name: entry[0]},
+ },
+ )
+ else:
+ self.compare(
+ parsers=parsers,
+ want={},
+ have={
+ "as_number": have["as_number"],
+ "bgp_params": {name: entry},
+ },
+ )
+
+ 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",
+ "filter_list",
+ "prefix_list",
+ "route_map",
+ ]:
+ wdict = want.pop(attrib, {})
+ hdict = have.pop(attrib, {})
+ for key, entry in iteritems(wdict):
+ if entry != hdict.pop(key, {}):
+ self.addcmd(entry, "neighbor.{0}".format(attrib), False)
+ # remove remaining items in have for replaced
+ for entry in hdict.values():
+ self.addcmd(entry, "neighbor.{0}".format(attrib), True)
+
+ def _bgp_global_list_to_dict(self, entry):
+ for name, proc in iteritems(entry):
+ if "neighbor" in proc:
+ neigh_dict = {}
+ for entry in proc.get("neighbor", []):
+ neigh_dict.update({entry["address"]: entry})
+ proc["neighbor"] = neigh_dict
+
+ if "network" in proc:
+ network_dict = {}
+ for entry in proc.get("network", []):
+ network_dict.update({entry["address"]: entry})
+ proc["network"] = network_dict
+
+ if "aggregate_address" in proc:
+ agg_dict = {}
+ for entry in proc.get("aggregate_address", []):
+ agg_dict.update({entry["prefix"]: entry})
+ proc["aggregate_address"] = agg_dict
+
+ if "redistribute" in proc:
+ redis_dict = {}
+ for entry in proc.get("redistribute", []):
+ redis_dict.update({entry["protocol"]: entry})
+ proc["redistribute"] = redis_dict
+
+ 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
+ return af_present
+
+ def _get_config(self, connection):
+ return connection.get(
+ 'show configuration commands | match "set protocols bgp .* neighbor"'
+ )
diff --git a/plugins/module_utils/network/vyos/facts/bgp_global/__init__.py b/plugins/module_utils/network/vyos/facts/bgp_global/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plugins/module_utils/network/vyos/facts/bgp_global/__init__.py
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
new file mode 100644
index 0000000..3cfa83c
--- /dev/null
+++ b/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py
@@ -0,0 +1,88 @@
+# -*- 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 vyos bgp_global fact class
+It is in this file the configuration is collected from the device
+for a given resource, parsed, and the facts tree is populated
+based on the configuration.
+"""
+
+from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
+ utils,
+)
+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.argspec.bgp_global.bgp_global import (
+ Bgp_globalArgs,
+)
+import re
+
+
+class Bgp_globalFacts(object):
+ """The vyos bgp_global facts class"""
+
+ def __init__(self, module, subspec="config", options="options"):
+ self._module = module
+ self.argument_spec = Bgp_globalArgs.argument_spec
+
+ def get_device_data(self, connection):
+ return connection.get(
+ 'show configuration commands | match "set protocols bgp"'
+ )
+
+ def populate_facts(self, connection, ansible_facts, data=None):
+ """Populate the facts for Bgp_global network resource
+
+ :param connection: the device connection
+ :param ansible_facts: Facts dictionary
+ :param data: previously collected conf
+
+ :rtype: dictionary
+ :returns: facts
+ """
+ facts = {}
+ objs = {}
+ config_lines = []
+
+ if not data:
+ data = self.get_device_data(connection)
+
+ for resource in data.splitlines():
+ if "address-family" not in resource:
+ config_lines.append(re.sub("'", "", resource))
+
+ bgp_global_parser = Bgp_globalTemplate(lines=config_lines)
+ objs = bgp_global_parser.parse()
+
+ if "neighbor" in objs:
+ objs["neighbor"] = list(objs["neighbor"].values())
+ objs["neighbor"] = sorted(
+ objs["neighbor"], key=lambda k: k["address"]
+ )
+ if "network" in objs:
+ objs["network"] = sorted(
+ objs["network"], key=lambda k: k["address"]
+ )
+ if "aggregate_address" in objs:
+ objs["aggregate_address"] = sorted(
+ objs["aggregate_address"], key=lambda k: k["prefix"]
+ )
+
+ ansible_facts["ansible_network_resources"].pop("bgp_global", None)
+
+ params = utils.remove_empties(
+ utils.validate_config(self.argument_spec, {"config": objs})
+ )
+
+ facts["bgp_global"] = params.get("config", [])
+ ansible_facts["ansible_network_resources"].update(facts)
+
+ return ansible_facts
diff --git a/plugins/module_utils/network/vyos/facts/facts.py b/plugins/module_utils/network/vyos/facts/facts.py
index c2766de..95eff2e 100644
--- a/plugins/module_utils/network/vyos/facts/facts.py
+++ b/plugins/module_utils/network/vyos/facts/facts.py
@@ -49,6 +49,9 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospf_interfaces.ospf_interfaces import (
Ospf_interfacesFacts,
)
+from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global import (
+ Bgp_globalFacts,
+)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legacy.base import (
Default,
Neighbors,
@@ -70,6 +73,7 @@ FACT_RESOURCE_SUBSETS = dict(
ospfv3=Ospfv3Facts,
ospfv2=Ospfv2Facts,
ospf_interfaces=Ospf_interfacesFacts,
+ bgp_global=Bgp_globalFacts,
)
diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_global.py b/plugins/module_utils/network/vyos/rm_templates/bgp_global.py
new file mode 100644
index 0000000..aff6258
--- /dev/null
+++ b/plugins/module_utils/network/vyos/rm_templates/bgp_global.py
@@ -0,0 +1,2043 @@
+# -*- 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.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 {as_number} 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 {as_number} maximum-paths ".format(**config_data)
+ + list_el["path"]
+ + " "
+ + str(list_el["count"])
+ )
+ 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
+
+
+def _tmplt_bgp_params_default(config_data):
+ command = "protocols bgp {as_number} 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_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"]):
+ command.append(
+ "protocols bgp {as_number} 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 {as_number} ".format(**config_data)
+ + "timers "
+ + k
+ + " "
+ + str(v)
+ )
+
+ return command
+
+
+def _tmplt_bgp_neighbor_attribute_unchanged_as_path(config_data):
+ command = "protocols bgp {as_number} ".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 {as_number} ".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 {as_number} ".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 {as_number} ".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 {as_number} ".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 {as_number} ".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 {as_number} ".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 {as_number} parameters distance global ".format(
+ **config_data
+ )
+ + config_data["bgp_params"]["distance"]["type"]
+ + " "
+ + str(config_data["bgp_params"]["distance"]["value"])
+ )
+ return command
+
+
+class Bgp_globalTemplate(NetworkTemplate):
+ def __init__(self, lines=None):
+ prefix = {"set": "set", "remove": "delete"}
+ super(Bgp_globalTemplate, self).__init__(
+ lines=lines, tmplt=self, prefix=prefix
+ )
+
+ # fmt: off
+ PARSERS = [
+ {
+ "name": "router",
+ "getval": re.compile(
+ r"""
+ ^set
+ \s+protocols
+ \s+bgp
+ \s+(?P<as_num>\d+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }}",
+ "compval": "as_number",
+ "result": {
+ "as_number": "{{ as_num }}",
+ }
+ },
+ {
+ "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"""
+ ^set
+ \s+protocols
+ \s+bgp
+ \s+(?P<as_num>\d+)
+ \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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+advertisement-interval
+ \s+(?P<interval>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} advertisement-interval {{ neighbor.advertisement_interval }}",
+ "remval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+allowas-in
+ \s+number
+ \s+(?P<num>\'\d+\')
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+as-override
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \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+(?P<as_num>\d+)
+ \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+(?P<as_num>\d+)
+ \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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+capability
+ \s+(?P<dynamic>dynamic)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+capability
+ \s+orf
+ \s+prefix-list
+ \s+(?P<orf>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+default-originate
+ \s+route-map
+ \s+(?P<map>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+description
+ \s+(?P<desc>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+disable-capability-negotiation
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+disable-connected-check
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+disable-send-community
+ \s+(?P<comm>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+ebgp-multihop
+ \s+(?P<hop>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+local-as
+ \s+(?P<as>\S+)
+ \s+no-prepend
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+maximum-prefix
+ \s+(?P<num>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+nexthop-self
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+override-capability
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+passive
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} nexthop-self",
+ "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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+password
+ \s+(?P<pwd>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} password {{ neighbor.address }}",
+ "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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+peer-group
+ \s+(?P<name>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+port
+ \s+(?P<num>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+remote-as
+ \s+(?P<num>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+remote-private-as
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+route-reflector-client
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+route-server-client
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+shutdown
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+soft-reconfiguration
+ \s+inbound
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+strict-capability-match
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+unsuppress-map
+ \s+(?P<map>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+update-source
+ \s+(?P<src>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+weight
+ \s+(?P<num>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+neighbor
+ \s+(?P<address>\S+)
+ \s+ttl-security
+ \s+(?P<ttl>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \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 {{ as_number }} neighbor {{ neighbor.address }} timers",
+ "compval": "neighbor.timers",
+ "result": {
+ "as_number": "{{ as_num }}",
+ "neighbor": {
+ "{{ address }}": {
+ "address": "{{ address }}",
+ "timers": {
+ "{{ type }}": "{{ sec }}"
+ }
+ }
+ }
+ }
+ },
+ {
+ "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"""
+ ^set
+ \s+protocols
+ \s+bgp
+ \s+(?P<as_num>\d+)
+ \s+timers
+ \s+(?P<type>\S+)
+ \s+(?P<val>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": _tmplt_bgp_timers,
+ "remval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+always-compare-med
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+bestpath
+ \s+as-path
+ \s+(?P<path>confed|ignore)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+bestpath
+ \s+compare-routerid
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+bestpath
+ \s+med
+ \s+(?P<path>confed|missing-as-worst)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+cluster-id
+ \s+(?P<id>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \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+(?P<as_num>\d+)
+ \s+parameters
+ \s+dampening
+ \s+half-life
+ \s+(?P<val>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+dampening
+ \s+max-suppress-time
+ \s+(?P<val>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+dampening
+ \s+re-use
+ \s+(?P<val>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+dampening
+ \s+start-suppress-time
+ \s+(?P<val>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \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 {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+deterministic-med
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+disable-network-import-check
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+distance\sprefix
+ \s+(?P<prefix>\S+)
+ \s+distance
+ \s+(?P<val>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} parameters distance prefix {{ bgp_params.distance.prefix }} distance {{ bgp_params.distance.value }}",
+ "compval": "bgp_params.distance.prefix",
+ "remval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+distance\sglobal
+ \s+(?P<type>\S+)
+ \s+(?P<val>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": _tmplt_bgp_params_distance,
+ "remval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+enforce-first-as
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+graceful-restart\s+stalepath-time
+ \s+(?P<val>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+log-neighbor-changes
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+no-client-to-client-reflection
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+no-fast-external-failover
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+router-id
+ \s+(?P<id>\S+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} 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+(?P<as_num>\d+)
+ \s+parameters
+ \s+scan-time
+ \s+(?P<sec>\d+)
+ *$""",
+ re.VERBOSE,
+ ),
+ "setval": "protocols bgp {{ as_number }} parameters scan-time {{ bgp_params.scan_time }}",
+ "compval": "bgp_params.scan_time",
+ "result": {
+ "as_number": "{{ as_num }}",
+ "bgp_params": {
+ "scan_time": "{{ val }}",
+ }
+ }
+ },
+
+ ]
+ # fmt: on