Skip to content

Commit

Permalink
ZTP CLI commands (sonic-net#599)
Browse files Browse the repository at this point in the history
Implemented following commands to use Zero Touch Provisioning

show ztp status
config ztp enable
config ztp disable
config ztp run

Signed-off-by: Rajendra Dendukuri <rajendra.dendukuri@broadcom.com>
Co-authored-by: Akhilesh Samineni <47657796+AkhileshSamineni@users.noreply.github.com>
Co-authored-by: rlhui <48738894+rlhui@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 12, 2020
1 parent 3d794cc commit a4385f0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
35 changes: 35 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,41 @@ def naming_mode_alias():
"""Set CLI interface naming mode to ALIAS (Vendor port alias)"""
set_interface_naming_mode('alias')

@config.group()
def ztp():
""" Configure Zero Touch Provisioning """
if os.path.isfile('/usr/bin/ztp') is False:
exit("ZTP feature unavailable in this image version")

if os.geteuid() != 0:
exit("Root privileges are required for this operation")
pass

@ztp.command()
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='ZTP will be restarted. You may lose switch data and connectivity, continue?')
@click.argument('run', required=False, type=click.Choice(["run"]))
def run(run):
"""Restart ZTP of the device."""
command = "ztp run -y"
run_command(command, display_cmd=True)

@ztp.command()
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='Active ZTP session will be stopped and disabled, continue?')
@click.argument('disable', required=False, type=click.Choice(["disable"]))
def disable(disable):
"""Administratively Disable ZTP."""
command = "ztp disable -y"
run_command(command, display_cmd=True)

@ztp.command()
@click.argument('enable', required=False, type=click.Choice(["enable"]))
def enable(enable):
"""Administratively Enable ZTP."""
command = "ztp enable"
run_command(command, display_cmd=True)

#
# 'syslog' group ('config syslog ...')
#
Expand Down
22 changes: 21 additions & 1 deletion show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2791,9 +2791,29 @@ def zones(verbose):
cmd = "sudo natconfig -z"
run_command(cmd, display_cmd=verbose)

# show features
#
# 'ztp status' command ("show ztp status")
#
@cli.command()
@click.argument('status', required=False, type=click.Choice(["status"]))
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def ztp(status, verbose):
"""Show Zero Touch Provisioning status"""
if os.path.isfile('/usr/bin/ztp') is False:
exit("ZTP feature unavailable in this image version")

if os.geteuid() != 0:
exit("Root privileges are required for this operation")
pass

cmd = "ztp status"
if verbose:
cmd = cmd + " --verbose"
run_command(cmd, display_cmd=verbose)

#
# show features
#
@cli.command('features')
def features():
"""Show status of optional features"""
Expand Down

0 comments on commit a4385f0

Please sign in to comment.