Dynamically creating static variables per virtual server
Not sure if this is something that can even be done but I can't get it to work.
I'm trying to create an iRule that I can generically use to attach to an undefined number of VIPs and I need to have a "static" variable that is scoped to the virtual server that I'm attached to but not globally. Then have another VIP that will be used to control the variable.
I tried to do something like the following but it doesn't work.
On the controlling VIP (the one I will use to change the variable), let's call it VS-variable-change
call it like
curl http://:/changeVariable?VIPName=VS-variable-test
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/changeVariable" } {
set VIPName [string tolower [URI::query [HTTP::uri] VIPName]]
set varName "static::/Common/${VIPName}_myVar"
log local0. "varName = $varName"
set [subst $varName] 1
log local0. "value = [subst $varName]"
}
}
Then on VS-variable-test I attach the following iRule to try to read this value
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/checkMyVariable" } {
set varName "static::[virtual name]_myVar"
log local0. "varname = $varName"
log local0. "value = [subst $varName]"
}
}
When I call VS-variable-change to change the variable, I get the following output
Rule /Common/irule-var-change : varName = static::/Common/vs-variable-test_myVar
Rule /Common/irule-var-change : value = static::/Common/vs-variable-test_myVar
So I thought it was because I didn't dereference the subst properly, so I changed from
[subst $varName]
to [subst $$varName]
Now I get
Rule /Common/irule-var-change : varName = static::/Common/vs-variable-test_myVar
TCL error: /Common/irule-var-change - can't read "static::": no such variable while executing "subst $$varName"
Is there a way to do this? I'm probably just confused about how to dereference that variable name.
Thanks!