diff --git a/clear/bgp_frr_v4.py b/clear/bgp_frr_v4.py deleted file mode 100644 index 2446792d218f..000000000000 --- a/clear/bgp_frr_v4.py +++ /dev/null @@ -1,226 +0,0 @@ -import click -from clear.main import * - - -############################################################################### -# -# 'clear bgp' cli stanza -# -############################################################################### - - -@cli.group(cls=AliasedGroup, default_if_no_args=True) -def bgp(): - """Clear BGP peers / state""" - 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 *"' - 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 {} "'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp *"' - 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 {} in"'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp * 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 {} out"'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp * 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 peers soft configuration""" - - if ipaddress is not None: - command = 'sudo vtysh -c "clear bgp {} soft "'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp * 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 {} soft in"'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp * 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 {} soft out"'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp * soft out"' - run_command(command) - - -############################################################################### -# -# 'clear bgp ipv4' cli stanza -# -############################################################################### - - -@bgp.group(cls=AliasedGroup, default_if_no_args=True, - context_settings=CONTEXT_SETTINGS) -def ipv4(): - """Clear BGP IPv4 peers / state""" - pass - - -# Default 'bgp' command (called if no subcommands or their aliases were passed) -@ipv4.command(default=True) -def default(): - """Clear all IPv4 BGP peers""" - command = 'sudo vtysh -c "clear bgp ipv4 *"' - run_command(command) - - -@ipv4.group(cls=AliasedGroup, default_if_no_args=True, - context_settings=CONTEXT_SETTINGS) -def neighbor(): - """Clear specific IPv4 BGP peers""" - pass - - -@neighbor.command(default=True) -@click.argument('ipaddress', required=False) -def default(ipaddress): - """Clear all IPv4 BGP peers""" - - if ipaddress is not None: - command = 'sudo vtysh -c "clear bgp ipv4 {} "'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp ipv4 *"' - 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 ipv4 {} in"'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp ipv4 * 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 ipv4 {} out"'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp ipv4 * 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 ipv4 {} soft "'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp ipv4 * 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 ipv4 {} soft in"'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp ipv4 * 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 ipv4 {} soft out"'.\ - format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp ipv4 * soft out"' - run_command(command) diff --git a/clear/bgp_frr_v6.py b/clear/bgp_frr_v6.py deleted file mode 100644 index a08453b0438f..000000000000 --- a/clear/bgp_frr_v6.py +++ /dev/null @@ -1,114 +0,0 @@ -import click -from clear.main import * - - -############################################################################### -# -# 'clear bgp ipv6' cli stanza -# -############################################################################### - - -@bgp.group(cls=AliasedGroup, default_if_no_args=True) -def ipv6(): - """Clear BGP IPv6 peers / state""" - pass - - -# Default 'bgp' command (called if no subcommands or their aliases were passed) -@ipv6.command(default=True) -def default(): - """Clear all IPv6 BGP peers""" - command = 'sudo vtysh -c "clear bgp ipv6 *"' - run_command(command) - - -@ipv6.group(cls=AliasedGroup, default_if_no_args=True, - context_settings=CONTEXT_SETTINGS) -def neighbor(): - """Clear specific IPv6 BGP peers""" - pass - - -@neighbor.command(default=True) -@click.argument('ipaddress', required=False) -def default(ipaddress): - """Clear all IPv6 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) diff --git a/clear/main.py b/clear/main.py index 32ced2177ecf..d74947967deb 100755 --- a/clear/main.py +++ b/clear/main.py @@ -151,9 +151,8 @@ def ipv6(): # -# Inserting BGP functionality into cli's clear parse-chain. The insertion point -# and the specific BGP commands to import, will be determined by the routing-stack -# being elected. +# Inserting BGP functionality into cli's clear parse-chain. +# BGP commands are determined by the routing-stack being elected. # if routing_stack == "quagga": from .bgp_quagga_v4 import bgp @@ -161,10 +160,20 @@ def ipv6(): from .bgp_quagga_v6 import bgp ipv6.add_command(bgp) elif routing_stack == "frr": - from .bgp_frr_v4 import bgp - cli.add_command(bgp) - from .bgp_frr_v6 import bgp - cli.add_command(bgp) + @cli.command() + @click.argument('bgp_args', nargs = -1, required = False) + def bgp(bgp_args): + """BGP information""" + bgp_cmd = "clear bgp" + options = False + for arg in bgp_args: + bgp_cmd += " " + str(arg) + options = True + if options is True: + command = 'sudo vtysh -c "{}"'.format(bgp_cmd) + else: + command = 'sudo vtysh -c "clear bgp *"' + run_command(command) @cli.command() diff --git a/show/bgp_frr_v4.py b/show/bgp_frr_v4.py deleted file mode 100644 index ba76b17f0384..000000000000 --- a/show/bgp_frr_v4.py +++ /dev/null @@ -1,127 +0,0 @@ -import click -from show.main import * - - -############################################################################### -# -# 'show bgp' cli stanza -# -############################################################################### - - -@cli.group(cls=AliasedGroup, default_if_no_args=False) -def bgp(): - """Show IPv4 BGP (Border Gateway Protocol) information""" - pass - - -# 'summary' subcommand ("show bgp summary") -@bgp.command() -def summary(): - """Show summarized information of IPv4 BGP state""" - run_command('sudo vtysh -c "show bgp summary"') - - -# 'neighbors' subgroup ("show bgp neighbors ...") -@bgp.group(cls=AliasedGroup, default_if_no_args=True) -def neighbors(): - """Show BGP neighbors""" - pass - - -# 'neighbors' subcommand ("show bgp neighbors") -@neighbors.command(default=True) -@click.argument('ipaddress', required=False) -def default(ipaddress): - """Show BGP neighbors""" - - if ipaddress is not None: - command = 'sudo vtysh -c "show bgp neighbor {} "'.format(ipaddress) - run_command(command) - else: - run_command('sudo vtysh -c "show bgp neighbor"') - - -# 'advertised-routes' subcommand ("show bgp neighbors advertised-routes ") -@neighbors.command('advertised-routes') -@click.argument('ipaddress') -def advertised_routes(ipaddress): - """Display routes advertised to a BGP peer""" - - command = 'sudo vtysh -c "show bgp ipv4 neighbor {} advertised-routes"'. \ - format(ipaddress) - run_command(command) - - -# 'routes' subcommand ("show bgp neighbors routes ") -@neighbors.command('routes') -@click.argument('ipaddress') -def routes(ipaddress): - """Display routes learned from neighbor""" - - command = 'sudo vtysh -c "show bgp ipv4 neighbor {} routes"'. \ - format(ipaddress) - run_command(command) - - -############################################################################### -# -# 'show bgp ipv4' cli stanza -# -############################################################################### - - -@bgp.group(cls=AliasedGroup, default_if_no_args=False) -def ipv4(): - """Show BGP ipv4 commands""" - pass - - -# 'summary' subcommand ("show bgp ipv4 summary") -@ipv4.command() -def summary(): - """Show summarized information of IPv4 BGP state""" - run_command('sudo vtysh -c "show bgp ipv4 summary"') - - -# 'neighbors' subgroup ("show bgp ipv4 neighbors ...") -@ipv4.group(cls=AliasedGroup, default_if_no_args=True) -def neighbors(): - """Show BGP IPv4 neighbors""" - pass - - -# 'neighbors' subcommand ("show bgp ipv4 neighbors") -@neighbors.command(default=True) -@click.argument('ipaddress', required=False) -def default(ipaddress): - """Show BGP IPv4 neighbors""" - - if ipaddress is not None: - command = 'sudo vtysh -c "show bgp ipv4 neighbor {} "'. \ - format(ipaddress) - run_command(command) - else: - run_command('sudo vtysh -c "show bgp ipv4 neighbor"') - - -# 'advertised-routes' subcommand ("show bgp ipv4 neighbors advertised-routes ") -@neighbors.command('advertised-routes') -@click.argument('ipaddress') -def advertised_routes(ipaddress): - """Display routes advertised to a BGP peer""" - - command = 'sudo vtysh -c "show bgp ipv4 neighbor {} advertised-routes"'. \ - format(ipaddress) - run_command(command) - - -# 'routes' subcommand ("show bgp ipv4 neighbors routes ") -@neighbors.command('routes') -@click.argument('ipaddress') -def routes(ipaddress): - """Display routes learned from neighbor""" - - command = 'sudo vtysh -c "show bgp ipv4 neighbor {} routes"'. \ - format(ipaddress) - run_command(command) diff --git a/show/bgp_frr_v6.py b/show/bgp_frr_v6.py deleted file mode 100644 index 8627461b83a8..000000000000 --- a/show/bgp_frr_v6.py +++ /dev/null @@ -1,65 +0,0 @@ -import click -from show.main import * - - -############################################################################### -# -# 'show bgp ipv6' cli stanza -# -############################################################################### - - -@bgp.group(cls=AliasedGroup, default_if_no_args=False) -def ipv6(): - """Show BGP ipv6 commands""" - pass - - -# 'summary' subcommand ("show bgp ipv6 summary") -@ipv6.command() -def summary(): - """Show summarized information of IPv6 BGP state""" - run_command('sudo vtysh -c "show bgp ipv6 summary"') - - -# 'neighbors' subgroup ("show bgp ipv6 neighbors ...") -@ipv6.group(cls=AliasedGroup, default_if_no_args=True) -def neighbors(): - """Show BGP IPv6 neighbors""" - pass - - -# 'neighbors' subcommand ("show bgp ipv6 neighbors") -@neighbors.command(default=True) -@click.argument('ipaddress', required=False) -def default(ipaddress): - """Show BGP IPv6 neighbors""" - - if ipaddress is not None: - command = 'sudo vtysh -c "show bgp ipv6 neighbor {} "'. \ - format(ipaddress) - run_command(command) - else: - run_command('sudo vtysh -c "show bgp ipv6 neighbor"') - - -# 'advertised-routes' subcommand ("show bgp ipv6 neighbors advertised-routes ") -@neighbors.command('advertised-routes') -@click.argument('ipaddress') -def advertised_routes(ipaddress): - """Display routes advertised to a BGP peer""" - - command = 'sudo vtysh -c "show bgp ipv6 neighbor {} advertised-routes"'. \ - format(ipaddress) - run_command(command) - - -# 'routes' subcommand ("show bgp ipv6 neighbors routes ") -@neighbors.command('routes') -@click.argument('ipaddress') -def routes(ipaddress): - """Display routes learned from neighbor""" - - command = 'sudo vtysh -c "show bgp ipv6 neighbor {} routes"'. \ - format(ipaddress) - run_command(command) diff --git a/show/main.py b/show/main.py index 38111ab2be38..5a2399c833f3 100755 --- a/show/main.py +++ b/show/main.py @@ -383,9 +383,8 @@ def protocol(): # -# Inserting BGP functionality into cli's show parse-chain. The insertion point -# and the specific BGP commands to import, will be determined by the routing-stack -# being elected. +# Inserting BGP functionality into cli's show parse-chain. +# BGP commands are determined by the routing-stack being elected. # if routing_stack == "quagga": from .bgp_quagga_v4 import bgp @@ -393,10 +392,15 @@ def protocol(): from .bgp_quagga_v6 import bgp ipv6.add_command(bgp) elif routing_stack == "frr": - from .bgp_frr_v4 import bgp - cli.add_command(bgp) - from .bgp_frr_v6 import bgp - cli.add_command(bgp) + @cli.command() + @click.argument('bgp_args', nargs = -1, required = False) + def bgp(bgp_args): + """BGP information""" + bgp_cmd = "show bgp" + for arg in bgp_args: + bgp_cmd += " " + str(arg) + command = 'sudo vtysh -c "{}"'.format(bgp_cmd) + run_command(command) #