このページの目次
例:T1 インターフェイスで内部クロッキングが必要
この例では、コミット スクリプトを使用して、T1 インターフェイスに内部クロッキングの設定を要求する方法を示します。
要件
この例では、T1インターフェイスを備えたJunos OSを実行するデバイスを使用します。
概要とコミット スクリプト
このコミット スクリプトにより、T1 インターフェイスは内部クロッキングを使用するように明示的に設定されます。ステートメントが clocking コンフィギュレーションに含まれていない場合、または clocking external ステートメントが含まれている場合、エラー メッセージが生成され、コンフィギュレーションはコミットされません。
スクリプトの例は、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[starts-with(name, 't1-')]"> <xsl:variable name="clock-source"> <xsl:value-of select="clocking"/> </xsl:variable> <xsl:if test="not($clock-source = 'internal')"> <!-- or xsl:if test="$clock-source != 'internal'" --> <xnm:error> <xsl:call-template name="jcs:edit-path"/> <xsl:call-template name="jcs:statement"> <xsl:with-param name="dot" select="clocking"/> </xsl:call-template> <message> This T1 interface should have internal clocking. </message> </xnm:error> </xsl:if> </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[starts-with(name, 't1-')]) {
var $clock-source = {
expr clocking;
}
if (not($clock-source = 'internal')) {
<xnm:error> {
call jcs:edit-path();
call jcs:statement($dot = clocking);
<message> "This T1 interface should have internal clocking.";
}
}
}
}
構成
手順
手順
スクリプトをダウンロード、有効化、およびテストするには:
スクリプトをテキストファイルにコピーし、必要に応じてファイルに clocking-error.xsl または clocking-error.slax という名前を付けて、デバイスの /var/db/scripts/commit/ディレクトリ にコピーします。
以下のテスト構成スタンザを選択し、Ctrl+c を押してクリップボードにコピーします。
SLAX バージョンのスクリプトを使用している場合は、階層レベルのファイル名
[edit system scripts commit file]を clocking-error.slax に変更します。system { scripts { commit { file clocking-error.xsl; } } } interfaces { t1-0/0/0 { clocking external; } t1-0/0/1 { unit 0; } }設定モードで、 コマンドを発行
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 ...
プロンプトで、マウスと貼り付けアイコンを使用して、クリップボードの内容を貼り付けます。
実行キーを押します。
Ctrl+dを押します。
設定をコミットします。
user@host# commit
検証
コミット スクリプトの実行の検証
目的
スクリプトが期待どおりに動作することを確認します。
アクション
コマンドの出力 commit を確認します。サンプル設定スタンザでは、2つのT1インターフェイスt1-0/0/0とt1-0/0/1を設定します。インターフェイスt1-0/0/0は ステートメントで clocking external 設定されていますが、インターフェイスt1-0/0/1にはステートメントが含まれていません clocking 。スクリプトはエラーを生成し、コミット操作は失敗します。コマンドを発行 commit すると、次の出力が表示されます。
[edit] user@host# commit [edit interfaces interface t1-0/0/0] 'clocking external;' This T1 interface should have internal clocking. [edit interfaces interface t1-0/0/1] ';' This T1 interface should have internal clocking. error: 2 errors reported by commit scripts error: commit script failure