-
Notifications
You must be signed in to change notification settings - Fork 819
[show] enhance 'show ip[v6] bgp summary' command #754
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ def bgp(): | |
| @bgp.command() | ||
| def summary(): | ||
| """Show summarized information of IPv6 BGP state""" | ||
| run_command('sudo vtysh -c "show bgp ipv6 summary"') | ||
| get_bgp_summary_extended('sudo vtysh -c "show ip bgp summary"') | ||
|
||
|
|
||
|
|
||
| # 'neighbors' subcommand ("show ipv6 bgp neighbors") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ def bgp(): | |
| @bgp.command() | ||
| def summary(): | ||
| """Show summarized information of IPv6 BGP state""" | ||
| run_command('sudo vtysh -c "show ipv6 bgp summary"') | ||
| get_bgp_summary_extended('sudo vtysh -c "show ip bgp summary"') | ||
|
||
|
|
||
|
|
||
| # 'neighbors' subcommand ("show ipv6 bgp neighbors") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -393,6 +393,49 @@ def run_command_in_alias_mode(command): | |
| sys.exit(rc) | ||
|
|
||
|
|
||
| def get_bgp_summary_extended(command): | ||
| """ | ||
| Adds Neighbor name to the show ip[v6] bgp summary command | ||
| :param command: command to get bgp summary | ||
| """ | ||
| try: | ||
| p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
|
||
| device_output = p.stdout.read() | ||
| modified_output = [] | ||
| my_list = iter(device_output.splitlines()) | ||
| for element in my_list: | ||
|
||
| if element.startswith("Neighbor"): | ||
| element = "{}\tNeighborName".format(element) | ||
| modified_output.append(element) | ||
| for line in my_list: | ||
| if not line or line.startswith('Total'): | ||
| modified_output.append(line) | ||
| continue | ||
| ip = bgp_neighbor_ip_to_name(line.split()[0]) | ||
| if len(line.split()) == 1: | ||
| modified_output.append(line) | ||
| line = next(my_list) | ||
| line = f"{}\t{}".format(line, ip) | ||
| modified_output.append(line) | ||
| continue | ||
| modified_output.append(element) | ||
| click.echo("\n".join(modified_output)) | ||
| except: | ||
| click.echo('unable to get output.\nTry issuing sudo vtysh -c "show ip[v6] bgp summary"') | ||
|
|
||
|
|
||
| def bgp_neighbor_ip_to_name(address): | ||
| """ | ||
| Gets BGP neighbor name from the given ipv4/v6 address | ||
| :param address: ipv4/ipv6 address | ||
| :return: string | ||
| """ | ||
| config_db = ConfigDBConnector() | ||
| config_db.connect() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you open that connection only once?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed in next iteration |
||
| neighbor_data = config_db.get_table('BGP_NEIGHBOR') | ||
| return neighbor_data[address].get("name", "NotAvailable") if address in neighbor_data else "NotAvailable" | ||
|
|
||
|
|
||
| CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help', '-?']) | ||
|
|
||
| # | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.