Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[show][bgp] Use only 'show ip bgp' as the base and use bgp_frr_v4 file for FRR routing stack #884

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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