NETCONF または XML プロトコルを使用して設定データJunosを置きJunos置き換える
Junos OSリリース15.1R1から、Junos OS replace-pattern <load-configuration> を実行しているデバイスとのNETCONFまたはJunos XMLプロトコル セッションで、操作の実行時に属性を含めて、設定内の変数と識別子を置き換えられます。属性 replace-pattern は、指定されたパターンを、グローバルで、または設定内の指定された階層またはオブジェクト レベルで別のパターンに置き換します。たとえば、この機能を使用して、PICをルーターの別のスロットに移動するときに、インターフェイス名のすべての出現を検索し、交換できます。属性の機能は、属性設定モード replace pattern コマンドの機能と同Junos OS CLI。
置き換えパターン操作は、XMLタグ要素としてフォーマットされた設定Junos使用できます。
パターンを置き換える場合、クライアント アプリケーションは、 および タグ 要素を送信し、「 Junos XML プロトコルを使用する構成要素の作成、変更、削除 」で説明されている基本的な Junos XML タグ要素を含します。<rpc> <load-configuration>パターンを置き換える階層またはオブジェクト レベルには、以下の属性を含める必要があります。
-
replace-pattern—交換するパターン。 -
with—置換パターン。 -
upto—(オプション)置換が必要な出現数。この属性を除外したり、ゼロに設定したりすると、指定した範囲内でパターンのすべてのインスタンスがデバイスで置き換えられます。
以下のセクションで説明するように、設定内に属性を配置すると、置換の範囲が決されます。
設定内でのパターンのグローバルな置き換え
受験者の構成データベースまたはオープン設定データベース全体 replace-pattern でパターンをグローバルに置き換える場合は、開始タグにおよび with 属性を含 <configuration> める。
<rpc>
<load-configuration>
<configuration replace-pattern="pattern1" with="pattern2" [upto="n"]>
</configuration>
</load-configuration>
</rpc>
たとえば、次の RPC は 172.17.1.5 のすべてのインスタンスを 172.16.1.1 に置き換える。
<rpc>
<load-configuration>
<configuration replace-pattern="172.17.1.5" with="172.16.1.1">
</configuration>
</load-configuration>
</rpc>
RPC の実行後、更新された受験者の設定をアクティブな構成と比較して、パターン置換を検証できます。変更を有効にするために設定をコミットする必要があります。
<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>
識別子を持つ階層レベルまたはコンテナ オブジェクト内のパターンの置き換え
replace-pattern withすべての子(または識別子を持つが識別子がないコンテナ オブジェクト)を含む特定の階層レベルの下のパターンを置き換えるには、クライアント アプリケーションに、階層レベルまたはコンテナ オブジェクトを表す空のタグにおよび 属性が含まれます。
<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>
次の RPC は、fe-0/0/1 のインスタンスを階層レベルの ge-1/0/1 に置き [edit interfaces] 換します。
<rpc>
<load-configuration>
<configuration>
<interfaces replace-pattern="fe-0/0/1" with="ge-1/0/1"/>
</configuration>
</load-configuration>
</rpc>
RPC の実行後、更新された受験者の設定をアクティブな構成と比較して、パターン置換を検証できます。例えば:
<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>
識別子を持つ設定オブジェクトのパターンの置換
識別子を持replace-patternwithつ設定オブジェクトのパターンを置き換える場合、クライアント アプリケーションはオブジェクトの開始タグにおよび属性を含み、そのオブジェクトの識別子タグ要素を囲います。次の例では、識別子タグ要素は次のとおりです<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>
次の RPC は、階層の下の fe-0/0/2 [edit interfaces] インターフェイスでのみ、「4.5」のインスタンスを「4.1」に置き換えています。
<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>
RPC の実行後、更新された受験者の設定をアクティブな構成と比較して、パターン置換を検証できます。例えば:
<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>