answer=input("WARNING: This is a potentially unsafe function! You may lose the connection to the router or active configuration after running this command. Use it at your own risk! Continue? [y/N]: ")
ifnotanswer.lower()=="y":
logger.error("User aborted command")
returnFalse
# check if another restart process already running
cmd_args_parser.add_argument('--action',choices=['restart'],required=True,help='action to frr daemons')
cmd_args_parser.add_argument('--daemon',choices=['bfdd','bgpd','ospfd','ospf6d','ripd','ripngd','staticd','zebra'],required=False,nargs='*',help='select single or multiple daemons')
# parse arguments
cmd_args=cmd_args_parser.parse_args()
# main logic
# restart daemon
ifcmd_args.action=='restart':
# check if it is safe to restart FRR
ifnot_check_safety():
print("\nOne of the safety checks was failed or user aborted command. Exiting.")
sys.exit(1)
ifnot_write_config():
print("Failed to save active config")
_cleanup()
sys.exit(1)
# a little trick to make further commands more clear
ifnotcmd_args.daemon:
cmd_args.daemon=['']
# check all daemons if they are running
ifcmd_args.daemon!=['']:
ifnot_check_args_daemon(cmd_args.daemon):
print("Warning: some of listed daemons are not running")
# run command to restart daemon
fordaemonincmd_args.daemon:
ifnot_daemon_restart(daemon):
print("Failed to restart daemon: {}".format(daemon))