VCLI -- Bash Configd Client Library
vcli provides a special wrapper to the bash shell that allows seemless access to the Vyatta CLI commands. This shell operates as if it is in configuration mode, with the caveat that one has to setup and teardown sessions before manipulating the candidate data tree.
Invocation
vcli has the following options
$ vcli -h
Invalid option: -h
vcli [ OPTIONS ]
OPTIONS: { -s SID | -c COMMAND | -i | -f FILE | -- SCRIPT_OPTIONS }
-i interactive modeless shell
-s SID configuration session id if not provided uses PID
-c COMMAND one shot command
-f FILE file to run
NOTES:
'-f FILE' is treated as a delimiter for SCRIPT_OPTIONS as well
vcli will read a full script from standard in if no options are provided
Following the 'awk' convention the '#!' for vcli invocation is as follows
#!/bin/vcli -f
Session ID
When invoking vcli one may use the '-s' option to specify the session id to use. by default if no '-s' is provided vcli uses its pid. The '-s' option is useful for connecting to an existing session such as invoking a script from an existing configuration session or for debugging a NETCONF transaction.
Session establishment
If one is not connecting vcli to an existing session then in order to manipulate a candidate configuration one must enter a configuration session.
This is done using the:
configure
command. This will be a persistent session and therefore must be cleaned up when the shell exits or it will persist until the device reboots. This is done with the
command.
Configuration manipulation
The following CLI commands are available in VCLI and function exactly as they do in the Vyatta CLI.
Note: all vcli commands require full configuration paths. The shortest unambiguous match abbreviations do not work since these scripts are meant to be run non interactively.
Additional convenience commands
In addition to the standard CLI commands there are a few additional convenience commands
The
command takes a path and returns its values a space separated list. This is convenient and allows one to programatically walk the configuration tree.
The
and
commands control the way operational commands prompt a user. When noninteractive is run any following operational mode command will not prompt for input but will accept all defaults. When interactive is run it changes back to the normal mode of operation and prompts for input.
Operational commands
Operational commands must be invoked by using the
command as is the case from configuration mode in the Vyatta CLI.
Control structure
All control structures such as conditionals and loops are done using normal bash syntax. This shell simply provides some the required wrappers to enable Vyatta CLI commands to be scriptable. I would refer one to http://wiki.bash-hackers.org/doku.php for an introduction to bash scripting.
Example