[Contents] [Prev] [Next] [Index] [Report an Error]

Declaring Arguments in Op Scripts

There are two ways to declare arguments to an op script: with XSLT (or SLAX) instructions in the script or with JUNOS statements in the configuration. Script-generated and configuration-generated arguments have the same operational impact.

To declare arguments within a script, declare a global variable named arguments, containing <argument> tag elements. Within each <argument> tag element, include the required <name> tag element and the optional <description> tag element:

XSLT Syntax

<xsl:variable name="arguments">
    <argument>
        <name>name</name>
        <description>name</description>
    </argument>
</xsl:variable>

SLAX Syntax

var $arguments = {
    <argument> {
        <name> "name";
        <description> "descriptive-text";
    }
}

To declare arguments in the configuration, include the arguments statement in either the [edit system scripts op file filename] hierarchy level (for op scripts) or the [edit event-options event-script file] hierarchy level (for event scripts).

[edit system scripts op file filename]
arguments {
argument-name {
description descriptive-text;
}
}

If you include the optional <description> tag element or the description statement, the text of the description appears in the command-line interface (CLI) as a help-text string to describe the purpose of the argument, as discussed in Configuring Command-Line Help Text.

In the automation script, you must include a corresponding parameter declaration for each argument. The parameter name must match the name of the argument:

<xsl:param name="name"/>

In SLAX, the syntax looks like this:

param $name;

You can create a hidden argument by including the <xsl:param name="name"/> instruction without listing the argument in the arguments variable or in the configuration.

After you declare an argument, you can use command completion to list available arguments:

user@host> op filename ?
Possible completions:
argument-name description
argument-name description

For each argument you include on the command-line, you must specify a corresponding value for the argument. To do this, include an argument-name and an argument-value when you execute the script with the op filename command:

user@host> op filename argument-name argument-value

Note: If you specify an argument that the script does not recognize, the script ignores the argument.

If you configure arguments by including the arguments statement in the configuration, any arguments that you declare directly in the script are still available, but do not appear among the Possible completions when you issue the op filename ? command:

user@host> op filename ?

Possible completions:
...Configuration-generated arguments appear.
...Script-generated arguments are hidden.

If you declare all arguments in the script (and none in the configuration), then the arguments do appear in Possible completions. This is because the management process (mgd) populates the Possible completions list by first checking the configuration for arguments. The management process looks in the script for arguments only if no arguments are found in the configuration. Thus, if arguments are declared in the configuration, the arguments declared in the script become hidden in the CLI.

Example: Declaring Arguments

Declare two arguments named interface and protocol. Execute the script, specifying the ge-0/2/0.0 interface and the inet protocol as values for the arguments. For either method, you must declare corresponding script parameters:

<xsl:param name="interface"/>
<xsl:param name="protocol"/>

Method 1:
In the script1 Op Script

<xsl:variable name="arguments">
    <argument>
        <name>interface</name>
        <description>Name of interface to display</description>
    </argument>
    <argument>
        <name>protocol</name>
        <description>Protocol to display (inet, inet6)</description>
    </argument>
</xsl:variable>

Method 2:
In the Configuration

system { 
    scripts op {
        file script1 {
            arguments {
                interface {
                    description "Name of interface to display";
                }
                protocol {
                    description "Protocol to display (inet, inet6)";
                }
            }
        }
    }
}

Executing the Script

user@host> op script1 interface ge-0/2/0.0 protocol inet

[Contents] [Prev] [Next] [Index] [Report an Error]