Navigation
Table of Contents
Guide That Contains This Content
[+] Expand All
[-] Collapse All
Script Example
The following is the script to take PIC offline.
A script has four associated attributes, @CONTEXT, @NAME, @DESCRIPTION and @CONFIRMATION. These attributes are given within comments (/* */).
The @CONTEXT attribute states, what context the script can be executed on.
The @NAME attribute defines the descriptive name of the script and @DESCRIPTION defines the description of the script.
The @CONFIRMATION defines the text that should be shown to the user for confirmation before the script gets executed. This is to prevent accidental execution of scripts.
Version 1.0; import "../import/junos.xsl"; import "cim-lib.slax"; /* Junos Space specific context, name and description */ /* @CONTEXT = "/device/chassis-inventory/chassis/chassis-module
[starts-with(name,"FPC")]/chassis-sub-module[starts-with(name,"PIC")]" */ /* @NAME = "Put PIC Offline" */ /* @DESCRIPTION = "Take PIC offline." */ /* @CONFIRMATION = "Are you sure that you want to take the PIC offline?" */ /* @EXECUTIONTYPE = "SINGLEEXECUTION" */ /*@VARIABLECONTEXT="[{'name':'XPATHVARIABLE1','defaultvalue':'mydefaultvalue',
'parameterscope':'devicespecific'},
{'name':'XPATHVARIABLE2','configuredvaluexpath':'/device/interface-information/
physical-interface/name/text()','parameterscope':'entityspecific'},
{'name':'XPATHVARIABLE3','selectionvaluesxpath':'/device/interface-information/
physical-interface/name/text()','parameterscope':'global'}]"*/
/* Global variables */ var $scriptname = "op-pic-offline.slax"; var $results; var $regex; var $result-regex;
var $arguments = {<argument> {<name> "CONTEXT";<description> "The context associated with this script.";}}
param $CONTEXT;
match / {<op-script-results> {var $regex = "/device/chassis-inventory/chassis\\[name=\"(.*)\"\\]/chassis-module\\[name=\"(.*
([0-9]+))\"\\]/chassis-sub-module\\[name=\"(.* ([0-9]+))\"\\]";var $result-regex = jcs:regex( $regex , $CONTEXT );/* Request PIC offline */var $command = {<command> "request chassis pic offline fpc-slot " _
$result-regex[4] _ " pic-slot " _ $result-regex[6];}var $results = jcs:invoke($command);/* Error check */call cim:error-check( $results-to-check = $results , $sev
= "external.error" , $script = $scriptname , $cmd = $command , $log
= "no" );<output> {<HTML> {<HEAD> {<title> "PIC offline";<style type="text/css"> {expr "body { font-family: Verdana, Georgia, Arial, sans-serif;font-size:
12px;color:#fff;}";expr "td { font-family: Verdana, Georgia, Arial, sans-serif;font-size:
12px;color:#fff;}";expr "p { font-family: Verdana, Georgia, Arial, sans-serif;font-size:
12px;color:#fff;}";}}<BODY bgcolor="transparent"> {<p> {copy-of $results;}}}}}}