示例:使用操作脚本重新启动 FPC
此示例使用 操作脚本 重新启动 灵活 PIC 集中器 (FPC)。
要求
此示例使用运行 Junos OS 且包含灵活 PIC 集中器 (FPC) 或等效组件的设备。
概述和操作脚本
以下脚本(以 XSLT 和 SLAX 格式显示)在给定 FPC 所在的插槽编号的情况下重新启动 FPC。调用脚本时,用户在命令行界面 (CLI) 中提供插槽编号。脚本将插槽编号存储为参数 slot 值,并构造 request chassis fpc 命令字符串以包括要重新启动的 FPC 的插槽编号。命令没有 Junos 可扩展标记语言 (XML) 等效 request chassis 项。因此,此脚本直接调用 request chassis fpc 命令,而不是使用 远程过程调用 (RPC)。
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:variable name="arguments">
<argument>
<name>slot</name>
<description>Slot number of the FPC</description>
</argument>
</xsl:variable>
<xsl:param name="slot"/>
<xsl:template match="/">
<op-script-results>
<xsl:variable name="restart">
<command>
<xsl:value-of select="concat('request chassis fpc slot ', $slot,'
restart')"/>
</command>
</xsl:variable>
<xsl:variable name="result" select="jcs:invoke($restart)"/>
<output>
<xsl:text>Restarting the FPC in slot </xsl:text>
<xsl:value-of select="$slot"/>
<xsl:text>. </xsl:text>
<xsl:text>To verify, issue the "show chassis fpc" command.</xsl:text>
</output>
</op-script-results>
</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";
var $arguments = {
<argument> {
<name> "slot";
<description> "Slot number of the FPC";
}
}
param $slot;
match / {
<op-script-results> {
var $restart = {
<command> 'request chassis fpc slot ' _ $slot _ ' restart';
}
var $result = jcs:invoke($restart);
<output> {
expr "Restarting the FPC in slot ";
expr $slot;
expr ". ";
expr "To verify, issue the \"show chassis fpc\" command.";
}
}
}
配置
程序
逐步过程
要下载、启用和测试脚本:
将 XSLT 或 SLAX 脚本复制到文本文件中,根据需要将文件命名为 restart-fpc.xsl 或 restart-fpc.slax ,并将其下载到设备上的 /var/db/script/op/ 目录中。
只有属于 Junos OS
super-user登录类的用户才能访问和编辑此目录中的文件。在配置模式下,在层次结构级别包括语句
[edit system scripts op],并酌情包含filerestart-fpc.xsl 或 restart-fpc.slax。[edit system scripts op] user@host# set file restart-fpc.(slax | xsl)
commit and-quit发出命令以提交配置并返回到操作模式。[edit] user@host# commit and-quit
通过发出
op restart-fpc slot slot-number操作模式命令来执行操作脚本。
验证
验证操作脚本执行
目的
验证 FPC 是否已重新启动,并且当前处于联机状态。
行动
通过发出 op filename 操作模式命令来执行操作脚本。提供 slot FPC 的编号作为参数。
user@host> op restart-fpc slot 0
执行脚本时,应会看到类似于以下内容的输出:
Restarting the FPC in slot 0. To verify, issue the "show chassis fpc" command.
发出 show chassis fpc detail fpc-slot 操作模式命令。
user@host> show chassis fpc detail 0 Slot 0 information: State Online Temperature 36 degrees C / 96 degrees F Total CPU DRAM 1024 MB Total RLDRAM 256 MB Total DDR DRAM 4096 MB Start time: 2009-08-11 21:20:30 PDT Uptime: 0 hours, 1 minutes, 50 seconds Max Power Consumption 335 Watts
意义
命令 show chassis fpc detail 输出显示 FPC 的状态、开始时间、正常运行时间和特性。通过检查 FPC 的启动时间和正常运行时间来验证 FPC 是否已重新启动。通过检查状态来验证重新启动的 FPC 的状态。如果状态为 Present,FPC 即将上线,但尚未联机。如果状态为 Online,FPC 已联机且正在运行。