이 페이지의 내용
예: IS-IS 및 MPLS 인터페이스 제어
이 예는 커밋 스크립트를 사용하여 수동 설정의 양을 줄이는 방법을 보여줍니다.
요구 사항
이 예에서는 Junos OS를 실행하는 디바이스를 사용합니다.
개요 및 커밋 스크립트
인터페이스에서 MPLS를 활성화하려면 및 [edit protocols mpls] 계층 수준에서 모두 [edit interfaces] 변경해야 합니다. 이 예는 커밋 스크립트를 사용하여 수동 설정의 양을 줄이는 방법을 보여줍니다.
이 예제에서는 두 가지 관련 작업을 수행합니다. 인터페이스가 구성되었 [family iso] 지만 구성되지 않은 [family mpls]경우 MPLS를 활성화하기 위해 (템플릿을 사용하 jcs:emit-change 여) 구성을 변경합니다. MPLS는 루프백 인터페이스(loX)에서 유효하지 않으므로 이 스크립트는 루프백 인터페이스를 무시합니다. 둘째, 인터페이스가 계층 수준에서 [edit protocols mpls] 구성되지 않은 경우 인터페이스를 추가하기 위해 변경됩니다. 두 변경 사항 모두 적절한 경고 메시지가 함께 표시됩니다.
예제 스크립트는 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:variable name="mpls" select="protocols/mpls"/> <xsl:for-each select="interfaces/interface[not(starts-with(name,'lo'))] /unit[family/iso]"> <xsl:variable name="ifname" select="concat(../name, '.', name)"/> <xsl:if test="not(family/mpls)"> <xsl:call-template name="jcs:emit-change"> <xsl:with-param name="message"> <xsl:text>Adding 'family mpls' to ISO-enabled interface</xsl:text> </xsl:with-param> <xsl:with-param name="content"> <family> <mpls/> </family> </xsl:with-param> </xsl:call-template> </xsl:if> <xsl:if test="$mpls and not($mpls/interface[name = $ifname])"> <xsl:call-template name="jcs:emit-change"> <xsl:with-param name="message"> <xsl:text>Adding ISO-enabled interface </xsl:text> <xsl:value-of select="$ifname"/> <xsl:text> to [protocols mpls]</xsl:text> </xsl:with-param> <xsl:with-param name="dot" select="$mpls"/> <xsl:with-param name="content"> <interface> <name> <xsl:value-of select="$ifname"/> </name> </interface> </xsl:with-param> </xsl:call-template> </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 {
var $mpls = protocols/mpls;
for-each (interfaces/interface[not(starts-with(name, "lo"))]/unit[family/iso]) {
var $ifname = ../name _ '.' _ name;
if (not(family/mpls)) {
call jcs:emit-change() {
with $message = {
expr "Adding 'family mpls' to ISO-enabled interface";
}
with $content = {
<family> {
<mpls>;
}
}
}
}
if ($mpls and not($mpls/interface[name = $ifname])) {
call jcs:emit-change($dot = $mpls) {
with $message = {
expr "Adding ISO-enabled interface ";
expr $ifname;
expr " to [protocols mpls]";
}
with $content = {
<interface> {
<name> $ifname;
}
}
}
}
}
}
구성
절차
단계별 절차
스크립트를 다운로드, 활성화 및 테스트하려면 다음을 수행합니다.
-
스크립트를 텍스트 파일에 복사하고 파일 이름을 적절하게 iso.xsl 또는 iso.slax 로 지정한 다음 디바이스의 /var/db/scripts/commit/ 디렉터리에 복사합니다.
-
다음 테스트 구성 스탠자를 선택하고 Ctrl+c를 눌러 클립보드에 복사하십시오.
SLAX 버전의 스크립트를 사용하는 경우 계층 수준에서
[edit system scripts commit file]파일 이름을 iso.slax로 변경합니다.system { scripts { commit { file iso.xsl; } } } interfaces { lo0 { unit 0 { family iso; } } so-1/2/3 { unit 0 { family iso; } } so-1/3/2 { unit 0 { family iso; } } } protocols { mpls { enable; } } -
구성 모드에서 명령을 실행
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 .
[edit] user@host# commit [edit interfaces interface so-1/2/3 unit 0] warning: Adding 'family mpls' to ISO-enabled interface [edit interfaces interface so-1/2/3 unit 0] warning: Adding ISO-enabled interface so-1/2/3.0 to [protocols mpls] [edit interfaces interface so-1/3/2 unit 0] warning: Adding 'family mpls' to ISO-enabled interface [edit interfaces interface so-1/3/2 unit 0] warning: Adding ISO-enabled interface so-1/3/2.0 to [protocols mpls] commit complete
명령을 내립니다. show interfaces 루프백 인터페이스가 변경되지 않았으며 SONET/SDH 인터페이스가 변경되었는지 확인합니다.
[edit]
user@host# show interfaces
so-1/2/3 {
unit 0 {
family iso;
family mpls;
}
}
so-1/3/2 {
unit 0 {
family iso;
family mpls;
}
}
lo0 {
unit 0 {
family iso;
}
}