Skip to content

Commit

Permalink
[201811] add bgpraw to show run all (#2603)
Browse files Browse the repository at this point in the history
What I did
Backport #2537
Add bgpraw output to show runningconfiguration all

How I did it
Generate bgpraw output then append it to show runnningconfiguration all's output

How to verify it
There is not unit test support on such old version.
Manually test on 201811 image.
  • Loading branch information
wen587 authored Feb 17, 2023
1 parent 02eb899 commit e86e275
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ def run_command(command, display_cmd=False):
sys.exit(rc)


def get_cmd_output(cmd):
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
return proc.communicate()[0], proc.returncode


def get_interface_mode():
mode = os.getenv('SONIC_CLI_IFACE_MODE')
if mode is None:
Expand Down Expand Up @@ -1322,8 +1327,24 @@ def runningconfiguration():
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def all(verbose):
"""Show full running configuration"""
cmd = "sonic-cfggen -d --print-data"
run_command(cmd, display_cmd=verbose)
cmd = ['sonic-cfggen', '-d', '--print-data']
stdout, rc = get_cmd_output(cmd)
if rc:
click.echo("Failed to get cmd output '{}':rc {}".format(cmd, rc))
raise click.Abort()

try:
output = json.loads(stdout)
except ValueError as e:
click.echo("Failed to load output '{}':{}".format(cmd, e))
raise click.Abort()

bgpraw_cmd = ['rvtysh', '-c', 'show running-config']
bgpraw, rc = get_cmd_output(bgpraw_cmd)
if rc:
bgpraw = ""
output['bgpraw'] = bgpraw
click.echo(json.dumps(output, indent=4))


# 'acl' subcommand ("show runningconfiguration acl")
Expand Down

0 comments on commit e86e275

Please sign in to comment.