diff --git a/clear/bgp_frr_v6.py b/clear/bgp_frr_v6.py new file mode 100644 index 000000000000..c8c34510861d --- /dev/null +++ b/clear/bgp_frr_v6.py @@ -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) diff --git a/clear/main.py b/clear/main.py index af71975ad45b..6c274ae99bc9 100755 --- a/clear/main.py +++ b/clear/main.py @@ -107,18 +107,15 @@ def get_routing_stack(): def run_command(command, pager=False, return_output=False): # Provide option for caller function to Process the output. - if return_output == True: - proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + if return_output: return proc.communicate() - - if pager is True: + elif pager: #click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green')) - p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) - click.echo_via_pager(p.stdout.read()) + click.echo_via_pager(proc.stdout.read()) else: #click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green')) - p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) - click.echo(p.stdout.read()) + click.echo(proc.stdout.read()) CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help', '-?']) @@ -165,21 +162,10 @@ def ipv6(): from .bgp_quagga_v6 import bgp ipv6.add_command(bgp) elif routing_stack == "frr": - @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) - + from .bgp_quagga_v4 import bgp + ip.add_command(bgp) + from .bgp_frr_v6 import bgp + ipv6.add_command(bgp) @cli.command() def counters(): diff --git a/show/bgp_frr_v6.py b/show/bgp_frr_v6.py new file mode 100644 index 000000000000..47c66aaed0f0 --- /dev/null +++ b/show/bgp_frr_v6.py @@ -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) diff --git a/show/main.py b/show/main.py index 2e510d554f02..d08be88305b3 100755 --- a/show/main.py +++ b/show/main.py @@ -1077,6 +1077,22 @@ def ipv6(): """Show IPv6 commands""" pass +# +# 'prefix-list' subcommand ("show ipv6 prefix-list") +# + +@ipv6.command('prefix-list') +@click.argument('prefix_list_name', required=False) +@click.option('--verbose', is_flag=True, help="Enable verbose output") +def prefix_list(prefix_list_name, verbose): + """show ip prefix-list""" + cmd = 'sudo vtysh -c "show ipv6 prefix-list' + if prefix_list_name is not None: + cmd += ' {}'.format(prefix_list_name) + cmd += '"' + run_command(cmd, display_cmd=verbose) + + # # 'show ipv6 interfaces' command @@ -1158,12 +1174,15 @@ 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_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") @@ -1215,7 +1234,7 @@ def table(verbose): def get_hw_info_dict(): """ - This function is used to get the HW info helper function + This function is used to get the HW info helper function """ hw_info_dict = {} machine_info = sonic_device_util.get_machine_info() @@ -1223,7 +1242,7 @@ def get_hw_info_dict(): config_db = ConfigDBConnector() config_db.connect() data = config_db.get_table('DEVICE_METADATA') - try: + try: hwsku = data['localhost']['hwsku'] except KeyError: hwsku = "Unknown" @@ -1327,7 +1346,7 @@ def version(verbose): version_info = sonic_device_util.get_sonic_version_info() hw_info_dict = get_hw_info_dict() serial_number_cmd = "sudo decode-syseeprom -s" - serial_number = subprocess.Popen(serial_number_cmd, shell=True, stdout=subprocess.PIPE) + serial_number = subprocess.Popen(serial_number_cmd, shell=True, stdout=subprocess.PIPE) sys_uptime_cmd = "uptime" sys_uptime = subprocess.Popen(sys_uptime_cmd, shell=True, stdout=subprocess.PIPE) click.echo("\nSONiC Software Version: SONiC.{}".format(version_info['build_version']))