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
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