forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bgp 'show' and 'clear' commands (sonic-net#692)
* Fix bgp commands * Make the function more pythonic * Fix clear command for current frr
- Loading branch information
1 parent
46f344e
commit 02375e1
Showing
4 changed files
with
182 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import click | ||
from clear.main import * | ||
|
||
|
||
############################################################################### | ||
# | ||
# 'clear ipv6 bgp' cli stanza | ||
# | ||
############################################################################### | ||
|
||
|
||
@ipv6.group(cls=AliasedGroup, default_if_no_args=True, | ||
context_settings=CONTEXT_SETTINGS) | ||
def bgp(): | ||
"""Clear IPv6 BGP (Border Gateway Protocol) information""" | ||
pass | ||
|
||
|
||
# Default 'bgp' command (called if no subcommands or their aliases were passed) | ||
@bgp.command(default=True) | ||
def default(): | ||
"""Clear all BGP peers""" | ||
command = 'sudo vtysh -c "clear bgp ipv6 *"' | ||
run_command(command) | ||
|
||
|
||
@bgp.group(cls=AliasedGroup, default_if_no_args=True, | ||
context_settings=CONTEXT_SETTINGS) | ||
def neighbor(): | ||
"""Clear specific BGP peers""" | ||
pass | ||
|
||
|
||
@neighbor.command(default=True) | ||
@click.argument('ipaddress', required=False) | ||
def default(ipaddress): | ||
"""Clear all BGP peers""" | ||
|
||
if ipaddress is not None: | ||
command = 'sudo vtysh -c "clear bgp ipv6 {} "'.format(ipaddress) | ||
else: | ||
command = 'sudo vtysh -c "clear bgp ipv6 *"' | ||
run_command(command) | ||
|
||
|
||
# 'in' subcommand | ||
@neighbor.command('in') | ||
@click.argument('ipaddress', required=False) | ||
def neigh_in(ipaddress): | ||
"""Send route-refresh""" | ||
|
||
if ipaddress is not None: | ||
command = 'sudo vtysh -c "clear bgp ipv6 {} in"'.format(ipaddress) | ||
else: | ||
command = 'sudo vtysh -c "clear bgp ipv6 * in"' | ||
run_command(command) | ||
|
||
|
||
# 'out' subcommand | ||
@neighbor.command('out') | ||
@click.argument('ipaddress', required=False) | ||
def neigh_out(ipaddress): | ||
"""Resend all outbound updates""" | ||
|
||
if ipaddress is not None: | ||
command = 'sudo vtysh -c "clear bgp ipv6 {} out"'.format(ipaddress) | ||
else: | ||
command = 'sudo vtysh -c "clear bgp ipv6 * out"' | ||
run_command(command) | ||
|
||
|
||
@neighbor.group(cls=AliasedGroup, default_if_no_args=True, | ||
context_settings=CONTEXT_SETTINGS) | ||
def soft(): | ||
"""Soft reconfig BGP's inbound/outbound updates""" | ||
pass | ||
|
||
|
||
@soft.command(default=True) | ||
@click.argument('ipaddress', required=False) | ||
def default(ipaddress): | ||
"""Clear BGP neighbors soft configuration""" | ||
|
||
if ipaddress is not None: | ||
command = 'sudo vtysh -c "clear bgp ipv6 {} soft "'.format(ipaddress) | ||
else: | ||
command = 'sudo vtysh -c "clear bgp ipv6 * soft"' | ||
run_command(command) | ||
|
||
|
||
# 'soft in' subcommand | ||
@soft.command('in') | ||
@click.argument('ipaddress', required=False) | ||
def soft_in(ipaddress): | ||
"""Send route-refresh""" | ||
|
||
if ipaddress is not None: | ||
command = 'sudo vtysh -c "clear bgp ipv6 {} soft in"'.format(ipaddress) | ||
else: | ||
command = 'sudo vtysh -c "clear bgp ipv6 * soft in"' | ||
run_command(command) | ||
|
||
|
||
# 'soft out' subcommand | ||
@soft.command('out') | ||
@click.argument('ipaddress', required=False) | ||
def soft_out(ipaddress): | ||
"""Resend all outbound updates""" | ||
|
||
if ipaddress is not None: | ||
command = 'sudo vtysh -c "clear bgp ipv6 {} soft out"' \ | ||
.format(ipaddress) | ||
else: | ||
command = 'sudo vtysh -c "clear bgp ipv6 * soft out"' | ||
run_command(command) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import click | ||
from show.main import * | ||
|
||
|
||
############################################################################### | ||
# | ||
# 'show ipv6 bgp' cli stanza | ||
# | ||
############################################################################### | ||
|
||
|
||
@ipv6.group(cls=AliasedGroup, default_if_no_args=False) | ||
def bgp(): | ||
"""Show IPv6 BGP (Border Gateway Protocol) information""" | ||
pass | ||
|
||
|
||
# 'summary' subcommand ("show ipv6 bgp summary") | ||
@bgp.command() | ||
def summary(): | ||
"""Show summarized information of IPv6 BGP state""" | ||
run_command('sudo vtysh -c "show bgp ipv6 summary"') | ||
|
||
|
||
# 'neighbors' subcommand ("show ipv6 bgp neighbors") | ||
@bgp.command() | ||
@click.argument('ipaddress', required=False) | ||
@click.argument('info_type', type=click.Choice(['routes', 'advertised-routes', 'received-routes']), required=False) | ||
def neighbors(ipaddress, info_type): | ||
"""Show IPv6 BGP neighbors""" | ||
ipaddress = "" if ipaddress is None else ipaddress | ||
info_type = "" if info_type is None else info_type | ||
command = 'sudo vtysh -c "show bgp ipv6 neighbor {} {}"'.format(ipaddress, info_type) | ||
run_command(command) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters