Forum Discussion
Calling commands by string / reflection
Hi,
Is there any way to call iRule commands by string? For example, can I turn the string "starts_with" into a variable which calls the command 'starts_with'?. I'm trying to make an iRule that interpret strings in a datagroup into commands efficiently, rather than using a bunch of switch statements.
To elaborate, say my iRule has just read a datagroup value, performed a split procedure on it, and returned a list with the values "HTTP::URI" , "starts_with" and "/blah" and then stored them into the variables $a , $b and $c respectively.
I want to be able to do something like
if {[$a $b $c]} and have it be interpreted as though it was 'if {"[HTTP::URI] starts_with /blah"}`.
in c this is called 'reflection', is there an iRule equivalent? http://www.dotnetperls.com/methodinfo-invoke
Thanks.
4 Replies
- Hannes_Rapp
Nimbostratus
Hi,
As far as I'm aware, no. The TCL
command which could otherwise be used for such purpose is excluded from the available iRule commands. Can you perhaps explain a bit what you'd like to do?execDo you want to select a specific pool or initiate a redirect, based on HTTP URI value? It also appears you want to manage all updates via an LTM data-group instead of iRule. Please give a few samples of condition/action in iRule format.
Regards,
- StephanManthey
Nacreous
Hi KingMeow,
I haven´t found a way to concat a comparison as a condition. Using
works fine with commands as demonstrated in this post. If you find a solution to this, please let us know. As Hannes already wrote, there are probably alternative solutions to meet your requirements from functional perspective. Thanks & +1 for the interesting question, Stephaneval - KingMeow_3883
Altostratus
Hi Stephan,
I can confirm you're correct for 11.4.1 at least. I haven't built my iRule exactly but fiddled did a lot of testing. I can turn attributes like
into variables just by setHTTP::uri
. then I can get the command HTTP::uri byx "HTTP::uri"
. Alternatively if I do$x
it returns the value of the HTTP uri.[$x]I even did something like
when HTTP_REQUEST { set a HTTP::header set b "replace" set c "host" set d "new.host.header.value" $a $b $c $d }And the last line actually replaced the host header.
I haven't been able to turn things like "starts_with" into variables though - every approach has resulted in a run time error but I think I've gotten around it by using
for all string matching and leaving it up to the user to enter the correct wildcards into the datagroup that feeds into the iRule.matches_globI think this is pretty much solved but I'll build my iRule when I get a chance again and repost in a couple of days with an update.
I'm quite sure this is going to cut my iRule down to a third of its size at least. Thanks for your help again!
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com