Forum Discussion
qqdixf5_74186
Nimbostratus
May 27, 2009v10 class feature
We are migrating our iRules to v10 and need to change the way we access datagroups. First, thank you for the detailed explanation about the new class feature(http://devcentral.f5.com/Default.aspx?tabi...
spark_86682
Jun 03, 2009Historic F5 Account
Given the way the class command currently operates, no. If you look carefully, the vipsForA variable is a list with 3 elements. However, the vipsForB variable is a string with two words in it. When you do an llength of it, it treats it as a list, and gives you the correct answer that there are two items there. (I'm being a little fuzzy here, since Tcl doesn't have strictly typed variables)
There's no super elegant way around this. The best way is probably to make your class key names list elements if they have spaces in them. For your example, that would look like:
class myDataGroup {
{"{vip1_a 123.4.5.6}"}{}
{"{vip2_a 123.4.5.7}"}{}
{"{vip3_a 123.4.5.8}"}{}
{"{vip1_b 123.4.5.9}"}{}
}
Now that I implement this, though, I notice that it is displayed incorrectly in the GUI; I'll file a bug for that shortly. Anyway, this gives you consistent behavior:
set resultA [class names -nocase myDataGroup *_a*]
set resultB [class names -nocase myDataGroup *_b*]
log local0. "resultA: $resultA countA: [llength $resultA]"
log local0. "resultB: $resultB countB: [llength $resultB]"
gives:
resultA: {{vip1_a 123.4.5.6}} {{vip2_a 123.4.5.7}} {{vip3_a 123.4.5.8}} countA: 3
resultB: {vip1_b 123.4.5.9} countB: 1
If you don't want to go that route for whatever reason, then you need to workaround Tcl's "spaces delimit list elements" behavior, and do something like:
set result [class names -nocase myDataGroup *_a*]
if { $result contains "{" } {
set length [llength $result]
} else {
set length 1
}
log local0. "result: $result length: $length"
Hope this helps.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
