|
Scripting can be used for automating complex CLI device configuration tasks. The ScriptHandler is capable of running different types of scripts such as Python, BeanShell, TCL, and others. It can be used to execute single line of script as well as script from a file. The arguments can also be passed to the file, containing the script, during its execution.
The default implementations for launching Python and BeanShell scripts are provided, which can be used to execute the Python and BeanShell scripts. The ScriptHandler also provides an extensive support to plug in custom script interpreter implementations.
The scripting is the utility module that consists of the following classes.
The following diagram explains different stages involved in execution of the Script using CLI.

ScriptHandler
class is used to invoke the scripts for CLI application.
It maintains a list of scripting languages and RunScriptInterface
implementations, as defined in the scripthandler.conf
file under <CLI Home>/conf
directory. The script handler can be used for invoking different scripting
language scripts.
| Method | Purpose |
|---|---|
|
This method can be used to set the script language of the ScriptHandler. | |
|
This method can be used to set the RunScriptInterface implementation class. | |
|
This method can be used to set the RunScriptInterface implementation class for the script type. | |
|
loadScriptProperties(java.lang.String sType, java.util.Properties prop) |
This method can be used to initialize the scriptType with the given properties. |
|
addRunScriptIfcImplClassName(java.lang.String sType, java.lang.String className) |
This method can be used to add a scriptType and its corresponding class dynamically to the already existing list. |
The following code snippet explains how to plug in a script written in BeanShell.
|
ScriptHandler sh = new ScriptHandler(); sh.executeScriptFromFile("test.bsh"); |
For more details, please refer to the Script Handling example application available in Examples chapter.
RunScriptInterface
interface is used to implement script handling
of any scripting language. The interface methods are called by the ScriptHandler class to execute the scripts.
The methods of the interface should be implemented appropriately to execute
the scripts. Hence, any script handling implementation can be plugged
into the ScriptHandler.
Python Scripting Implementation
PythonScriptRunnerImpl
class is used to execute the scripts written in Python.
The Python Interpreter is used to execute the script. This class contains
the following methods.
| Method | Purpose |
|---|---|
|
This method can be used to initialize a list of properties. | |
|
executeScript(java.lang.String scriptFileName, java.lang.String[] args) |
This method can be used to execute a Python script with file name and arguments to be passed to the script. |
|
This method can be used to execute a Python script line by line. |
Python scripts can be launched by filing the PythonScriptRunnerImpl in scripthandler.conf file as given below that is available in <CLI Home>/conf directory.
|
py com.adventnet.util.script.PythonScriptRunnerImpl |
For more details, please refer to the Python Scripting example available in Examples chapter.
BeanShell Scripting Implementation
BeanShellScriptRunnerImpl
class is used to execute the scripts written in BeanShell.
The BeanShell Interpreter is used to execute the script. This class contains
the following methods.
| Method | Purpose |
|---|---|
|
This method can be used to initialize a list of properties. | |
|
executeScript(java.lang.String scriptFileName, java.lang.String[] args) |
This method can be used to execute a BeanShell script with filename and arguments to be passed to the script. |
|
This method can be used to executes a BeanShell script line by line. |
BeanShell scripts can be launched by filing the BeanShellScriptRunnerImpl in scripthandler.conf file as given below that is available in <CLI Home>/conf directory.
|
bsh com.adventnet.util.script.BeanShellScriptRunnerImpl |
For more details, please refer to the BeanShell Scripting example available in Examples chapter.
How to Plug in Scripting Implementation
ScriptHandler API provides an extensive support to plug in any scripting languages. The following procedure can be followed to plug in a custom scripting language:
Provide implementation of RunScriptInterface - Write a class implementing the RunScriptInterface. According to the scripting language interpreter, define executeScript, executeLine, and other methods.
Include an entry for the Scripting language and its implementation class ( the fully qualified class name ) in the scripthandler.conf file present in the <CLI-HOME>/conf directory.
|
|
Note:
|
Please refer to Java documentation for complete details.
|