Forum Discussion

Chris_Phillips's avatar
Chris_Phillips
Icon for Nimbostratus rankNimbostratus
Feb 23, 2012

single vs multi element classes in irules

 

Howdy,

 

 

 

I wrote a bit of code on 10.2.0 which looped through a class and used scan to extract three variables:

 

 

 

foreach limit_element [class get ${static::limit_prefix}_dgl] {

 

scan $limit_element {%[^ ] %d/%d} limit_uri conn_limit conn_timeout

 

[...]

 

}

 

 

 

etc. With a class with ONE element, this chokes, as the $limit_element value is only the value itself, e.g. "200/1", not the attribute name as well. With MORE elements in the list, it works great, and $limit_element is "/login 200/1" . Similarly this looks to be reflected in bigip.conf contents, as extra brackets exist etc.:

 

 

 

class http_request_limit_dgl {

 

{

 

"/login" { "200/1" }

 

"/sample_uri" { "5/10" }

 

}

 

}

 

 

 

class t1_http_request_limit_dglxx {

 

"/login" { "200/1" }

 

}

 

 

 

Can anyone comment on this?

 

  • If you need to loop through the datagroup to perform an operation with the key or value, you can use a class loop:

    
        Save a class name to search through
       set class_name t1_http_request_limit_dglxx2
    
        Save a search ID for the datagroup
       set id [class startsearch $class_name]
    
        Loop through the class row by row
       while {[class anymore $class_name $id]}{
    
    set element [class nextelement $class_name $id]
    log local0. "\[class nextelement $class_name $id\]: $element"
    
     Perform some operation against the current datagroup key and/or value
    scan $element {%[^ ] %d/%d} a b c
    log local0. "scanned $element: $a, $b, $c"
       }
        Clean up the search
       class donesearch $class_name $id
    

    This works for a single line or multiple line data group. I think the reason your original rule isn't working as expected is that the name and value returned using class get against a single line data group is interpreted as a two element TCL list: {name} {value}, whereas a multiple line data group is interpreted as {name1 value1} {name2 value2}.

    Aaron
  • Yes, absolutely. I think the issue I have is how this is at all acceptable..? It's massively inconsistent.

     

     

    But you say that method will always present the data in a consistent way, whether it's one or more elements on a class? Worth a go... thanks
  • That does seem a bit buggy. If you are interested in finding out more about you could open a case with Support. If you do, can you reply with the case number so I can follow it?

     

     

    The class startsearch option worked as expected though so you should have a workaround.

     

     

    Thanks, Aaron
  • Yep, that does work, thanks for that. I'll see if I can something raised, that does seem pretty bizarre to me.