From a4385f00787119c337224f05f757c3f0c1dfb770 Mon Sep 17 00:00:00 2001 From: rajendra-dendukuri <47423477+rajendra-dendukuri@users.noreply.github.com> Date: Wed, 12 Feb 2020 10:40:55 -0500 Subject: [PATCH] ZTP CLI commands (#599) 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 Co-authored-by: Akhilesh Samineni <47657796+AkhileshSamineni@users.noreply.github.com> Co-authored-by: rlhui <48738894+rlhui@users.noreply.github.com> --- config/main.py | 35 +++++++++++++++++++++++++++++++++++ show/main.py | 22 +++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/config/main.py b/config/main.py index 1b017b7ba139..8ef53a66b03f 100755 --- a/config/main.py +++ b/config/main.py @@ -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 ...') # diff --git a/show/main.py b/show/main.py index cb116d20de12..e15dd2465cc0 100755 --- a/show/main.py +++ b/show/main.py @@ -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"""