Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

close
keyboard_arrow_left
Workspaces User Guide
Table of Contents Expand all
list Table of Contents
file_download PDF
keyboard_arrow_right

Script Example

date_range 26-Apr-22

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.

content_copy zoom_out_map
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;
                    }
                }
            }
        }
    }
}
external-footer-nav
Ask AI
close

How can I help you today?

LLMs can make mistakes. Verify important information.
chat_add_on New topic
send progress_activity
This conversation will be monitored and recorded. Any information you provide will be subject to our Privacy Notice and may be used for quality assurance purposes. Do not include any personal or sensitive information. Ask AI can make mistakes. Verify generated output for accuracy.
Protected by hCaptcha arrow_drop_down arrow_drop_up
Juniper Networks, Inc. | Privacy Notice | Terms of Use