Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Replace Patterns in Configuration Data Using the NETCONF or Junos XML Protocol

NETCONF and Junos XML protocol client applications can replace variables and identifiers in the configuration when performing a <load-configuration> operation.

A NETCONF or Junos XML protocol client application can replace variables and identifiers in the configuration of devices running Junos OS or devices running Junos OS Evolved. For example, you might need to replace all occurrences of an interface name when a PIC is moved to another slot in the router.

To replace a pattern, a client application uses the <load-configuration> operation with the replace-pattern attribute. The replace-pattern attribute replaces the existing pattern with the new pattern. The scope of the replacement can be global or at a specified hierarchy or object level in the configuration. The functionality of the replace-pattern attribute is identical to that of the replace pattern configuration mode command in the Junos OS CLI.

Note:

To use the replace pattern operations, you must use Junos XML elements for the configuration data format.

To replace a pattern, a client application emits the <rpc> and <load-configuration> elements and includes the basic Junos XML tag elements described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol. At the hierarchy or object level where you want to replace the pattern, include the following attributes:

  • replace-pattern—Pattern to replace.

  • with—Replacement pattern.

  • upto—(Optional) Number of occurrences to replace. If you omit this attribute or set it to zero, the device replaces all instances of the pattern within the specified scope.

The placement of the attributes within the configuration determines the scope of the replacement as described in the following sections.

Replace Patterns Globally Within the Configuration

To replace a pattern globally throughout the candidate configuration or open configuration database, include the replace-pattern and with attributes in the opening <configuration> tag. You can optionally include the up-to attribute to replace only a specified number of occurrences.

For example, the following RPC replaces all instances of 172.17.1.5 with 172.16.1.1:

After executing the RPC, you can compare the updated candidate configuration to the active configuration to verify the pattern replacement. You must commit the configuration for the changes to take effect.

Replace Patterns Within a Hierarchy Level or Container Object That Has No Identifier

A client application can replace a pattern under a specific hierarchy level including all of its children (or a container object that has children but no identifier). To replace the pattern within a specific hierarchy level, a client application includes the replace-pattern and with attributes in the empty tag that represents the hierarchy level or container object.

The following RPC replaces instances of fe-0/0/1 with ge-1/0/1 at the [edit interfaces] hierarchy level:

Compare the updated candidate configuration to the active configuration to verify the pattern replacement. For example:

Replace Patterns for a Configuration Object That Has an Identifier

To replace a pattern for a configuration object that has an identifier, a client application includes the replace-pattern and with attributes in the opening tag for the object. Within the container tag, the application also includes the identifier element for that object. In the following example, the identifier tag is <name>:

The following RPC replaces instances of 4.5 with 4.1, but only for the fe-0/0/2 interface under the [edit interfaces] hierarchy:

You can compare the updated candidate configuration to the active configuration to verify the pattern replacement. For example: