- play_arrow Disclaimer
- play_arrow Junos PyEZ Overview
- play_arrow Install Junos PyEZ
- play_arrow Connect to and Retrieve Facts From a Device Using Junos PyEZ
- play_arrow Use Junos PyEZ to Manage the Configuration
- Use Junos PyEZ to Retrieve a Configuration
- Use Junos PyEZ to Compare the Candidate Configuration and a Previously Committed Configuration
- Use Junos PyEZ to Configure Junos Devices
- Use the Junos PyEZ Config Utility to Configure Junos Devices
- Use Junos PyEZ to Commit the Configuration
- Example: Use Junos PyEZ to Load Configuration Data from a File
- Example: Use Junos PyEZ to Roll Back the Configuration
- Use Junos PyEZ to Manage the Rescue Configuration on Junos Devices
- play_arrow Create and Use Junos PyEZ Tables and Views
- Understanding Junos PyEZ Tables and Views
- Predefined Junos PyEZ Operational Tables (Structured Output)
- Load Inline or External Tables and Views in Junos PyEZ Applications
- Define Junos PyEZ Operational Tables for Parsing Structured Output
- Define Views for Junos PyEZ Operational Tables that Parse Structured Output
- Use Junos PyEZ Operational Tables and Views that Parse Structured Output
- Define Junos PyEZ Operational Tables for Parsing Unstructured Output
- Define Views for Junos PyEZ Operational Tables that Parse Unstructured Output
- Use Junos PyEZ Tables with TextFSM Templates
- Use Junos PyEZ Operational Tables and Views that Parse Unstructured Output
- Define Junos PyEZ Configuration Tables
- Define Views for Junos PyEZ Configuration Tables
- Use Junos PyEZ Configuration Tables to Retrieve Configuration Data
- Overview of Using Junos PyEZ Configuration Tables to Define and Configure Structured Resources
- Use Junos PyEZ Configuration Tables to Configure Structured Resources on Junos Devices
- Save and Load Junos PyEZ Table XML to and from Files
- play_arrow Troubleshoot Junos PyEZ
Suppress RpcError Exceptions Raised for Warnings in Junos PyEZ Applications
For certain operations in a Junos PyEZ application, you can suppress
RpcError
exceptions that are raised in response to
<rpc-error>
elements that have a severity of warning.
Junos PyEZ enables you to perform operational and configuration tasks on Junos
devices. In a Junos PyEZ application, when you call specific methods or execute
on-demand RPCs, Junos PyEZ sends the appropriate RPCs to the device to perform the
operation or retrieve the requested information. If the RPC reply contains
<rpc-error>
elements with a severity of warning or
higher, the Junos PyEZ application raises an RpcError
exception.
In certain cases, it might be necessary or desirable to suppress the
RpcError
exceptions that are raised in response to warnings.
You can instruct a Junos PyEZ application to suppress RpcError
exceptions that are raised for warnings by including the
ignore_warning
argument in the method call or RPC invocation.
The ignore_warning
argument takes a Boolean, a string, or a list of
strings. You can instruct the device to ignore all warnings or one or more specific
warnings.
You can use the ignore_warning
argument in the following
jnpr.junos.utils.config.Config
class methods:
commit()
diff()
load()
pdiff()
rollback()
You can also use ignore_warning
when you retrieve the configuration
and state data with the get()
RPC.
Ignore All Warnings
To instruct the application to ignore all warnings for an operation or RPC, include
the ignore_warning=True
argument in the method call or RPC
invocation. The following example ignores all warnings for the
load()
and commit()
methods:
from jnpr.junos import Device from jnpr.junos.utils.config import Config dev = Device(host='router1.example.com') dev.open() with Config(dev, mode='exclusive') as cu: cu.load(path='mx-config.conf', ignore_warning=True) cu.commit(ignore_warning=True) data = dev.rpc.get_configuration() print(etree.tostring(data, encoding='unicode')) dev.close()
If you include ignore_warning=True
and all of the
<rpc-error>
elements have a severity of warning, the
application ignores all warnings and does not raise an RpcError
exception. However, any <rpc-error>
elements with higher
severity levels will still raise exceptions.
Ignore Specific Warnings
To instruct the application to ignore specific warnings, set the
ignore_warning
argument to a string or a list of strings
containing the warnings to ignore. When ignore_warning
is set to a
string or list of strings, the string is used as a case-insensitive regular
expression. If a string contains only alphanumeric characters, it results in a
case-insensitive substring match. However, you can include any regular expression
pattern supported by the re
library to match warnings.
The following Junos PyEZ application ignores two specific warnings during the commit
operation. The application suppresses RpcError
exceptions if all of
the <rpc-error>
elements have a severity of warning and each
warning in the response matches one or more of the specified strings.
from jnpr.junos import Device from jnpr.junos.utils.config import Config commit_warnings = ['Advertisement-interval is less than four times', 'Chassis configuration for network services has been changed.'] dev = Device(host='router1.example.com') dev.open() with Config(dev, mode='exclusive') as cu: cu.load(path='mx-config.conf') cu.commit(ignore_warning=commit_warnings) dev.close()