Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Use Junos PyEZ to Halt, Reboot, or Shut Down Junos Devices

Perform a System Halt, Reboot, or Shut Down

SUMMARY Use Junos PyEZ to halt, reboot, or shut down Junos devices.

The Junos PyEZ jnpr.junos.utils.sw.SW utility provides methods that enable you to perform the following operations on Junos devices:

  • An immediate system halt, reboot, or shutdown

  • A halt, reboot, or shutdown operation with an optional delay

  • A halt, reboot, or shutdown operation scheduled at a specific date and time

Table 1 outlines the available methods. By default, the methods immediately execute the requested operation on all Routing Engines or nodes in the setup. You can include additional arguments to execute the operation at a later time as well as specify the affected Routing Engines or nodes.

Table 1: Junos PyEZ Halt, Reboot, and Power Off Methods

Method

Description

halt()

Gracefully shut down the Junos OS software but maintain system power

poweroff()

Gracefully shut down the Junos OS software and power off the Routing Engines

reboot()

Reboot the Junos OS software

Note:

Starting in Junos PyEZ Release 2.1.0, the reboot() and poweroff() methods perform the requested operation on all Routing Engines in a dual Routing Engine or Virtual Chassis setup. In earlier releases, the methods perform the operation only on the 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 application establishes a NETCONF session over SSH with a Junos device 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.

The following Junos PyEZ example shuts down all Routing Engines on the device, effective immediately.

How to Halt, Reboot, or Shut Down the System with a Delay or at a Specified Time

By default, the halt(), reboot(), and poweroff() methods immediately execute the requested operation. You can also delay the operation or schedule it at a particular date and time.

To delay the operation 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 executing the operation. 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 operation at a specific time, include the at parameter, which takes a string that can be specified in one of the following ways:

  • now—Immediately initiate the halt, reboot, or shut down of the software.

  • +minutes—Number of minutes from now when the requested operation is initiated.

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

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

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

Similarly, the following example schedules all Routing Engines to power off at 22:30 on the current day:

How to Specify the Target Routing Engines or Nodes

By default, the halt(), reboot(), and poweroff() methods perform the requested operation on all Routing Engines in a dual Routing Engine or Virtual Chassis setup and on all nodes on devices running Junos OS Evolved. You can also perform the operation on a specific Routing Engine or node.

To specify the target Routing Engines, you use the all_re and other_re parameters. Table 2 summarizes the all_re and other_re values that are required to execute the requested operation on specific Routing Engines.

Table 2: Parameters to Specify the Target Routing Engines

Affected Routing Engines

all_re Parameter

other_re Parameter

All Routing Engines (default)

Omit or set to True

Only the connected Routing Engine

Set to False

All Routing Engines except the Routing Engine to which the application is connected

Set to True

To explicitly indicate that the operation should be performed on all Routing Engines in a dual Routing Engine or Virtual Chassis setup, include the all_re=True argument, which is the default.

To perform the requested operation on only the Routing Engine to which the application is connected, include the all_re=False argument.

To perform the requested operation on all Routing Engines in the system except for the Routing Engine to which the application is connected, include the other_re=True argument.

To reboot or shut down a specific node of a device running Junos OS Evolved, include the on_node argument, and specify the node. For example:

How to Reboot a VM Host

On devices that have Routing Engines with VM host support, Junos OS runs as a virtual machine (VM) over a Linux-based host (VM host). The Junos PyEZ reboot() method supports the vmhost argument, which enables you to reboot a VM Host. When you include the vmhost=True argument, the system reboots the host OS and compatible Junos OS on all Routing Engines by executing the <request-vmhost-reboot> RPC, which corresponds to the request vmhost reboot operational mode command.

The following example reboots the Routing Engines on the VM Host, which reboots both the guest Junos OS and the host OS.

Release History Table
Release
Description
2.1.0
Starting in Junos PyEZ Release 2.1.0, the reboot() and poweroff() methods perform the requested operation on all Routing Engines in a dual Routing Engine or Virtual Chassis setup.