cli script
cli script(1) BIG-IP TMSH Manual cli script(1)
NAME
script - Automates tmsh using Tool Command Language (Tcl).
MODULE
cli
SYNTAX
Configure the script component within the cli module using the syntax shown in the following sections.
EDIT
create script [name]
modify script [name]
options:
app-service [[string] | none]
description [string]
ignore-verification [true | false]
script-checksum [[string] | none]
script-signature [[string] | none]
edit script [ [ [name] | [glob] | [regex] ] ... ]
options:
all-properties
DISPLAY
list script
list script [ [ [name] | [glob] | [regex] ] ... ]
show running-config script
show running-config script [ [ [name] | [glob] | [regex] ] ... ]
options:
all-properties
DELETE
delete script [name]
GENERATE
Note: generate cryptographic signature or checksum based on cli script text.
generate cli script [name]
options:
checksum
signature
RUN
run script [name] [options ...]
options:
file [file name] [options ...]
verbatim-arguments [file option] [file name] [options ...]
The options that are available depend on which script you are running.
The file option is limited to users with the role of administrator.
DESCRIPTION
You can use the script component to build Tcl scripts to automate management of the BIG-IP(r) system. By combining command
aliases with scripts, you can extend tmsh to build commands that are customized to your environment.
To do this, place the content of the script inside one or more Tcl procedures. The content of a script cannot exceed 65,000
bytes. However, a script can include other scripts. For more information about including scripts in other scripts, see
tmsh::include following.
Starting with BIGIP 11.5.0, tmsh commands are versioned. The tmsh active version should be specified in scripts. This will
avoid breaking scripts due to changes in tmsh syntax in the different versions. See examples below for how to use it in a
script. Without tmsh active version specified, scripts will run on the current active version. By default, the active
version will be the latest cli version.
You can use the following procedures in the manner specified:
script::run
tmsh invokes the procedure script::run when you issue the command sequence run / cli script [name]. A script is run
relative to the module in which the run command is invoked.
The script::run procedure must be defined in the script named by the run command. Scripts that are included by
tmsh::include are not required to implement the procedure script::run.
script::help
Provides context sensitive help. A script is not required to implement script::help.
script::tabc
Provides context sensitive help. A script is not required to implement script::tabc.
script::init
tmsh calls the procedure script::init before calling one of the following procedures: script::run, script::help, or
script::tabc. The script::init procedure can use the Tcl variable tmsh::csh to determine which one of these three
procedures tmsh invokes after tmsh:init.
Additionally, you can use the procedure script::init to initialize global variables. A script is not required to
implement script::init.
EXAMPLES
edit script myscript
Creates or modifies the script myscript.
edit script myscript yourscript
Creates or modifies the scripts myscript and yourscript at the same time.
list script myscript
Displays the contents of the script myscript.
delete script [name]
Deletes the script myscript from the system.
run script myscript [arguments ...]
Runs the script myscript. The system passes arguments to the script in the following Tcl variables:
• tmsh::argc contains the number of arguments including the name of the script.
• tmsh::argv contains the list of argument values. The first item in tmsh::argv is always the name of the script.
Tip: You can create an alias for the command sequence run / cli script [name] using the cli alias component. For more
information, see help cli alias.
run script verbatim-arguments myscript [arguments ...]
Runs the same commands as run script myscript [arguments...] above, except the system passes all arguments specified in the
command as one argument to the script. Note that you do not need to enclose the argument list in double quotes, and you do
not need to escape special characters.
generate my_script checksum
Generate a checksum for the script text and add the checksum as a property.
generate my_script signature signing-key my_key
Generate a signature for the script text using the specified private key and add the signature as a property.
Note: For a script which includes a checksum or signature to successfully load, the script text contents must match the
stored checksum or signature. To temporarily stop the verification of signature or checksum and still retain the checksum
or signature, the ignore-verification attribute must be set to true. This is done by editing the script and adding the
ignore-verification attribute.
To completely clear the signature or checksum, simply set the attribute script-signature or script-checksum to empty string
"". By doing so, the script will be processed as if it was never signed or checksumed.
modify script /Common/my_script { proc script::init {} { }
proc script::run {} { }
proc script::help {} { }
proc script::tabc {} { }
ignore-verification true
script-checksum 74778e7b13016e0b9329a17f8d2da601
total-signing-status checksum
verification-status checksum-verified }
OPTIONS
app-service
Specifies the name of the application service to which the object belongs. The default value is none. Note: If the
strict-updates option is enabled on the application service that owns the object, you cannot modify or delete the
object. Only the application service can modify or delete the object.
checksum
Generate a checksum for the script text and add the checksum to the script as a property. Only for use with the
generate command.
description
A user defined description.
file Specifies that the script to be run should come from a file located on the file system rather than a script from the
configuration.
glob Displays the scripts that match the glob expression. See help glob for a description of glob expression syntax.
name Specifies a unique name for the script. This option is required for the edit and delete commands.
regex
Displays the scripts that match the regular expression. The regular expression must be preceded by an at sign
(@[regular expression]) to indicate that the identifier is a regular expression. See help regex for a description of
regular expression syntax.
signature
Generate a signature for the script text using the specified private key and add the signature to the script as a
property. Only for use with the generate command.
signing-key
The private key to use for signing the script. Only for use with the signature option.
verbatim-arguments
Specifies that the arguments at the end of the command should not be tokenized by tmsh prior to being sent to the
script. This is useful when the script is wrapping another utility that takes arguments.
CONFIGURATION AND STATUS ACCESSORS
The following Tcl commands mirror tmsh commands. For example, the Tcl tmsh::create command accepts the same components,
object identifiers, and properties that the tmsh create command accepts.
tmsh::cd [args...]
Runs the cd command using the specified arguments.
tmsh::cp [args...]
Runs the cp command using the specified arguments.
tmsh::create [args...]
Runs the create command using the specified arguments.
tmsh::delete [args...]
Runs the delete command using the specified arguments.
tmsh::install [args...]
Runs the install command using the specified arguments.
tmsh::generate [args...]
Runs the generate command using the specified arguments.
tmsh::list [args...]
Runs the list command using the specified arguments. The system returns the results as a string.
tmsh::load [args...]
Runs the load command using the specified arguments.
tmsh::modify [args...]
Runs the modify command using the specified arguments.
tmsh::publish [args...]
Runs the publish command using the specified arguments.
tmsh::pwd
Runs the pwd command.
tmsh::reset-stats [args...]
Runs the reset-stats command using the specified arguments.
tmsh::restart [args...]
Runs the command restart using the specified arguments.
tmsh::run [args...]
Runs the run command using the specified arguments.
tmsh::save [args...]
Runs the save command using the specified arguments.
tmsh::show [args...]
Runs the show command using the specified arguments. The system returns the results as a string.
tmsh::start [args...]
Runs the command start using the specified arguments.
tmsh::stop [args...]
Runs the command stop using the specified arguments.
The following Tcl commands provide structured access for retrieving configuration, statistics, and status information.
tmsh::get_config [args...]
Returns a list of Tcl objects. Each of these objects can be passed to the commands that accept an $obj argument. The
arguments for this command are the same as for the tmsh list command.
tmsh::get_status [component] [args...]
Returns a list of Tcl objects that can be passed to the following commands that accept an $obj argument. The arguments
to this command are the same as the tmsh show command.
This command can only be used on components that accept the field-fmt option. The field-fmt option is automatically
appended to the argument list. The tmsh help pages identify if a component supports the field-fmt option.
That there are very few components that have status and statistics that do not support the field-fmt option, and in
those cases you can use the Tcl tmsh::show command to retrieve the object in the form of a Tcl string object.
A component must be specified, for example, tmsh::get_status ltm pool.
tmsh::get_type $obj
Returns the type identifier associated with the object. The $obj argument must be an object that was returned by
either of the Tcl tmsh::get_config or tmsh::get_status commands.
tmsh::get_name $obj
Returns the object identifier associated with the object. The $obj argument must be an object that was returned by
either of the Tcl commands tmsh::get_config or tmsh::get_status.
tmsh::get_field_names [value | nested] $obj
Returns a list of field names (not the value associated with a field) that are present in an object. The value fields
are simple values or lists (for example, an integer or a string). The nested fields are a collection of zero or more
nested objects, where the nested objects have their own fields (for example, pool members, and virtual server
profiles).
The $obj argument must be an object that was returned by the Tcl tmsh::get_config or tmsh::get_status commands. If the
object was retrieved using the Tcl tmsh::get_config command, the field names are identical to those that are displayed
by the tmsh list command. If the object was retrieved using the Tcl tmsh::get_status command, the fields are identical
to those that the system displays using the tmsh show command with the field-fmt option.
tmsh::get_field_value $obj [field name] [Tcl variable]
Retrieves the value of field name.
The Tcl variable is optional. The behavior of this command depends on whether field name is present in $obj and a Tcl
variable is present in the command.
• If field name is present in $obj, and a Tcl variable is present, the Tcl variable is set to the value of field
name and the command returns 1.
• If field name is not present in $obj, and a Tcl variable is present, the command returns 0 (zero).
• If field name is present in $obj, and a Tcl variable is not present, the command returns the field value.
• If field name is not present in $obj, and a Tcl variable is not present, the command raises an error that causes
the script to stop. You can use the Tcl command catch to recognize the error and continue to run the script.
The $obj argument must be an object that was returned by the Tcl tmsh::get_config or tmsh::get_status commands, or a
nested object obtained from the Tcl tmsh::get_field_value command.
If the field is a set of nested objects, the Tcl object that the system returns is a list of objects, where each of
the objects can contain fields. Each of the objects can be passed to the Tcl tmsh::get_field_value command. If the
field is not a nested object the system returns a single Tcl string object.
TRANSACTION CONTROL
The following Tcl commands are specific to the tmsh Tcl API. There are no corresponding commands available in tmsh.
tmsh::begin_transaction
Begins an update transaction. The Tcl tmsh::create, tmsh::delete, and tmsh::modify commands that are issued before the
next Tcl tmsh::commit_transaction command are submitted as a single update.
The system rolls back all of the commands if any of the commands fail.
tmsh::commit_transaction
Runs the commands that have been issued since the last Tcl tmsh::begin_transaction command. The system validates all
of the commands against the running configuration. If any one of the commands fail, the system does not apply any of
the commands to the running configuration.
tmsh::cancel_transaction
Cancels all commands that you have issued since the last Tcl tmsh::begin_transaction command.
Important: You cannot use these Tcl commands inside an active transaction:
• tmsh::list
• tmsh::show
• tmsh::get_config
• tmsh::get_status
LOGGING
You can use the following Tcl commands to generate log events. These commands affect the behavior of the script and do not
affect tmsh. These commands are available only to users who have been assigned either the Administrator or Resource
Administrator role.
tmsh::log_dest [screen | file]
Specifies whether the system sends events to the screen or to log files. If file is selected, log messages will be
directed to /var/log/ltm.
tmsh::log_level [level]
Specifies the default severity level. The system does not log events below the specified level. The options, listed in
decreasing order of severity, are:
• emerg
• alert
• crit
• err
• warning
• notice
• info
• debug
tmsh::log [level] "message..."
Logs the specified message. The level parameter is optional. The level can be one of those described in the Tcl
tmsh::log_level command.
CUSTOM ISTATS
Custom counter, gauge, and string fields may be created, modified, and retrieved using iRules or tmsh scripts. These custom
fields are created on first write and do not need to be declared separately.
Each custom field has a "key" that can be associated with a tmsh configuration object. This key is composed of a tmsh
component dotted path, a specific object name or ID, the field type, and the field name. The entire key must be enclosed in
quotes.
For example, "ltm.pool /Common/my_pool counter num_hits" refers to the num_hits counter associated with the LTM pool named
my_pool, located in the Common folder.
These custom fields are displayed with the tmsh show command on the associated object.
istats::incr [key] [amount]
Increments a custom counter by amount.
istats::set [key] [value]
Sets a custom gauge or string to value. Setting a counter to an exact value will only set it in the local segment, but
istats::get will always read the aggregated (not local) value.
istats::get [key]
Returns the latest aggregated value of the custom field or 0 (zero) if it does not exist ("" for string fields).
istats::remove [key]
Removes the custom field from all segments on all blades. Effectively resets a counter to 0.
UTILITIES
The following commands are TCL utility commands.
tmsh::clear_screen
Clears the screen and places the cursor at the upper left of the screen.
tmsh::display [variable | command output]
Provides access to the tmsh pager. Output generated with the Tcl puts command is not paged.
tmsh::display_threshold [integer]
When a script is run, the system disables the option cli preference display-threshold.
You can use the Tcl tmsh::display_threshold command to re-enable the threshold. Re-enabling the threshold in this way
causes the script to generate a prompt if you issue the tmsh::list, tmsh::show, tmsh::get_config, or tmsh::get_status
commands, and the output that is generated exceeds the threshold. See help cli preference for a description of this
option and valid ranges for its value.
tmsh::expand_macro [macro_text] options...
Expands a macro and returns the resulting string. A macro is a string containing macro syntax which can be used for
parameter substitution, script and iRule templatization, etc. The Macro Syntax includes the following delimiters:
<% The beginning of an expansion code block.
<%= The beginning of an expansion code block. Spool the output after evaluating.
<%D[0-9][0-9] The beginning of a debug/logging code block with the debug threshold set to 0 thru 99.
<%D[0-9][0-9]= The beginning of a debug/logging code block with the debug threshold set to 0 thru 99. Spool the
output after evaluating.
%> The end of the current block (works for all types).
Typically, the result of the expand_macro command is used as the input to another command (eg. ltm rule create). The
command can be called multiple times within an iApp implementation to expand multiple macros.
macro_text is the blob of text to expand. If not specified, the command will expand the Macro section of the iApp. If
no macro_text argument is specified and no Macro section exists for the iApp, an error will be issued.
-vars name_value_pair_list
Specifies a list of additional variables (name/value pairs) which can be referenced within the macro and expanded by
the command. All APL variables are automatically available from within the macro, so the -vars option allows a way to
specify additional variables from the iApp Implementation section. Since the variables are defined within a Tcl list
the format is: { name1 value1 name2 ... nameN valueN }
-debug debug_levels
Specifies a single debug level or list of debug levels for controlling which debug messages get rendered in the
expanded output.
-debuginclusive debug_level
Specifies a debug level for controlling which debug messages get rendered in the expanded output. Since it's
"inclusive" all messages with a level at the specified level and below will get rendered in the expanded output.
The following example expands the macro defined in the Macro section of the iApp, and sets the debug level to render
all debug messages with a level of 11, 33 or 66:
tmsh::expand_macro -debug {11 33 66}
The following example expands the macro defined via a Tcl variable (mac), adds two variables (foo and enable_mything),
and sets the debug level to render all messages of level 66 and below:
tmsh::expand_macro $mac -vars {foo bar enable_mything true} -debuginclusive 66
tmsh::get_ifile_text [iFile name]
Retrieve the text contained in the specified text iFile. When used on an iFile containing characters which are non-
ascii or are not printable/space, an error will be returned.
tmsh::include [script name]
Runs the Tcl eval command on the specified script. The system evaluates the script at a global level, and all
procedures in the included script are available to any other procedure. You must have previously created the script
that is being included using the tmsh edit / cli script [name] command. If a full path is not given for the script
name, tmsh will attempt to first locate the script from the same folder as the including script, then the root
partition folder of the including script, and finally the /Common folder.
tmsh::run_proc [script_name:proc_name] options...]
Runs the Tcl eval command on the specified script and process. The script script_name is loaded as if tmsh::include
was called. After the script is loaded, the Tcl eval command is run on the specified Tcl process. Any options that
were specified are passed to the Tcl process. This is essentially a short form of running tmsh::include script_name,
followed by running one of the Tcl processes contained in the script that was included.
The following example invokes the display_pool_status proc that is contained in the pool_utils script:
tmsh::run_proc pool_utils:display_pool_status
tmsh::stateless [disabled | enabled]
Modifies the behavior of tmsh::create and tmsh::delete.
When stateless mode is disabled, an attempt to create an object that already exists in the configuration results in an
error, and an attempt to delete an object that does not exist in the configuration is an error.
When stateless mode is enabled, an attempt to create an object that already exists in the configuration does not
result in an error, and an attempt to delete an object that does not exist in the configuration does not result in an
error.
Enabling stateless mode enables scripts to successfully run multiple times with the same input.
The default value is disabled.
tmsh::version
Returns the version number of the BIG-IP system as a Tcl string. The version consists of three digits: a major, minor,
and maintenance version, separated by periods. For example, 10.1.0 indicates minor version 1 of major version 10.
CONTEXT SENSITIVE HELP
Use the following commands to create a script that provides context sensitive help when a user types Tab or question mark
(?).
script::help
Scripts can provide the script::help procedure. tmsh invokes the procedure when a user types a question mark (?) while
entering the command sequence run / cli script [name]. If the specified script includes the script::init procedure,
tmsh invokes it before the script::help procedure. The script can add context sensitive help by calling the
tmsh::add_help and tmsh::builtin_help procedures. tmsh formats the help and displays it.
script::tabc
Scripts can provide the script::tabc procedure. The system invokes this procedure when the user types Tab while
entering the command sequence run / cli script. If the script::init procedure is included in the script, that
procedure is invoked before the script::tabc procedure. The script can add tab completion datasets to the script by
calling the tmsh::add_tabc and tmsh::builtin_tabc procedures. tmsh either formats and displays the tab completion
datasets, or if possible, completes the current argument.
tmsh::csh
tmsh::csh is a Tcl string variable that can be used in the script::init procedure to determine the context in which
the script::init procedure was invoked.
tmsh::csh is set to one of the following:
question mark (?)
Indicates that the user typed a question mark (?).
TABC Indicates the user pressed the Tab key.
an empty string ""
Indicates the script is being run.
tmsh::add_help [ [category item description] | [description] ]
Displays context sensitive help when the user types a question mark (?). If you supply one argument, that argument
displays as-is with no formatting applied to the description.
If you supply three arguments, one or more datasets are constructed. The first argument is the name of the dataset.
The second argument is an item in the dataset. The third argument is a description of the item. This command has an
effect only if the Tcl tmsh::csh variable is set to question mark (?).
tmsh::builtin_help ["tmsh command" args...]
Presents the same results as typing a question mark (?) while entering a tmsh command. The system stores a set of
possible completions and displays the possibilities when the script::help procedure returns. This command has an
effect only if the Tcl tmsh::csh variable is set to question mark (?).
tmsh::add_tabc [ [category item] | [item] ]
Adds tab completion datasets. If you supply one argument, the system adds that argument to an anonymous dataset. If
you supply two arguments, the system constructs one or more datasets. The first argument is the name of the dataset.
The second argument is an item in the dataset. Potential completions are displayed in groups based on category. This
command has an effect only if the Tcl $tmsh::csh variable is set to TABC.
tmsh::builtin_tabc ["tmsh command" args...]
Many of the tmsh commands that are available for scripting are also available in the interactive shell. A script can
use the tmsh::builtin_tabc command to present the same tab completion results as a built-in command. The command does
not return a value. The set of possible completions are stored internally and displayed when the script::tabc
procedure returns. This command has an effect only if the Tcl $tmsh::csh variable is set to TABC.
THIRD PARTY TCL LIBRARY USAGE
A selection of third party libraries have been tested to work within the CLI script environment, including MD5, BASE64,
SHA1/SHA256, HTTP, TLS, TCL Perl, LDAP client, and XML parser. The TCL packages can only reside in the directory of
/usr/share/compat-tcl8.4.
Important: Only these tested packages are supported currently.
This example demonstrates the use of a Tcl package command to make use of tls/https. The TLS package is installed in the
directory /usr/share/compat-tcl8.4/tls in the form of two files: tls.tcl and libtls1.6.1.so.
Modify script /Common/use_tls {
proc script::run {} {
set pkg_name tls
set pkg_version 1.6
package require http
if {[catch {package require $pkg_name pkg_version}]} {
puts "No package found: $pkg_name!\n"
} else {
puts "Found package: $pkg_name!\n"
http::register https 443 tls::socket
set token [http::geturl https://172.27.42.161/]
upvar #0 $token state
puts $state(http)
puts $state(body)
}
}
}
This example uses the callback function to handle http data.
cli script /Common/use_http2 {
proc script::httpCallback {token} {
upvar #0 $token state
puts $state(http)
puts $state(body)
incr ::got_something
}
proc script::run {} {
namespace eval :: {
set got_something 0
}
set pkg_name http
set pkg_version 2.4.5
if {[catch {package require $pkg_name $pkg_version}]} {
puts "No package found: $pkg_name!\n"
} else {
puts "Found package: $pkg_name!\n"
http::geturl http://172.27.42.22/index.htm -command script::httpCallback
vwait ::got_something
}
}
}
This example uses the LDAP client package to query data.
cli script /Common/use_ldap {
proc script::run {} {
set pkg_name ldap
if {[catch {package require $pkg_name 1.8}]} {
puts "No package found: $pkg_name!\n"
} else {
puts "Found package: $pkg_name!\n"
set handle [ldap::connect 172.27.1.2]
ldap::bind $handle
set results [ldap::search $handle "dc=f5,dc=com" "(uid=test)" {}]
foreach result $results {
puts $result
}
ldap::unbind $handle
ldap::disconnect $handle
}
}
}
Here are some additional examples:
cli script /Common/use_parray {
proc script::run {} {
puts [info patch]
namespace eval :: {
set pkg_location /usr/share/compat-tcl8.4/
source [file join $pkg_location package.tcl]
}
puts "NS: [namespace current]"
set pkg_location $::pkg_location
source [file join $pkg_location parray.tcl]
parray ::tcl_platform
}
}
cli script /Common/use_sha2 {
proc script::run {} {
set pkg_name sha256
if {[catch {package require $pkg_name}]} {
puts "No package found: $pkg_name!\n"
} else {
puts "Found package: $pkg_name!\n"
puts "TCL does SHA2 now:"
puts [sha2::sha256 "TCL does SHA2"]
}
}
}
cli script /Common/use_tclperl {
proc script::run {} {
set pkg_name tclperl
if {[catch {package require $pkg_name}]} {
puts "No package found: $pkg_name!\n"
} else {
puts "Found package: $pkg_name!\n"
set interpreter [perl::interp new]
$interpreter eval {print "Hello World\n"}
perl::interp delete $interpreter
}
}
}
SPECIAL CHARACTERS
There are several characters that are part of both Tcl and tmsh syntax. You must escape these characters in a shell script
so that Tcl passes them to tmsh. You can use standard Tcl escape characters, such as quotes and back slashes. You must
escape curly braces ({ }), for example, "{" "}".
tmsh::create ltm pool my_pool members add "{ 10.1.2.3:80 }"
Creates a Local Traffic Manager pool named my_pool.
DISABLED COMMANDS
The following commands are disabled for users that have not been assigned a user role of Administrator or Resource
Administrator:
• auto_execok
• auto_import
• auto_load
• auto_mkindex
• auto_mkindex_old
• auto_qualify
• auto_reset
• bgerror
• cd
• close
• eof
• exec
• fblocked
• fconfigure
• fcopy
• file
• filevent
• filename
• flush
• glob
• http
• interp
• load
• memory
• open
• package
• pid
• pkg:create
• pkg_mkindex
• pwd
• seek
• socket
• source
• tcl_findLibrary
• tell
• unknown
• updates
• vwait
EXAMPLES
The following example demonstrates the use of all tmsh Tcl commands. The script displays all configuration property values
or all status and statistic values for the specified component, depending on the specified arguments. The system displays
all configuration settings if you replace [tmsh::get_config $comp all-properties] with [tmsh::get_config / all-properties].
The use of the all-properties option ensures that all options are displayed.
This command sequence is an example of how to run the following script: run / cli script example.tcl config ltm pool.
cli script example.tcl {
proc script::init { } {
set ::field_fmt "%-25s %s"
set ::usage_string "usage: [lindex $tmsh::argv 0] \
"
}
proc script::help { } {
if { $tmsh::argc < 2 } {
tmsh::add_help Options: config "Display configuration"
tmsh::add_help Options: status \
"Display status and statistics"
}
else {
build_csh tmsh::builtin_help
}
}
proc script::tabc { } {
if { $tmsh::argc < 2 } {
tmsh::add_tabc config
tmsh::add_tabc status
}
else {
build_csh tmsh::builtin_tabc
}
}
proc script::run { } {
if { $tmsh::argc < 3 } {
usage
}
set opt [lindex $tmsh::argv 1]
if { $opt != "config" && $opt != "status" } {
usage
}
set comp ""
for {set idx 2} {$idx < $tmsh::argc} {incr idx} {
append comp "[lindex $tmsh::argv $idx] "
}
if { $opt == "config" } {
set objs [tmsh::get_config $comp all-properties]
}
else {
set objs [tmsh::get_status $comp]
}
set idx 0
set total [llength $objs]
while { $idx < $total } {
set obj [lindex $objs $idx]
print_object obj
puts ""
incr idx;
}
}
proc print_fields { objVar } {
upvar $objVar obj
set fdx 0
set fields [tmsh::get_field_names value $obj]
set field_count [llength $fields]
while { $fdx < $field_count } {
set field [lindex $fields $fdx]
puts [format $::field_fmt $field \
[tmsh::get_field_value $obj $field]]
incr fdx
}
}
proc print_object { objVar } {
upvar $objVar obj
puts "[tmsh::get_type $obj] [tmsh::get_name $obj]"
# name/value pairs
print_fields obj
# nested objects
set fdx 0
set fields [tmsh::get_field_names nested $obj]
set count [llength $fields]
while { $fdx < $count } {
set field [lindex $fields $fdx]
set nested_objects [tmsh::get_field_value $obj $field]
set ndx 0
set n_count [llength $nested_objects]
while { $ndx < $n_count } {
set nobj [lindex $nested_objects $ndx]
print_object nobj
incr ndx
}
if {$n_count == 0 } {
puts [format $::field_fmt $field "none"]
}
incr fdx
}
}
proc build_csh { command } {
# generate context sensitive help, tab completion or "?"
set args ""
for {set idx 2} {$idx < $tmsh::argc} {incr idx} {
lappend args [lindex $tmsh::argv $idx]
}
set opt [lindex $tmsh::argv 1]
if { $opt == "config" } {
$command list $args
}
elseif { $opt == "status" } {
$command show $args
}
else {
puts "\nunexpected argument: $opt"
}
return $args
}
proc usage { } {
puts $::usage_string
exit
}
}
EXAMPLES
The following example demonstrates the scripts using 11.6.0 tmsh syntax.
cli script example_ver.tcl {
...
proc script::run {} {
tmsh::modify cli version active 11.6.0
# the tmsh command in the section below should contain 11.6.0 tmsh syntax
puts stdout [tmsh::list ltm pool mypool]
...
}
}
The following example demonstrates the scripts that are using multiple tmsh syntaxes.
cli script example_multi_ver.tcl {
....
proc script::run {} {
tmsh::modify cli version active 11.5.0
# the tmsh command in the section below should contain 11.5.0 tmsh syntax
puts stdout [tmsh::list ltm pool mypool]
...
tmsh::modify cli version active 11.6.0
# the tmsh command in the section below should contain 11.6.0 tmsh syntax
puts stdout [tmsh::list ltm pool mypool]
...
}
}
SEE ALSO
cli alias, create, delete, edit, glob, list, modify, regex, reset-stats, show, tmsh and generate.
For complete information about tmsh, see the Traffic Management Shell (tmsh) Reference Guide. This guide is available on
the Ask F5(sm) Knowledge Base (www.askf5.com).
For information about Tcl, see www.tcl.tk.
COPYRIGHT
No part of this program may be reproduced or transmitted in any form or by any means, electronic or mechanical, including
photocopying, recording, or information storage and retrieval systems, for any purpose other than the purchaser's personal
use, without the express written permission of F5 Networks, Inc.
F5 Networks and BIG-IP (c) Copyright 2009-2016. All rights reserved.
BIG-IP 2016-03-14 cli script(1)