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 17 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
25 changes: 25 additions & 0 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,5 +380,30 @@ def line(linenum):
cmd = "consutil clear " + str(linenum)
run_command(cmd)

#
# 'nat' group ("clear nat ...")
#

@cli.group(cls=AliasedGroup, default_if_no_args=False)
def nat():
"""Clear the nat info"""
pass

# 'statistics' subcommand ("clear nat statistics")
@nat.command()
def statistics():
""" Clear all NAT statistics """

cmd = "natclear -s"
run_command(cmd)

# 'translations' subcommand ("clear nat translations")
@nat.command()
def translations():
""" Clear all NAT translations """

cmd = "natclear -t"
run_command(cmd)

if __name__ == '__main__':
cli()
43 changes: 42 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import aaa
import mlnx
import nat

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help', '-?'])

Expand Down Expand Up @@ -404,6 +405,7 @@ def _stop_services():
'pmon',
'bgp',
'hostcfgd',
'nat'
]
if asic_type == 'mellanox' and 'pmon' in services_to_stop:
services_to_stop.remove('pmon')
Expand Down Expand Up @@ -432,7 +434,8 @@ def _reset_failed_services():
'snmp',
'swss',
'syncd',
'teamd'
'teamd',
'nat'
]

for service in services_to_reset:
Expand All @@ -455,6 +458,7 @@ def _restart_services():
'pmon',
'lldp',
'hostcfgd',
'nat',
'sflow',
]
if asic_type == 'mellanox' and 'pmon' in services_to_restart:
Expand Down Expand Up @@ -487,6 +491,8 @@ def config():
exit("Root privileges are required for this operation")
config.add_command(aaa.aaa)
config.add_command(aaa.tacacs)
# === Add NAT Configuration ==========
config.add_command(nat.nat)

@config.command()
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
Expand Down Expand Up @@ -2059,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
Loading