Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Using Salt to Reboot or Shut Down Devices Running Junos OS

Juniper Networks provides support for using Salt to manage devices running Junos OS, and the Junos execution and state modules (for Salt) define functions that enable you to perform operational and configuration tasks on the managed devices. The salt.modules.junos.shutdown execution function and the salt.states.junos.shutdown state function enable you to use Salt to reboot or power down a device running Junos OS.

This topic discusses how to use Salt to reboot or power down a device running Junos OS, execute the operation after a delay, or schedule the operation at a specific time.

junos.shutdown Function Overview

You can use the junos.shutdown function to request the following operations on devices running Junos OS:

  • An immediate system reboot or shutdown

  • A reboot or shutdown operation with an optional delay

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

By default, the junos.shutdown function executes the requested operation on all Routing Engines, if in a dual Routing Engine or Virtual Chassis setup. The junos.shutdown function requires one argument, which is the action to perform. You must explicitly include either the reboot or the shutdown parameter and set it equal to True.

The salt.modules.junos.shutdown execution function syntax is:

The salt.states.junos.shutdown state function syntax is:

where:

  • at=\'time\'—(Optional) Time at which to schedule the operation.

  • id—User-defined identifier for the state declaration.

  • in_min=minutes—(Optional) Number of minutes to delay the reboot or shutdown operation.

  • (reboot | shutdown)=True—Operation to perform. You must explicitly set either the reboot or the shutdown parameter to True to specify whether to reboot or shut down the device, respectively.

How to Use the junos.shutdown Execution Function

The salt.modules.junos.shutdown execution function enables you to reboot or power down one or more devices running Junos OS from the Salt master command line.

For example, the following command immediately reboots all Routing Engines on the target device:

Similarly, the following command powers down the device:

The following command immediately reboots all devices that match on the os_family:junos grain, which is useful when you want to apply the operation to all managed devices running Junos OS:

How to Use the junos.shutdown State Function

You can use the salt.states.junos.shutdown state function within a Salt state file to reboot or power down one or more devices running Junos OS.

The following state file immediately reboots all Routing Engines on the target devices to which the state is applied:

When you apply the state to the target, the device immediately performs the operation.

Similarly, the following state file powers off the target devices:

How to Perform a Reboot or Shutdown Operation with a Delay

The default behavior of the junos.shutdown function is to immediately execute the reboot or shutdown operation. You can also request a delay before the operation executes.

To delay the reboot or shutdown operation by a specified number of minutes, set the optional in_min parameter to the number of minutes that the target device running Junos OS should wait before executing the operation. The following command requests a reboot of all Routing Engines in 2 minutes:

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

How to Perform a Reboot or Shutdown Operation at a Specified Time

The default behavior of the junos.shutdown function is to immediately execute the reboot or shutdown operation. You can also schedule the operation at a particular date and time. 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—Stop or reboot the software immediately.

  • +minutes—Number of minutes from now to perform the operation.

  • 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.

Note:

The proxy minion server requires Junos PyEZ Release 2.3.0 or later to use the at parameter when you specify shutdown=True.

For example, the following Salt state file schedules a system reboot of all Routing Engines at 22:30 on the current day:

When you apply the state to the target, the device schedules the reboot for the specified time.

You can view the pending reboot on the device with the show system reboot command.

When you execute the same operation on the Salt master command line, Salt passes the CLI input through PyYAML to ensure it is loaded as a proper Python data type. In this case, the at value might be parsed incorrectly. To use the junos.shutdown execution function with the at argument, you can provide the value using one of the following methods: