Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Use Junos PyEZ to Commit the Configuration

Junos PyEZ enables you to make structured and unstructured configuration changes on Junos devices. After connecting to the device and modifying the configuration, you must commit the configuration to make it active. This topic discusses how to commit the configuration and which commit options are supported in Junos PyEZ applications.

How to Commit the Candidate Configuration

When you use the Junos PyEZ jnpr.junos.utils.config.Config utility to make unstructured configuration changes on a device, you commit the candidate configuration by calling the Config instance commit() method. For example:

To verify the syntax of the configuration without committing it, call the commit_check() method in place of the commit() method.

When you use Junos PyEZ configuration Tables and Views to make structured configuration changes on a device, you commit the candidate configuration by calling either the set() method, which automatically calls the lock(), load(), commit() and unlock() methods, or by calling the various methods individually. For example:

Similarly, you can call the individual methods, as in the following example:

Note:

If you use a context manager to create the Config or Table object and set the mode argument to private, exclusive, dynamic, batch, or ephemeral, you only call the load() and commit() methods to configure the device. The context manager handles opening and locking and closing and unlocking the database, so calls to the lock(), unlock(), or set() methods in one of these modes results in a LockError exception.

How to Specify Commit Options

The Junos CLI provides options for the commit operation, such as adding a commit comment or synchronizing the configuration on multiple Routing Engines. Junos PyEZ supports many of these same commit options and some additional options, which you can use in your Junos PyEZ application by including the appropriate arguments in the commit() or set() method argument list. Table 1 outlines the supported commit options and provides the corresponding CLI command.

Table 1: Junos PyEZ Supported Commit Options

Commit Option Argument

Description

CLI command

comment="comment"

Log a comment for that commit operation in the system log file and in the device’s commit history.

commit comment "comment"

confirm=(True | minutes)

Require that a commit operation be confirmed within a specified amount of time after the initial commit. Otherwise, roll back to the previously committed configuration.

Set the argument to True to use the default time of 10 minutes.

commit confirmed <minutes>

detail=True

Return an XML object with detailed information about the commit process.

commit | display detail | display xml

force_sync=True

Synchronize and commit the configuration on both Routing Engines, even if there are open configuration sessions or uncommitted configuration changes on the other Routing Engine.

commit synchronize force

ignore_warning=True

ignore_warning="string"

ignore_warning=["string1", "string2"]

Ignore warnings that are raised during the commit operation.

Set the argument to True to ignore all warnings, or set the argument to a string or list of strings specifying which warnings to ignore.

sync=True

Synchronize and commit the configuration on both Routing Engines.

commit synchronize

timeout=seconds

Wait for completion of the operation using the specified value as the timeout.

Commit Comment

When you commit the configuration, you can include a brief comment to describe the purpose of the committed changes. To log a comment describing the changes, include the comment parameter and a message string in the commit() or set() method argument list, as appropriate. For example:

Including the comment argument is equivalent to issuing the commit comment configuration mode command in the CLI. The comment is logged to the system log file and included in the device’s commit history, which you can view by issuing the show system commit command in the CLI.

Commit Confirm

To require that a commit operation be confirmed within a specified amount of time after the initial commit, include the confirm=minutes argument in the commit() or set() method argument list, as appropriate.

If the commit is not confirmed within the given time limit, the device automatically rolls back to the previously committed configuration and sends a broadcast message to all logged-in users. The allowed range is 1 through 65,535 minutes. You can also specify confirm=True to use the default rollback time of 10 minutes. To confirm the commit operation, call either the commit() or commit_check() method.

The confirmed commit operation is useful for verifying that a configuration change works correctly and does not prevent management access to the device. If the change prevents access or causes other errors, the automatic rollback to the previous configuration enables access to the device after the rollback deadline passes. If you lose connectivity to the device, you must issue the Junos PyEZ open() method to restore connectivity.

Commit Detail

You can review the details of the entire commit operation by including the detail=True argument in the commit() or set() method argument list. When you include this argument, the method returns an XML object with detailed information about the commit process. The return value is equivalent to the contents enclosed by the <commit-results> element in the output of the commit | display detail | display xml command in the CLI.

Commit Synchronize

If the device has dual Routing Engines, you can synchronize and commit the configuration on both Routing Engines by including the sync=True argument in the commit() or set() method argument list.

When you include the sync=True argument, the device copies the candidate configuration stored on the local Routing Engine to the other Routing Engine, verifies the candidate’s syntactic correctness, and commits it on both Routing Engines. To force the commit synchronize operation to succeed even if there are open configuration sessions or uncommitted configuration changes on the other Routing Engine, use the force_sync=True argument, which causes the device to terminate any configuration sessions on the other Routing Engine before synchronizing and committing the configuration.

Commit and Commit Check Timeout

The default time for an RPC to time out is 30 seconds. Large configuration changes might exceed this value causing a commit or commit check operation to time out before the configuration can be uploaded, checked, and committed. To accommodate configuration changes that might require a commit check or commit time that is longer than the default timeout interval, include the timeout=seconds argument in the commit_check(), commit() or set() method argument list, and set the timeout interval to an appropriate value. For example:

Ignore Warnings

Junos PyEZ raises an RpcError exception when the RPC reply contains <rpc-error> elements with a severity of warning or higher. In cases where it is necessary or desirable to suppress the RpcError exceptions that are raised in response to warnings, you can include the commit() method’s ignore_warning parameter. For example:

For more information about using the ignore_warning parameter, see Suppress RpcError Exceptions Raised for Warnings in Junos PyEZ Applications.