このページで
例:デュアル ルーティング エンジンの設定
デバイスに冗長( デュアルとも呼ばれる)ルーティングエンジンがある場合、Junos OSの設定は複雑になる可能性があります。この例では、コミット スクリプトを使用して、デュアル ルーティング エンジン プラットフォームの設定を簡素化および制御する方法を示します。
要件
この例では、デュアル ルーティング エンジンを搭載した Junos OS を実行しているデバイスを使用します。
概要とコミット スクリプト
Junos OS は、および という 2 つの特別な設定グループ re0
を re1
サポートしています。ステートメントを使用してこれらのグループを apply-groups [ re0 re1 ]
適用する場合、ルーティング エンジン名がグループ名と一致する場合に有効になります。階層レベルに [edit groups re0]
含まれるステートメントは、RE0という名前のルーティングエンジンでのみ継承され、階層レベルに [edit groups re1]
含まれるステートメントはRE1というルーティングエンジンでのみ継承されます。
この例では、2 つのコミット スクリプトが含まれています。最初のスクリプト dual-re.xsl は、 ステートメント、任意の IP バージョン 4(IPv4)インターフェイス アドレス、または fxp0 インターフェイス設定が設定グループではなくターゲット設定に設定されている場合 system host-name
に警告を生成します。
2 つ目のスクリプト dual-re2.xsl は、まずホスト名構成が構成されているかどうかを確認してから、構成グループ内で構成されているかどうかを確認します。otherwise
ホスト名がまったく構成されていない場合、エラー メッセージが生成されます。最初when
の構成要素では、ホスト名が設定グループに既に設定されている場合、スクリプトは何も実行しません。2 つ目when
の構成要素は、ターゲット構成でホスト名が構成されている場合に有効になります。この場合、このスクリプトでは、ホスト名の設定を および 設定グループに配置しre1
、構成済みのホスト名をグループにre0
コピーし、各グループのホスト名を -RE0
および -RE1
、 と連結して、ターゲット設定のホスト名を無効にして、構成グループのホスト名を継承できるようにする一時変更を生成します。
スクリプトの例は、XSLT と SLAX の両方の構文で示されています。
XSLT 構文:dual-re.xsl スクリプト
<?xml version="1.0" standalone="yes"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:junos="http://xml.juniper.net/junos/*/junos" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm" xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0"> <xsl:import href="../import/junos.xsl"/> <xsl:template match="configuration"> <xsl:for-each select="system/host-name | interfaces/interface/unit/family/inet/address | interfaces/interface[name = 'fxp0']"> <xsl:if test="not(@junos:group) or not(starts-with(@junos:group, 're'))"> <xnm:warning> <xsl:call-template name="jcs:edit-path"> <xsl:with-param name="dot" select=".."/> </xsl:call-template> <xsl:call-template name="jcs:statement"/> <message> <xsl:text>statement should not be in target</xsl:text> <xsl:text> configuration on dual RE system</xsl:text> </message> </xnm:warning> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet>
XSLT 構文:dual-re2.xsl スクリプト
<?xml version="1.0" standalone="yes"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:junos="http://xml.juniper.net/junos/*/junos" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm" xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0"> <xsl:import href="../import/junos.xsl"/> <xsl:template match="configuration"> <xsl:variable name="hn" select="system/host-name"/> <xsl:choose> <xsl:when test="$hn/@junos:group"/> <xsl:when test="$hn"> <transient-change> <groups> <name>re0</name> <system> <host-name> <xsl:value-of select="concat($hn, '-RE0')"/> </host-name> </system> </groups> <groups> <name>re1</name> <system> <host-name> <xsl:value-of select="concat($hn, '-RE1')"/> </host-name> </system> </groups> <system> <host-name inactive="inactive"/> </system> </transient-change> </xsl:when> <xsl:otherwise> <xnm:error> <message>Missing [system host-name]</message> </xnm:error> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
SLAX 構文:dual-re.xsl スクリプト
version 1.0; ns junos = "http://xml.juniper.net/junos/*/junos"; ns xnm = "http://xml.juniper.net/xnm/1.1/xnm"; ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0"; import "../import/junos.xsl"; match configuration { for-each (system/host-name | interfaces/interface/unit/family/inet/address | interfaces/interface[name = 'fxp0']) { if (not(@junos:group) or not(starts-with(@junos:group, 're'))) { <xnm:warning> { call jcs:edit-path($dot = ..); call jcs:statement(); <message> { expr "statement should not be in target"; expr " configuration on dual RE system"; } } } } }
SLAX 構文:dual-re2.xsl スクリプト
version 1.0; ns junos = "http://xml.juniper.net/junos/*/junos"; ns xnm = "http://xml.juniper.net/xnm/1.1/xnm"; ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0"; import "../import/junos.xsl"; match configuration { var $hn = system/host-name; if ($hn/@junos:group) { } else if ($hn) { <transient-change> { <groups> { <name> "re0"; <system> { <host-name> $hn _ '-RE0'; } } <groups> { <name> "re1"; <system> { <host-name> $hn _ '-RE1'; } } <system> { <host-name inactive="inactive">; } } else { <xnm:error> { <message> "Missing [system host-name]"; } } } }
構成
手順
手順
スクリプトをダウンロード、有効化、実行するには、次の手順にしたがっています。
スクリプトを 2 つのテキスト ファイルにコピーし、 dual-re.xsl と dual-re2.xsl または dual-re.slax と dual-re2.slax に名前を付け、デバイス上の /var/db/scripts/commit/ ディレクトリにコピーします。
以下のテスト構成スタンザを選択し、Ctrl+cを押してクリップボードにコピーします。
スクリプトの SLAX バージョンを使用している場合は、 階層レベルのファイル名を
[edit system scripts commit file]
dual-re.slax および dual-re2.slax に変更します。groups { re0 { interfaces { fxp0 { unit 0 { family inet { address 10.0.0.1/24; } } } } } } apply-groups re0; system { host-name router1; scripts { commit { file dual-re.xsl; file dual-re2.xsl; } } } interfaces { fe-0/0/0 { unit 0 { family inet { address 192.168.220.1/30; } } } }
設定モードで、 コマンドを
load merge terminal
発行して、スタンザをデバイス設定にマージします。[edit] user@host# load merge terminal [Type ^D at a new line to end input] ... Paste the contents of the clipboard here ...
プロンプトで、マウスと貼り付けアイコンを使用して、クリップボードの内容を貼り付けます。
Enter キーを押します。
Ctrl+dを押します。
設定をコミットします。
user@host# commit
検証
コミット スクリプトの変更の検証
目的
スクリプトが想定どおりに動作していることを確認します。
アクション
コマンドの出力を commit
確認します。コミット操作が完了すると、デバイスホスト名がルーター1-RE0に変更されます。
[edit] user@host# commit [edit system] 'host-name router1;' warning: statement should not be in target configuration on dual RE system [edit interfaces interface fe-0/0/0 unit 0 family inet] 'address 192.168.220.1/30;' warning: statement should not be in target configuration on dual RE system commit complete