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

Junos PyEZ enables you to perform operational and configuration tasks on devices running Junos OS. 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.

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() method and the get_configuration() RPC:

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.

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. For example, the following Junos PyEZ application ignores two specific warnings during the commit operation:

The Junos PyEZ 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. 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.