Forum Discussion

David_Bradley_2's avatar
David_Bradley_2
Icon for Nimbostratus rankNimbostratus
Feb 15, 2007

How do I modify class data from an iRule?

Is there a way to make a change to a class from an irule? For instance, let's say I have:

 

 

class Foobar {

 

"thing1 10"

 

"thing2 20"

 

}

 

 

Now I want to change "thing2 20" to "thing2 30" from within an irule. I can't seem to make this work with any straightforward TCL statements, such as lreplace. I've also tried to add "thing3 30" using lappend. No luck. If there is a way i'm assuming there is some black magic to do this. Help! Thanks.

5 Replies

  • I should mention that I DO actually see the modifications I made to the data when I dump it own from within the iRule. It doesn't show up in the actual class, though. I'm assuming the class is copied into a TCL list when I do an lappend, or lreplace. As such it's only modifying this TCL structure, probably as a global variable. What I really want to do is to be able to make modify class data from within the irule, then read that modified class back out from iControl. When I run my iControl code to read the class data, it shows up as the original, unmodified, data. Thanks.
  • we do stuff like this pretty regularly...usually with banned ip addresses.

     

     

    b class add { thing1 30 }

     

     

    b class delete { thing1 10 }

     

     

     

    There might be some constraints on the format of your class...like for ip addresses instead of just ip addresses in a list, we had to use { host

     

     

     

  • Thanks! Can this be used inside an iRule? I know you can do this in the F5 itself on the command line.
  • Currently there is no way to write to a data group (or class) from within an iRule. You can modify it's local copy but there is no way to flush your changes back to the configuration. What happens is that at rule initialization, the data groups are loaded into internal TCL lists at the global scope. At this point it's just a copy of the original data group in TCL form. There are lots of "gotchas" involved with modifying these lists and then flushing them back into the system specifically related to content format changing.

     

     

    This isn't completely infeasible, but it's just not implemented yet. If you need this ability, I'd recommend you contact product technical support to get it added.

     

     

    With that said, there are some fun things you could do with iRules and iControl to do what you want. You could build a special iRule that handles the HTTP request for a special URL and returns the content directly to the client with an HTTP::respond. Then your client could use that returned data and plug it into an iControl call to update the data group. Kind of hokey but theoretically it should work. You could get into race conditions if an iRule is updates the global list after the download and before the update of the data group by your iControl application so that's something to test and lookout for.

     

     

    If you go that route, let us know how it goes...

     

     

    -Joe
  • Since we're talking theory here, couldn't you log the change, have a syslog-ng filter listening for a keyword in that log statement that would fire off a message to an iControl application which would then update the class?