Rebooting a Device Running Junos OS Using Junos PyEZ

 

Performing a Reboot

The Junos PyEZ jnpr.junos.utils.sw.SW utility enables you to reboot a device running Junos OS by executing the reboot() method. You can perform an immediate system reboot, request a reboot with an optional delay, or you can schedule a reboot at a specified date and time. The reboot() method, by default, executes the reboot immediately and reboots all Routing Engines, if in a dual Routing Engine or Virtual Chassis setup.

Note

Starting in Junos PyEZ Release 2.1.0, the reboot() method reboots all Routing Engines in a dual Routing Engine or Virtual Chassis setup. In earlier releases, the reboot() method reboots only that Routing Engine to which the application is connected.

Note

If a Junos PyEZ application reboots a device from a NETCONF-over-SSH session or from a Telnet session through the management interface, the application loses connectivity to the device when it reboots. If the application requires access to the device after the reboot, it must issue the Junos PyEZ open() method to restore connectivity.

The following Junos PyEZ example, which uses Python 3, establishes a NETCONF session over SSH with a device running Junos OS and reboots all Routing Engines, effective immediately.

The application prompts for the device hostname and user credentials. After requesting the system reboot, the application displays the reboot message and the process ID for the process on the connected Routing Engine.

user1@server:~$ python3 junos-pyez-reboot.py

Performing a Reboot with a Delay or at a Specified Time

The reboot() method default behavior is to immediately execute the operation. You can also request a delay before the reboot or you can schedule the reboot at a particular date and time.

To delay the reboot by a specified number of minutes, set the optional in_min parameter to the amount of time in minutes that the system should wait before rebooting. The following example requests a reboot of all Routing Engines in 2 minutes:

The target device issues messages about the impending reboot to any users logged into the system. After the specified amount of time has passed, the system reboots.

To schedule the reboot at a specific time, include the at parameter, which takes a string that can be specified in one of the following ways:

  • now—Stop or reboot the software immediately.

  • +minutes—Number of minutes from now to reboot the software.

  • yymmddhhmm—Absolute time at which to reboot the software, specified as year, month, day, hour, and minute.

  • hh:mm—Absolute time on the current day at which to reboot the software, specified in 24-hour time.

The following example schedules a system reboot of all Routing Engines at 22:30 on the current day:

Specifying the Target for the Reboot

Starting in Junos PyEZ Release 2.1.0, the default for the reboot() method is to reboot all Routing Engines in a dual Routing Engine or Virtual Chassis setup. To reboot only the Routing Engine to which the application is connected, include the all_re=False argument in the method.

Release History Table
Release
Description
Starting in Junos PyEZ Release 2.1.0, the reboot() method reboots all Routing Engines in a dual Routing Engine or Virtual Chassis setup.