diff options
| author | Viacheslav Hletenko <v.gletenko@vyos.io> | 2025-09-12 10:25:20 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-12 10:25:20 +0300 |
| commit | 6a47b699577904eb3e5866c27ab2813058cc9ed9 (patch) | |
| tree | 16fe9362c7dd2ef8062ee22e2cd7b0b5da93014c | |
| parent | 7d75763655b641c291d58ecc27be8173d0260411 (diff) | |
| parent | ad6b626e1b5fe5957934fa0e86ec730594557544 (diff) | |
| download | vyos-1x-6a47b699577904eb3e5866c27ab2813058cc9ed9.tar.gz vyos-1x-6a47b699577904eb3e5866c27ab2813058cc9ed9.zip | |
Merge pull request #4709 from l0crian1/reset-bgp-all-in-out-soft
op-mode: T7516: expand 'reset bgp all' elements with in/out/soft options
| -rw-r--r-- | op-mode-definitions/include/bgp/reset-bgp-afi-common.xml.i | 4 | ||||
| -rw-r--r-- | op-mode-definitions/include/bgp/reset-bgp-neighbor-options.xml.i | 14 | ||||
| -rw-r--r-- | op-mode-definitions/include/bgp/reset-bgp-peer-group-vrf.xml.i | 2 | ||||
| -rw-r--r-- | op-mode-definitions/include/bgp/reset-bgp-peer-group.xml.i | 2 | ||||
| -rw-r--r-- | op-mode-definitions/reset-bgp.xml.in | 92 | ||||
| -rw-r--r-- | op-mode-definitions/reset-ip-bgp.xml.in | 31 | ||||
| -rwxr-xr-x | src/op_mode/bgp.py | 23 |
7 files changed, 112 insertions, 56 deletions
diff --git a/op-mode-definitions/include/bgp/reset-bgp-afi-common.xml.i b/op-mode-definitions/include/bgp/reset-bgp-afi-common.xml.i index 2f88daad3..8089ef578 100644 --- a/op-mode-definitions/include/bgp/reset-bgp-afi-common.xml.i +++ b/op-mode-definitions/include/bgp/reset-bgp-afi-common.xml.i @@ -3,7 +3,7 @@ <properties> <help>Reset all external peers</help> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> @@ -12,7 +12,7 @@ <properties> <help>Reset peers with the AS number</help> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> diff --git a/op-mode-definitions/include/bgp/reset-bgp-neighbor-options.xml.i b/op-mode-definitions/include/bgp/reset-bgp-neighbor-options.xml.i index d9feee18a..7392dc30d 100644 --- a/op-mode-definitions/include/bgp/reset-bgp-neighbor-options.xml.i +++ b/op-mode-definitions/include/bgp/reset-bgp-neighbor-options.xml.i @@ -3,13 +3,13 @@ <properties> <help>Send route-refresh unless using 'soft-reconfiguration inbound'</help> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> <leafNode name="prefix-filter"> <properties> <help>Push out prefix-list ORF and do inbound soft reconfig</help> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> </leafNode> </children> </node> @@ -17,31 +17,31 @@ <properties> <help>Reset message statistics</help> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> </leafNode> <leafNode name="out"> <properties> <help>Resend all outbound updates</help> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> </leafNode> <node name="soft"> <properties> <help>Soft reconfig inbound and outbound updates</help> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> <node name="in"> <properties> <help>Send route-refresh unless using 'soft-reconfiguration inbound'</help> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> </node> <node name="out"> <properties> <help>Resend all outbound updates</help> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> </node> </children> </node> diff --git a/op-mode-definitions/include/bgp/reset-bgp-peer-group-vrf.xml.i b/op-mode-definitions/include/bgp/reset-bgp-peer-group-vrf.xml.i index c1a24bae2..f9871eb8c 100644 --- a/op-mode-definitions/include/bgp/reset-bgp-peer-group-vrf.xml.i +++ b/op-mode-definitions/include/bgp/reset-bgp-peer-group-vrf.xml.i @@ -6,7 +6,7 @@ <path>vrf name ${COMP_WORDS[4]} protocols bgp peer-group</path> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> diff --git a/op-mode-definitions/include/bgp/reset-bgp-peer-group.xml.i b/op-mode-definitions/include/bgp/reset-bgp-peer-group.xml.i index c26e47b47..0497804b8 100644 --- a/op-mode-definitions/include/bgp/reset-bgp-peer-group.xml.i +++ b/op-mode-definitions/include/bgp/reset-bgp-peer-group.xml.i @@ -6,7 +6,7 @@ <path>protocols bgp peer-group</path> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> diff --git a/op-mode-definitions/reset-bgp.xml.in b/op-mode-definitions/reset-bgp.xml.in index 3d73fd417..fd8b9532b 100644 --- a/op-mode-definitions/reset-bgp.xml.in +++ b/op-mode-definitions/reset-bgp.xml.in @@ -14,17 +14,20 @@ <script>${vyos_completion_dir}/list_bgp_neighbors.sh --both</script> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> </virtualTagNode> - <leafNode name="all"> + <node name="all"> <properties> <help>Clear all peers</help> </properties> - <command>vtysh -c "clear bgp *"</command> - </leafNode> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> + <children> + #include <include/bgp/reset-bgp-neighbor-options.xml.i> + </children> + </node> #include <include/bgp/reset-bgp-afi-common.xml.i> #include <include/bgp/reset-bgp-peer-group.xml.i> <tagNode name="prefix"> @@ -34,19 +37,22 @@ <list><x.x.x.x/x></list> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> </tagNode> <node name="ipv4"> <properties> <help>IPv4 Address Family</help> </properties> <children> - <leafNode name="all"> + <node name="all"> <properties> <help>Clear all peers</help> </properties> - <command>vtysh -c "clear bgp ipv4 *"</command> - </leafNode> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> + <children> + #include <include/bgp/reset-bgp-neighbor-options.xml.i> + </children> + </node> #include <include/bgp/reset-bgp-afi-common.xml.i> #include <include/bgp/reset-bgp-peer-group.xml.i> <virtualTagNode> @@ -56,7 +62,7 @@ <script>${vyos_completion_dir}/list_bgp_neighbors.sh --ipv4</script> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> @@ -68,12 +74,15 @@ <help>IPv6 Address Family</help> </properties> <children> - <leafNode name="all"> + <node name="all"> <properties> <help>Clear all peers</help> </properties> - <command>vtysh -c "clear bgp ipv6 *"</command> - </leafNode> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> + <children> + #include <include/bgp/reset-bgp-neighbor-options.xml.i> + </children> + </node> #include <include/bgp/reset-bgp-afi-common.xml.i> #include <include/bgp/reset-bgp-peer-group.xml.i> <virtualTagNode> @@ -83,7 +92,7 @@ <script>${vyos_completion_dir}/list_bgp_neighbors.sh --ipv6</script> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> @@ -100,12 +109,15 @@ <help>Ethernet Virtual Private Network</help> </properties> <children> - <leafNode name="all"> + <node name="all"> <properties> <help>Clear all peers</help> </properties> - <command>vtysh -c "clear bgp l2vpn evpn *"</command> - </leafNode> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> + <children> + #include <include/bgp/reset-bgp-neighbor-options.xml.i> + </children> + </node> #include <include/bgp/reset-bgp-afi-common.xml.i> #include <include/bgp/reset-bgp-peer-group.xml.i> <virtualTagNode> @@ -115,7 +127,7 @@ <script>${vyos_completion_dir}/list_bgp_neighbors.sh --both</script> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> @@ -139,17 +151,20 @@ <script>${vyos_completion_dir}/list_bgp_neighbors.sh --both --vrf ${COMP_WORDS[3]}</script> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> </virtualTagNode> - <leafNode name="all"> + <node name="all"> <properties> <help>Clear all peers</help> </properties> - <command>vtysh -c "clear bgp vrf $4 *"</command> - </leafNode> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> + <children> + #include <include/bgp/reset-bgp-neighbor-options.xml.i> + </children> + </node> #include <include/bgp/reset-bgp-afi-common.xml.i> #include <include/bgp/reset-bgp-peer-group-vrf.xml.i> <tagNode name="prefix"> @@ -159,19 +174,22 @@ <list><x.x.x.x/x></list> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> </tagNode> <node name="ipv4"> <properties> <help>IPv4 Address Family</help> </properties> <children> - <leafNode name="all"> + <node name="all"> <properties> <help>Clear all peers</help> </properties> - <command>vtysh -c "clear bgp vrf $4 ipv4 *"</command> - </leafNode> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> + <children> + #include <include/bgp/reset-bgp-neighbor-options.xml.i> + </children> + </node> #include <include/bgp/reset-bgp-afi-common.xml.i> #include <include/bgp/reset-bgp-peer-group-vrf.xml.i> <virtualTagNode> @@ -181,7 +199,7 @@ <script>${vyos_completion_dir}/list_bgp_neighbors.sh --ipv4 --vrf ${COMP_WORDS[3]}</script> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> @@ -193,12 +211,15 @@ <help>IPv6 Address Family</help> </properties> <children> - <leafNode name="all"> + <node name="all"> <properties> <help>Clear all peers</help> </properties> - <command>vtysh -c "clear bgp vrf $4 ipv6 *"</command> - </leafNode> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> + <children> + #include <include/bgp/reset-bgp-neighbor-options.xml.i> + </children> + </node> #include <include/bgp/reset-bgp-afi-common.xml.i> #include <include/bgp/reset-bgp-peer-group-vrf.xml.i> <virtualTagNode> @@ -208,7 +229,7 @@ <script>${vyos_completion_dir}/list_bgp_neighbors.sh --ipv6 --vrf ${COMP_WORDS[3]}</script> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> @@ -225,12 +246,15 @@ <help>Ethernet Virtual Private Network</help> </properties> <children> - <leafNode name="all"> + <node name="all"> <properties> <help>Clear all peers</help> </properties> - <command>vtysh -c "clear bgp vrf $4 l2vpn evpn *"</command> - </leafNode> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> + <children> + #include <include/bgp/reset-bgp-neighbor-options.xml.i> + </children> + </node> #include <include/bgp/reset-bgp-afi-common.xml.i> #include <include/bgp/reset-bgp-peer-group-vrf.xml.i> <virtualTagNode> @@ -240,7 +264,7 @@ <script>${vyos_completion_dir}/list_bgp_neighbors.sh --both --vrf ${COMP_WORDS[3]}</script> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/bgp.py reset --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> diff --git a/op-mode-definitions/reset-ip-bgp.xml.in b/op-mode-definitions/reset-ip-bgp.xml.in index 9201865dc..d11d3ce3d 100644 --- a/op-mode-definitions/reset-ip-bgp.xml.in +++ b/op-mode-definitions/reset-ip-bgp.xml.in @@ -16,17 +16,20 @@ <script>${vyos_completion_dir}/list_bgp_neighbors.sh --ipv4</script> </completionHelp> </properties> - <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> + <command>${vyos_op_scripts_dir}/reset_bgp.py --command="$*"</command> <children> #include <include/bgp/reset-bgp-neighbor-options.xml.i> </children> </virtualTagNode> - <leafNode name="all"> + <node name="all"> <properties> <help>Clear all BGP peering sessions</help> </properties> - <command>vtysh -c "clear bgp ipv4 *"</command> - </leafNode> + <command>${vyos_op_scripts_dir}/reset_bgp.py --command="$*"</command> + <children> + #include <include/bgp/reset-bgp-neighbor-options.xml.i> + </children> + </node> <tagNode name="dampening"> <properties> <help>Clear BGP route flap dampening information for given host ornetwork address</help> @@ -36,9 +39,9 @@ </properties> <standalone> <help>Clear BGP route flap dampening information</help> - <command>vtysh -c "clear ip bgp dampening"</command> + <command>${vyos_op_scripts_dir}/reset_bgp.py --command="$*"</command> </standalone> - <command>vtysh -c "clear ip bgp dampening $5"</command> + <command>${vyos_op_scripts_dir}/reset_bgp.py --command="$*"</command> <children> <virtualTagNode> <properties> @@ -47,7 +50,7 @@ <list><x.x.x.x></list> </completionHelp> </properties> - <command>vtysh -c "clear ip bgp dampening $5 $6"</command> + <command>${vyos_op_scripts_dir}/reset_bgp.py --command="$*"</command> </virtualTagNode> </children> </tagNode> @@ -61,12 +64,15 @@ </completionHelp> </properties> <children> - <leafNode name="all"> + <node name="all"> <properties> <help>Clear all BGP peering sessions for vrf</help> </properties> - <command>vtysh -c "clear bgp vrf $5 *"</command> - </leafNode> + <command>${vyos_op_scripts_dir}/reset_bgp.py --command="$*"</command> + <children> + #include <include/bgp/reset-bgp-neighbor-options.xml.i> + </children> + </node> <virtualTagNode> <properties> <help>Clear BGP neighbor IP address</help> @@ -74,7 +80,10 @@ <list><x.x.x.x></list> </completionHelp> </properties> - <command>vtysh -c "clear bgp vrf $5 $6"</command> + <command>${vyos_op_scripts_dir}/reset_bgp.py --command="$*"</command> + <children> + #include <include/bgp/reset-bgp-neighbor-options.xml.i> + </children> </virtualTagNode> </children> </tagNode> diff --git a/src/op_mode/bgp.py b/src/op_mode/bgp.py index 011f39c1b..7f0815433 100755 --- a/src/op_mode/bgp.py +++ b/src/op_mode/bgp.py @@ -80,6 +80,29 @@ show bgp ArgFamily = typing.Literal['inet', 'inet6', 'l2vpn'] ArgFamilyModifier = typing.Literal['unicast', 'labeled_unicast', 'multicast', 'vpn', 'flowspec'] +def reset(command: str): + from vyos.utils.process import cmd + + tokens = command.split() + + # reset -> clear (only if it's the first token) + if tokens and tokens[0] == "reset": + tokens[0] = "clear" + + # peer-group and vrf may have 'all' in their names; don't replace 'all' with '*' + skip_indexes = [] + for index, word in enumerate(tokens[:-1]): + if word in ("peer-group", "vrf"): + skip_indexes.append(index + 1) + + # replace standalone "all" with "*" unless it's in the skip list + for index, word in enumerate(tokens): + if word == "all" and index not in skip_indexes: + tokens[index] = "*" + + command = " ".join(tokens) + cmd(f'vtysh -c "{command}"') + def show_summary(raw: bool): from vyos.utils.process import cmd |
