이 페이지의 내용
예: Require 및 Restrict 구성 문
Junos OS 커밋 스크립트는 사용자 지정 구성 규칙을 적용합니다. 후보 구성이 커밋되면 각 활성 커밋 스크립트에 의해 검사됩니다. 이 예에서는 커밋 스크립트를 사용하여 필수 및 금지된 구성 문을 지정합니다.
요구 사항
이 예에서는 이더넷 관리 인터페이스 fxp0이 있는 Junos OS를 실행하는 디바이스를 사용합니다.
개요 및 커밋 스크립트
이 예에서는 커밋 스크립트를 사용하여 필수 및 금지된 구성 문을 지정하는 방법을 보여줍니다. 다음 커밋 스크립트는 이더넷 관리 인터페이스(fxp0)가 구성되었는지 확인하고 인터페이스가 부적절하게 비활성화된 시점을 감지합니다. 또한 스크립트는 문이 계층 수준에 포함되지 않은 경우에도 bgp
감지합니다 [edit protocols]
. 모든 경우에 스크립트가 오류 메시지를 생성하고 커밋 작업이 실패합니다.
예제 스크립트는 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:call-template name="error-if-missing"> <xsl:with-param name="must" select="interfaces/interface[name='fxp0']/ unit[name='0']/family/inet/address"/> <xsl:with-param name="statement" select="'interfaces fxp0 unit 0 family inet address'"/> </xsl:call-template> <xsl:call-template name="error-if-present"> <xsl:with-param name="must" select="interfaces/interface[name='fxp0']/disable | interfaces/interface[name='fxp0']/ unit[name='0']/disable"/> <xsl:with-param name="message"> <xsl:text>The fxp0 interface is disabled.</xsl:text> </xsl:with-param> </xsl:call-template> <xsl:call-template name="error-if-missing"> <xsl:with-param name="must" select="protocols/bgp"/> <xsl:with-param name="statement" select="'protocols bgp'"/> </xsl:call-template> </xsl:template> <xsl:template name="error-if-missing"> <xsl:param name="must"/> <xsl:param name="statement" select="'unknown'"/> <xsl:param name="message" select="'missing mandatory configuration statement'"/> <xsl:if test="not($must)"> <xnm:error> <edit-path><xsl:copy-of select="$statement"/></edit-path> <message><xsl:copy-of select="$message"/></message> </xnm:error> </xsl:if> </xsl:template> <xsl:template name="error-if-present"> <xsl:param name="must" select="1"/> <!-- error if param missing --> <xsl:param name="message" select="'invalid configuration statement'"/> <xsl:for-each select="$must"> <xnm:error> <xsl:call-template name="jcs:edit-path"/> <xsl:call-template name="jcs:statement"/> <message><xsl:copy-of select="$message"/></message> </xnm:error> </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 { call error-if-missing($must = interfaces/interface[name='fxp0']/unit[name='0']/family/inet/address, $statement = 'interfaces fxp0 unit 0 family inet address'); call error-if-present($must = interfaces/interface[name='fxp0']/disable | interfaces/interface[name='fxp0']/unit[name='0']/disable) { with $message = { expr "The fxp0 interface is disabled."; } } call error-if-missing($must = protocols/bgp, $statement = 'protocols bgp'); } error-if-missing ($must, $statement = 'unknown', $message = 'missing mandatory configuration statement') { if (not($must)) { <xnm:error> { <edit-path> { copy-of $statement; } <message> { copy-of $message; } } } } error-if-present ($must = 1, $message = 'invalid configuration statement') { for-each ($must) { <xnm:error> { call jcs:edit-path(); call jcs:statement(); <message> { copy-of $message; } } } }
구성
절차
단계별 절차
스크립트를 다운로드, 사용 및 테스트하려면:To download, enable, and test the script:
스크립트를 텍스트 파일로 복사하고, 파일 이름을 no-nukes.xsl 또는 no-nukes.slax 로 적절하게 지정한 다음, 디바이스의 /var/db/scripts/commit/ 디렉터리에 복사합니다.
다음 테스트 구성 스탠자를 선택하고 Ctrl+c를 눌러 클립보드에 복사하십시오.
스크립트의 SLAX 버전을 사용하는 경우 계층 수준에서 파일 이름을
[edit system scripts commit file]
no-nukes.slax로 변경합니다.system { scripts { commit { file no-nukes.xsl; } } } interfaces { fxp0 { disable; unit 0 { family inet { address 10.0.0.1/24; } } } }
구성 모드에서 명령을 실행하여
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
출력을 검토합니다. 이 스크립트를 사용하려면 이더넷 관리 인터페이스(fxp0)가 구성 및 활성화되어야 하며 bgp
명령문이 계층 수준에 포함되어야 [edit protocols]
합니다. 샘플 구성 스탠자는 fxp0 인터페이스를 포함하지만 비활성화합니다. 또한 bgp
문은 계층 수준에서 구성 [edit protocols]
되지 않습니다. 스크립트를 실행하면 오류가 발생하고 커밋 작업이 실패합니다. 명령을 실행한 후 다음 출력이 나타납니다.commit
[edit] user@host# commit [edit interfaces interface fxp0 disable] 'disable;' The fxp0 interface is disabled. protocols bgp missing mandatory configuration statement error: 2 errors reported by commit scripts error: commit script failure