- play_arrow Overview
- play_arrow Junos XML Management Protocol and Junos XML API Overview
- play_arrow Junos XML Protocol and Junos XML Tags Overview
- XML and Junos OS Overview
- XML Overview
- XML and Junos XML Management Protocol Conventions Overview
- Map Junos OS Commands and Command Output to Junos XML Tag Elements
- Map Configuration Statements to Junos XML Tag Elements
- Using Configuration Response Tag Elements in Junos XML Protocol Requests and Configuration Changes
- play_arrow Junos XML Protocol and JSON Overview
-
- play_arrow Manage Junos XML Protocol Sessions
- play_arrow Junos XML Protocol Session Overview
- play_arrow Manage Junos XML Protocol Sessions
- Satisfy the Prerequisites for Establishing a Connection to the Junos XML Protocol Server
- Configure clear-text or SSL Service for Junos XML Protocol Client Applications
- Connect to the Junos XML Protocol Server
- Start a Junos XML Protocol Session
- Authenticate with the Junos XML Protocol Server for Cleartext or SSL Connections
- Send Requests to the Junos XML Protocol Server
- Parse the Junos XML Protocol Server Response
- Parse Response Tag Elements Using a Standard API in NETCONF and Junos XML Protocol Sessions
- How Character Encoding Works on Juniper Networks Devices
- Handle an Error or Warning in Junos XML Protocol Sessions
- Halt a Request in Junos XML Protocol Sessions
- Lock, Unlock, or Create a Private Copy of the Candidate Configuration Using the Junos XML Protocol
- Terminate a Junos XML Protocol Session
- End a Junos XML Protocol Session and Close the Connection
- Sample Junos XML Protocol Session
- play_arrow Junos XML Protocol Tracing Operations
- play_arrow Junos XML Protocol Operations
- play_arrow Junos XML Protocol Processing Instructions
- play_arrow Junos XML Protocol Response Tags
- play_arrow Junos XML Element Attributes
- active
- count
- delete
- inactive
- insert
- junos:changed
- junos:changed-localtime
- junos:changed-seconds
- junos:commit-localtime
- junos:commit-seconds
- junos:commit-user
- junos:group
- junos:interface-range
- junos:key
- junos:position
- junos:total
- matching
- protect
- recurse
- rename
- replace
- replace-pattern
- start
- unprotect
- xmlns
-
- play_arrow Request Operational and Configuration Information Using the Junos XML Protocol
- play_arrow Request Operational Information Using the Junos XML Protocol
- play_arrow Request Configuration Information Using the Junos XML Protocol
- Request Configuration Data Using the Junos XML Protocol
- Specify the Source for Configuration Information Requests in a Junos XML Protocol Session
- Specify the Output Format for Configuration Data in a Junos XML Protocol Session
- Request Commit-Script-Style XML Configuration Data Using the Junos XML Protocol
- Specify the Output Format for Configuration Groups and Interface Ranges Using the Junos XML Protocol
- Request Identifier Indicators for Configuration Elements Using the Junos XML Protocol
- Request Change Indicators for Configuration Elements Using the Junos XML Protocol
- Specify the Scope of Configuration Data to Return in a Junos XML Protocol Session
- Request the Complete Configuration Using the Junos XML Protocol
- Request a Configuration Hierarchy Level or Container Object Without an Identifier Using the Junos XML Protocol
- Request All Configuration Objects of a Specific Type Using the Junos XML Protocol
- Request a Specific Number of Configuration Objects Using the Junos XML Protocol
- Request Identifiers for Configuration Objects of a Specific Type Using the Junos XML Protocol
- Request a Single Configuration Object Using the Junos XML Protocol
- Request Subsets of Configuration Objects Using Regular Expressions
- Request Multiple Configuration Elements Using the Junos XML Protocol
- Retrieve a Previous (Rollback) Configuration Using the Junos XML Protocol
- Retrieve the Rescue Configuration Using the Junos XML Protocol
- Compare the Active or Candidate Configuration to a Prior Version Using the Junos XML Protocol
- Compare Two Previous (Rollback) Configurations Using the Junos XML Protocol
- Request an XML Schema for the Configuration Hierarchy Using the Junos XML Protocol
-
- play_arrow Junos XML Protocol Utilities
- play_arrow Develop Junos XML Protocol C Client Applications
-
- play_arrow Configuration Statements and Operational Commands
Replace Patterns in Configuration Data Using the NETCONF or Junos XML Protocol
Starting in Junos OS Release 15.1R1, in a NETCONF or Junos XML protocol session with a
device running Junos OS, you can replace variables and identifiers in the configuration by
including the replace-pattern
attribute when performing a
<load-configuration>
operation. The
replace-pattern
attribute replaces the given pattern with another
pattern either globally or at the indicated hierarchy or object level in the configuration.
For example, you can use this feature to find and replace all occurrences of an interface
name when a PIC is moved to another slot in the router. The functionality of the attribute
is identical to that of the replace pattern
configuration mode command in
the Junos OS CLI.
The replace pattern operation can only be used with configuration data formatted as Junos XML tag elements.
To replace a pattern, a client application emits the <rpc>
and
<load-configuration>
tag elements and includes the basic Junos
XML tag elements described in Creating, Modifying, or Deleting 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.
Replacing Patterns Globally Within the Configuration
To globally replace a pattern throughout the candidate
configuration or open configuration database, include the replace-pattern
and with
attributes in the opening <configuration>
tag.
<rpc> <load-configuration> <configuration replace-pattern="pattern1" with="pattern2" [upto="n"]> </configuration> </load-configuration> </rpc>
For example, the following RPC replaces all instances of 172.17.1.5 with 172.16.1.1:
<rpc> <load-configuration> <configuration replace-pattern="172.17.1.5" with="172.16.1.1"> </configuration> </load-configuration> </rpc>
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.
<rpc> <get-configuration compare="rollback" rollback="0" format="text"> </get-configuration> </rpc> <rpc-reply xmlns:junos="http://xml.juniper.net/junos/15.1R1/junos"> <configuration-information> <configuration-output> [edit groups global system ntp] - boot-server 172.17.1.5; + boot-server 172.16.1.1; [edit groups global system ntp] + server 172.16.1.1; - server 172.17.1.5; </configuration-output> </configuration-information> </rpc-reply>
Replacing Patterns Within a Hierarchy Level or Container Object That Has No Identifier
To replace a pattern under a specific hierarchy level
including all of its children (or a container object that has children
but no identifier), a client application includes the replace-pattern
and with
attributes in the empty tag that represents the hierarchy level
or container object.
<rpc> <load-configuration> <configuration> <!-- opening tag for each parent element --> <level-or-object replace-pattern="pattern1" with="pattern2" [upto="n"]/> <!-- closing tag for each parent element --> </configuration> </load-configuration> </rpc>
The following RPC replaces instances of fe-0/0/1 with
ge-1/0/1 at the [edit interfaces]
hierarchy level:
<rpc> <load-configuration> <configuration> <interfaces replace-pattern="fe-0/0/1" with="ge-1/0/1"/> </configuration> </load-configuration> </rpc>
After executing the RPC, you can compare the updated candidate configuration to the active configuration to verify the pattern replacement. For example:
<rpc> <get-configuration compare="rollback" rollback="0" format="text"> </get-configuration> </rpc> <rpc-reply xmlns:junos="http://xml.juniper.net/junos/15.1R1/junos"> <configuration-information> <configuration-output> [edit interfaces] - fe-0/0/1 { - unit 0 { - family inet { - address 10.0.1.1/27; - } - } - } + ge-1/0/1 { + unit 0 { + family inet { + address 10.0.1.1/27; + } + } + } </configuration-output> </configuration-information> </rpc-reply>
Replacing 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, which then encloses
the identifier tag element for that object. In the following example,
the identifier tag element is <name>
:
<rpc> <load-configuration> <configuration> <!-- opening tag for each parent element --> <container-tag replace-pattern="pattern1" with="pattern2" [upto="n"]> <name>identifier</name> </container-tag> <!-- closing tag for each parent element --> </configuration> </load-configuration> </rpc>
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:
<rpc> <load-configuration> <configuration> <interfaces> <interface replace-pattern="4.5" with="4.1"> <name>fe-0/0/2</name> </interface> </interfaces> </configuration> </load-configuration> </rpc>
After executing the RPC, you can compare the updated candidate configuration to the active configuration to verify the pattern replacement. For example:
<rpc> <get-configuration compare="rollback" rollback="0" format="text"> </get-configuration> </rpc> <rpc-reply xmlns:junos="http://xml.juniper.net/junos/15.1R1/junos"> <configuration-information> <configuration-output> [edit interfaces fe-0/0/2 unit 0 family inet] + address 10.0.4.1/30; - address 10.0.4.5/30; </configuration-output> </configuration-information>