Forum Discussion
smp_86112
Cirrostratus
Apr 28, 2010v9 matchclass and v10 class match iRule commands
I've got a v9 irule that takes action based on whether or not the client IP address is in a data class. The v9 iRule looks like this:
if { [matchclass [IP::remote_addr] equals $::allow...
hoolio
Cirrostratus
Apr 28, 2010Hey SMP,
Sorry that wasn't very clear. The matchclass command does work in all current versions, so if you're using matchclass in v9, you could continue using it in v10. But as it (and findclass) have been deprecated you could change these commands to the new 'class' command. For any reference to a datagroup in v9.4.4 or higher you should remove the $:: prefix from the datagroup name to ensure the iRule won't break CMP compatibility.
Using TCL list commands like lindex, llength, lsort, etc will not work in v10. If you want to convert the datagroup contents to a TCL list, you can use [class get datagroup_name]. Here are a couple of quick examples:
when HTTP_REQUEST {
This method works but prevents CMP from being used on any VIP the iRule is enabled on
See http://devcentral.f5.com/Wiki/default.aspx/iRules/CMPCompatibility for related info
log local0. "\[class get $::my_test_class\]: [class get $::my_test_class]"
Correct way to retrieve the contents of a datagroup as a TCL list
log local0. "\[class get my_test_class\]: [class get my_test_class]"
Some TCL list commands run against a datagroup which has been retrieved as a TCL list
log local0. "\[llength \[class get my_test_class\]\]: [llength [class get my_test_class]]"
log local0. "\[lindex \[class get my_test_class\] 0\]: [lindex [class get my_test_class] 0]"
This TCL list command example just returns the datagroup name because of the $:: prefix on the datagroup name
log local0. "\[lindex $::my_test_class 0\]: [lindex $::my_test_class 0]"
}
: [class get my_test_class]: {item2 {}} {item1 {}} {item10 {}} {item4 {}}
: [class get my_test_class]: {item2 {}} {item1 {}} {item10 {}} {item4 {}}
: [llength [class get my_test_class]]: 4
: [lindex [class get my_test_class] 0]: item2 {}
: [lindex my_test_class 0]: my_test_class
So long story short: you would do well to replace all matchclass and findclass commands with the new 'class' command equivalents. Remove $:: from any datagroup reference. And replace any TCL list commands that you might have been running directly against a datagroup, like [lindex $::datagroup_name 0], with [lindex [class get datagroup_name] 0].
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
