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] replace shell=True, replace xml by lxml, replace exit by sys.exit #2666

Merged
merged 15 commits into from
May 31, 2023
12 changes: 5 additions & 7 deletions show/bgp_quagga_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def bgp():
def summary():
"""Show summarized information of IPv4 BGP state"""
try:
device_output = run_command('sudo {} -c "show ip bgp summary"'.format(constants.RVTYSH_COMMAND), return_cmd=True)
device_output = run_command(['sudo', constants.RVTYSH_COMMAND, '-c', "show ip bgp summary"], return_cmd=True)
get_bgp_summary_extended(device_output)
except Exception:
run_command('sudo {} -c "show ip bgp summary"'.format(constants.RVTYSH_COMMAND))
run_command(['sudo', constants.RVTYSH_COMMAND, '-c', "show ip bgp summary"])


# 'neighbors' subcommand ("show ip bgp neighbors")
Expand All @@ -35,15 +35,13 @@ def summary():
def neighbors(ipaddress, info_type):
"""Show IP (IPv4) BGP neighbors"""

command = 'sudo {} -c "show ip bgp neighbor'.format(constants.RVTYSH_COMMAND)
command = ['sudo', constants.RVTYSH_COMMAND, '-c', "show ip bgp neighbor"]

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

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

command += '"'
command[-1] += ' {}'.format(info_type)

run_command(command)
6 changes: 3 additions & 3 deletions show/bgp_quagga_v6.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def bgp():
def summary():
"""Show summarized information of IPv6 BGP state"""
try:
device_output = run_command('sudo {} -c "show ipv6 bgp summary"'.format(constants.RVTYSH_COMMAND), return_cmd=True)
device_output = run_command(['sudo', constants.RVTYSH_COMMAND, '-c', "show ipv6 bgp summary"], return_cmd=True)
get_bgp_summary_extended(device_output)
except Exception:
run_command('sudo {} -c "show ipv6 bgp summary"'.format(constants.RVTYSH_COMMAND))
run_command(['sudo', constants.RVTYSH_COMMAND, '-c', "show ipv6 bgp summary"])


# 'neighbors' subcommand ("show ipv6 bgp neighbors")
Expand All @@ -34,5 +34,5 @@ def summary():
@click.argument('info_type', type=click.Choice(['routes', 'advertised-routes', 'received-routes']), required=True)
def neighbors(ipaddress, info_type):
"""Show IPv6 BGP neighbors"""
command = 'sudo {} -c "show ipv6 bgp neighbor {} {}"'.format(constants.RVTYSH_COMMAND, ipaddress, info_type)
command = ['sudo', constants.RVTYSH_COMMAND, '-c', "show ipv6 bgp neighbor {} {}".format(ipaddress, info_type)]
run_command(command)
Loading