Forum Discussion

tidenz_92110's avatar
tidenz_92110
Icon for Nimbostratus rankNimbostratus
Jun 16, 2010

irule data class reference issues 9.4.x to 10.1

Hi Guys,

 

 

We recently have migrated to v10.1 from 9.4.7 and we have broken our existing irule. The part that is braking is parsing the data class into an array for processing.

 

 

when debugging i see that the data class name is added into the array not the actual index and value.

 

 

reading through the new class commands in v10.x i need to remove the $::data group as this what is causing the name of the data group to be entered.

 

 

I have changed it but i still see the same output in the debug string.

 

 

log local0.debug "Adding $index --> $data"

 

Jun 16 15:51:14 Rule EP-cms-nz-http-ir : Adding URL_REWRITE_NZ_LIST -->

 

 

Any ideas?

 

 

 

when RULE_INIT {

 

 

set this to 1 to enable maintenance

 

set ::MAINTENANCE 0

 

 

array unset ::ARRAY_REWRITE_NZ

 

array set ::ARRAY_REWRITE_NZ { }

 

array unset ::ARRAY_REDIRECT_NZ

 

array set ::ARRAY_REDIRECT_NZ { }

 

set ::SERIAL1 0

 

set ::SERIAL2 0

 

set ::REQ_COUNT 0

 

 

log local0.debug "-------- RULE INIT -------------"

 

if { [findclass "serial" $::URL_REWRITE_NZ_LIST "|"] != $::SERIAL1 }{

 

clear contents of previous mem resident table

 

array unset ::ARRAY_REWRITE_NZ

 

set ::SERIAL1 [findclass "serial" $::URL_REWRITE_NZ_LIST "|"]

 

 

log local0.debug "RELOADING UPDATED URI REWITE CLASS TO MEMORY"

 

 

foreach item $::URL_REWRITE_NZ_LIST {

 

set index [findstr $item "" 0 "|"]

 

set data [findstr $item "|" 1 "\n"]

 

set LIST "$index $data"

 

set ::ARRAY_REWRITE_NZ($index) $data

 

log local0.debug "Adding $index --> $data"

 

}

 

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    In 10.x, you can no longer directly access a datagroup as a TCL list. For the same functionality, you can use [class get my_class]:

    
    when RULE_INIT {
    
        set this to 1 to enable maintenance 
       set ::MAINTENANCE 0
    
       
       array unset ::ARRAY_REWRITE_NZ
       array set ::ARRAY_REWRITE_NZ { }
       array unset ::ARRAY_REDIRECT_NZ
       array set ::ARRAY_REDIRECT_NZ { }
       set ::SERIAL1 0
       set ::SERIAL2 0
       set ::REQ_COUNT 0
    
       log local0.debug "-------- RULE INIT -------------"  
       if { [findclass "serial" URL_REWRITE_NZ_LIST "|"] != $::SERIAL1 }{
    
          clear contents of previous mem resident table
          array unset ::ARRAY_REWRITE_NZ
          set ::SERIAL1 [findclass "serial" URL_REWRITE_NZ_LIST "|"] 
    
          log local0.debug "RELOADING UPDATED URI REWITE CLASS TO MEMORY"
    
          foreach item [class get URL_REWRITE_NZ_LIST] {
             set index [findstr $item "" 0 "|"]
             set data [findstr $item "|" 1 "\n"]
             set LIST "$index $data"
             set ::ARRAY_REWRITE_NZ($index) $data
             log local0.debug "Adding $index --> $data"
          }
       }
    }
    

    Aaron
  • Thanks Aaron,

     

     

    I have also made a few changes as the set data [findstr $item "|" 1 "\n"] also inserted a {} bracket.

     

     

    I have changed the code to set data [findstr $item "|" 1 "\{"] to fix the added backet issue.

     

     

  • The initial irule was developed by someone else and uses arrays to store and process redirects, is this the best approach? in terms of speed and future compatibility.

     

     

    The data class is also defined in the bigip.conf at the moment, the amount of redirects are small(100-200) would it be better to reference them out of external files?

     

     

    Are there any best practise doc's around data group classes
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    I have also made a few changes as the set data [findstr $item "|" 1 "\n"] also inserted a {} bracket.

     

     

    You can use lindex to get the first list element instead of stripping the {}'s:

     

     

    set data [lindex [findstr $item "|" 1 "\n"] 0]

     

     

    The CMP compatibility page lists some suggestions for accessing classes in recent LTM versions:

     

     

    http://devcentral.f5.com/Wiki/default.aspx/iRules/cmpcompatibility

     

     

    The class command provides additional info on new ways to search datagroups:

     

     

    http://devcentral.f5.com/Wiki/default.aspx/iRules/class

     

     

    I'm not aware of any performance benefit of using an external file as a source for a datagroup. Either way the datagroup contents are read from disk to memory upon config load.

     

     

    Aaron