Use Junos PyEZ to Restore a Junos Device to the Factory-Default State
Use Junos PyEZ to restore a device running Junos OS or a device running Junos OS Evolved to its factory-default configuration settings.
The Junos PyEZ jnpr.junos.utils.sw.SW utility
enables you to reset a Junos device to its factory-default state. The zeroize() method can reset:
-
All Routing Engines in a dual Routing Engine setup
-
The connected Routing Engine on a device running Junos OS
-
Routing Engines with VM host support
-
The connected member switch in a Virtual Chassis or Virtual Chassis Fabric (VCF)
Note: We recommend that you remove and disconnect each member from the Virtual Chassis or VCF, and then zeroize each isolated switch individually.
When you execute the zeroize() method, Junos PyEZ executes the
<request-system-zeroize> RPC on the target host. This
operation removes all configuration information on the target Routing Engines and resets
all key values on the device. The operation unlinks all user-created data files,
including customized configuration and log files, from their directories. The device
then reboots and reverts to the factory-default configuration. After you restore a
device to the factory-default state, you must log in through the console as root in
order to access the device.
For more information about the corresponding operational commands, see:
The following Junos PyEZ application uses the zeroize() method to reset
all Routing Engines on the specified host.
from jnpr.junos import Device from jnpr.junos.utils.sw import SW confirm = input("This application resets hosts to their factory-default state. Enter YES to proceed: ") if (confirm == "YES"): print("Resetting device to factory-default state.") with Device(host='router1.example.net') as dev: sw = SW(dev) rsp = sw.zeroize() print(rsp) else: print ("Canceling zeroize operation.")
How to Specify the Target Routing Engines
By default, the zeroize() method executes the operation on both
Routing Engines in a dual Routing Engine setup. On devices running Junos OS, you
can also perform the operation on just the connected Routing Engine. Junos OS
Evolved and VM hosts, however, always zeroize both Routing Engines, and you
cannot alter this behavior.
To specify the target Routing Engine on a device running Junos OS, include the
all_re parameter. Table 1
summarizes the all_re values.
|
Affected Routing Engines |
|
|---|---|
|
All Routing Engines (default) |
Omit or set to |
|
Only the connected Routing Engine (Junos OS only) |
Set to |
For example, to zeroize all Routing Engines, omit the all_re
argument or explicitly set all_re=True.
from jnpr.junos import Device from jnpr.junos.utils.sw import SW with Device(host='router1.example.net') as dev: sw = SW(dev) sw.zeroize(all_re=True)
On devices running Junos OS, to zeroize only the Routing Engine to which the
application is connected, include the all_re=False
argument.
from jnpr.junos import Device from jnpr.junos.utils.sw import SW with Device(host='router1.example.net') as dev: sw = SW(dev) sw.zeroize(all_re=False)
How to Zeroize 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
zeroize() method supports the vmhost
argument, which enables you to zeroize a VM host. When you include
vmhost=True, the system executes the
<request-vmhost-zeroize> RPC, which corresponds to
the request vmhost zeroize operational mode command.
The following example resets all Routing Engines on the VM Host to their factory-default state.
from jnpr.junos import Device from jnpr.junos.utils.sw import SW with Device(host='switch1.example.net') as dev: sw = SW(dev) sw.zeroize(vmhost=True)
Change History Table
Feature support is determined by the platform and release you are using. Use Feature Explorer to determine if a feature is supported on your platform.
zeroize()
method supports the vmhost argument. Include
vmhost=True to reset Routing Engines with VM Host support
to their factory-default state.