このページで
例:インターフェイス上の内部ゲートウェイプロトコルの設定
このコミットスクリプトの例では、マクロを使用して、 階層レベルで [edit protocols]
インターフェイスを自動的に含め、インターフェイス上に適切な内部ゲートウェイプロトコル(IGP)を設定します。
要件
この例では、Junos OSを実行しているデバイスを使用しています。
概要とコミット スクリプト
OSPF または IS-IS ドメインに新しいインターフェイスを追加する場合、および [edit protocols]
を含む[edit interfaces]
複数の階層レベルでインターフェイスを設定する必要があります。この例では、コミットスクリプトとマクロを使用して、インターフェイス設定に含めるステートメントの内容に応じて、 階層レベルに[edit protocols]
インターフェイスをapply-macro
自動的に含めたり、インターフェイスに適切なIGP(OSPFまたはIS-IS)を設定したりします。このマクロを使用すると、単一の階層レベルでより多くの設定タスクを実行できます。
この例では、Junos OS管理(mgd)プロセスがステートメントを探apply-macro
して設定を検査します。階層レベルに[edit interfaces interface-name unit logical-unit-number]
含まれる各apply-macro ifclass
ステートメントに対して、スクリプトは パラメータがrole
. として定義cpe
されているかどうかをテストします。その場合、スクリプトは パラメーターをigp
確認します。
パラメータが igp
として isis
定義されている場合、スクリプトには 階層レベルの関連するインターフェイス名が [edit protocols isis interface]
含まれます。
パラメータが igp
として ospf
定義されている場合、スクリプトには 階層レベルの関連するインターフェイス名が [edit protocols ospf area address interface]
含まれます。OSPFの場合、スクリプトはパラメータを area
参照して、エリアの正しいサブネットアドレスを決定します。
このスクリプトの例は、XSLT と SLAX の両方の構文で示されています。
XSLT 構文
<?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="interfaces/interface/unit/apply-macro[name = 'ifclass']"> <xsl:variable name="role" select="data[name='role']/value"/> <xsl:variable name="igp" select="data[name='igp']/value"/> <xsl:variable name="ifname"> <xsl:value-of select="../../name"/> <xsl:text>.</xsl:text> <xsl:value-of select="../name"/> </xsl:variable> <xsl:choose> <xsl:when test="$role = 'cpe'"> <change> <xsl:choose> <xsl:when test="$igp = 'isis'"> <protocols> <isis> <interface> <name><xsl:value-of select="$ifname"/></name> </interface> </isis> </protocols> </xsl:when> <xsl:when test="$igp = 'ospf'"> <protocols> <ospf> <area> <name> <xsl:value-of select="data[name='area']/value"/> </name> <interface> <name><xsl:value-of select="$ifname"/></name> </interface> </area> </ospf> </protocols> </xsl:when> </xsl:choose> </change> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:template> </xsl:stylesheet>
SLAX 構文
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 (interfaces/interface/unit/apply-macro[name = 'ifclass']) { var $role = data[name='role']/value; var $igp = data[name='igp']/value; var $ifname = { expr ../../name; expr "."; expr ../name; } if ($role = 'cpe') { <change> { if ($igp = 'isis') { <protocols> { <isis> { <interface> { <name> $ifname; } } } } else if ($igp = 'ospf') { <protocols> { <ospf> { <area> { <name> data[name='area']/value; <interface> { <name> $ifname; } } } } } } } } }
構成
手順
手順
スクリプトをダウンロード、有効化、テストするには、以下の手順にしたがっています。
スクリプトをテキスト ファイルにコピーし、 if-class.xsl または if-class.slax に名前を付け、デバイス上の /var/db/scripts/commit/ ディレクトリにコピーします。
以下のテスト構成スタンザを選択し、Ctrl+cを押してクリップボードにコピーします。
スクリプトの SLAX バージョンを使用している場合は、 階層レベルのファイル名を
[edit system scripts commit file]
if-class.slax に変更します。system { scripts { commit { file if-class.xsl; } } } interfaces { so-1/2/3 { unit 0 { apply-macro ifclass { area 10.4.0.0; igp ospf; role cpe; } } } t3-0/0/0 { unit 0 { apply-macro ifclass { igp isis; role cpe; } } } }
設定モードで、 コマンドを
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
検証
設定の検証
目的
スクリプトが想定どおりに動作していることを確認します。
アクション
構成を表示して、手動による変更とスクリプトによって生成された変更が存在することを確認します。
設定モード コマンドを show interfaces
発行すると、サンプルの設定スタンザによって追加された変更が設定に存在する必要があります。
[edit] user@host# show interfaces t3-0/0/0 { unit 0 { apply-macro ifclass { igp isis; role cpe; } } } so-1/2/3 { unit 0 { apply-macro ifclass { area 10.4.0.0; igp ospf; role cpe; } } }
設定モード コマンドを show protocols
発行すると、スクリプトで生成された変更が設定に存在する必要があります。
[edit] user@host# show protocols isis { interface t3-0/0/0.0; } ospf { area 10.4.0.0 { interface so-1/2/3.0; } }