iApp variable scope
Hi all,
I'm writing my first iApp to automate deployment of a few virtual servers, nodes, pools and iRule data-groups
I have finished the presentation section and am now starting on the implementation. One issue that I'm having though is referencing variables assigned from the presentation within tmsh::create, tmsh:modify etc
I can read the variables back fine within the base iApp, for example I have the following:
puts "Adding SNAT data. $::private__privateAddr maps to $::public__publicAddr"
Which logs the following in scriptd.out:
Adding SNAT data. xxx.xxx.xxx.xxx maps to xxx.xxx.xxx.xxx
Where I run into the issue though is referencing the same variables in tmsh::modify.
For example I have the following:
proc tmsh_modify { args } {
set args [join $args]
puts "tmsh modify $args"
tmsh::modify $args
return [lindex $args [lsearch -glob $args "*_*"]]
}
puts "Adding SNAT data. $::private__privateAddr maps to $::public__publicAddr"
tmsh_modify { ltm data-group internal /Common/snat-map
records add {
$::private__privateAddr {
data $::public__publicAddr
}
}
}
This logs the following:
[root@ltm02-dev:Active:Changes Pending] config tail -f /var/tmp/scriptd.out -n0
Adding SNAT data. xxx.xxx.xxx.xxx maps to xxx.xxx.xxx.xxx
tmsh modify ltm data-group internal /Common/snat-map
records add {
$::private__privateAddr {
data $::public__publicAddr
}
}
So from this I can see the variables are being treated as normal strings. As expected this errors out on the iApp creation screen:
script did not successfully complete: ("$::private__privateAddr" invalid address
while executing
"tmsh::modify $args"
(procedure "tmsh_modify" line 4)
invoked from within
"tmsh_modify { ltm data-group internal /Common/snat-map
records add {
$::private__privateAddr {
data $::public__publicAddr
} ..." line:14)
I couldn't find any specific information on the scope of variables when used in this manner, perhaps it is just a simple issue of syntax.
I'd appreciate if someone can give me some guidance on this.
Thanks!
Scope is not the problem. Tcl treats anything inside curly braces as verbatim. Enclosed strings in quotes and escape each curly brace with a backslash.
tmsh_modify "ltm data-group internal /Common/snat-map records add { $::private__privateAddr { data $::public__publicAddr }}"