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

ZTP CLI commands #599

Merged
merged 18 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
lguohan marked this conversation as resolved.
Show resolved Hide resolved
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