Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Suppress RpcError Exceptions Raised for Warnings in Junos PyEZ Applications

For certain Junos PyEZ operations, you can suppress RpcError exceptions raised in response to <rpc-error> elements that have a severity level of warning.

Junos PyEZ enables you to perform operational and configuration tasks on devices running Junos OS and devices running Junos OS Evolved. When a Junos PyEZ application calls specific methods or executes 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 level of warning or higher, Junos PyEZ 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. A Junos PyEZ application can suppress these RpcError exceptions 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 include the ignore_warning argument when you:

  • Use the get() RPC to retrieve configuration or state data.

  • Call the following jnpr.junos.utils.config.Config class methods:

    • commit()

    • diff()

    • load()

    • pdiff()

    • rollback()

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:

If you include ignore_warning=True and all of the <rpc-error> elements have a severity level 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.