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

SUMMARY 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:

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.