Skip to content

Commit

Permalink
[show][bgp] Use only 'show ip bgp' as the base and use bgp_frr_v4 fil…
Browse files Browse the repository at this point in the history
…e for FRR routing stack (#884)

Co-authored-by: Travis Van Duyn <trvanduy@microsoft.com>
  • Loading branch information
tsvanduyn and Travis Van Duyn authored Apr 21, 2020
1 parent a87173b commit c5a60ce
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
47 changes: 47 additions & 0 deletions show/bgp_frr_v4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import click
from show.main import ip, run_command, get_bgp_summary_extended


###############################################################################
#
# 'show ip bgp' cli stanza
#
###############################################################################


@ip.group()
def bgp():
"""Show IPv4 BGP (Border Gateway Protocol) information"""
pass


# 'summary' subcommand ("show ip bgp summary")
@bgp.command()
def summary():
"""Show summarized information of IPv4 BGP state"""
try:
device_output = run_command('sudo vtysh -c "show ip bgp summary"', return_cmd=True)
get_bgp_summary_extended(device_output)
except Exception:
run_command('sudo vtysh -c "show ip bgp summary"')


# 'neighbors' subcommand ("show ip 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 IP (IPv4) BGP neighbors"""

command = 'sudo vtysh -c "show ip bgp neighbor'

if ipaddress is not None:
command += ' {}'.format(ipaddress)

# info_type is only valid if ipaddress is specified
if info_type is not None:
command += ' {}'.format(info_type)

command += '"'

run_command(command)
18 changes: 4 additions & 14 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,26 +1585,16 @@ def protocol(verbose):
# Inserting BGP functionality into cli's show parse-chain.
# BGP commands are determined by the routing-stack being elected.
#
from .bgp_quagga_v4 import bgp
ip.add_command(bgp)

if routing_stack == "quagga":
from .bgp_quagga_v4 import bgp
ip.add_command(bgp)
from .bgp_quagga_v6 import bgp
ipv6.add_command(bgp)
elif routing_stack == "frr":
from .bgp_frr_v4 import bgp
ip.add_command(bgp)
from .bgp_frr_v6 import bgp
ipv6.add_command(bgp)
@cli.command()
@click.argument('bgp_args', nargs = -1, required = False)
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def bgp(bgp_args, verbose):
"""Show BGP information"""
bgp_cmd = "show bgp"
for arg in bgp_args:
bgp_cmd += " " + str(arg)
cmd = 'sudo vtysh -c "{}"'.format(bgp_cmd)
run_command(cmd, display_cmd=verbose)


#
# 'lldp' group ("show lldp ...")
Expand Down

0 comments on commit c5a60ce

Please sign in to comment.