Forum Discussion

rnorberg's avatar
rnorberg
Icon for Nimbostratus rankNimbostratus
Feb 11, 2012

class match confusion...

im having an issue getting my hands around this irule:

 

 

 

set pooluri ""

 

set pooluri [class match -name $originaluri starts_with pool-list]

 

if {$pooluri eq ""} {

 

set pooluri "default"

 

}

 

set pooluri2 [class match -value pooluri equals pool-list]

 

set dest_pool [getfield variable_uri_2 "," 1]

 

 

im not understanding what the -name and -value differences are. is this rule saying if the $originaluri variable starts with an entry in the pool-list class, set the $pooluri variable to 'default' .. and if its not in the class list do nothing?

 

 

then im really confused on the class match -value statement. what is the difference between -name and -value? ive never used class match in this way, and help decoding this would be much appreciated!

 

8 Replies

  • e.g.

    [root@ve1023:Active] config  b class pool-list list
    class pool-list {
       {
          "string1" { "value1" }
          "string2" { "value2" }
          "string3" { "value3" }
       }
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when RULE_INIT {
            log local0. "\[class get pool-list\]: [class get pool-list]"
            log local0. "\[class match -- string2 equals pool-list\]: [class match -- string1 equals pool-list]"
            log local0. "\[class match -- string2 equals pool-list\]: [class match -name string2 equals pool-list]"
            log local0. "\[class match -- string2 equals pool-list\]: [class match -value string2 equals pool-list]"
    }
    }
    
    [root@ve1023:Active] config  tail -f /var/log/ltm
    Feb 11 21:56:09 local/ve1023 err mcpd[3746]: 01020066:3: The requested rule (myrule) already exists in partition Common.
    Feb 11 21:56:10 local/tmm info tmm[4822]: Rule myrule : [class get pool-list]: {string1 value1} {string2 value2} {string3 value3}
    Feb 11 21:56:10 local/tmm info tmm[4822]: Rule myrule : [class match -- string2 equals pool-list]: 1
    Feb 11 21:56:10 local/tmm info tmm[4822]: Rule myrule : [class match -- string2 equals pool-list]: string2
    Feb 11 21:56:10 local/tmm info tmm[4822]: Rule myrule : [class match -- string2 equals pool-list]: value2
    
  • thanks! im almost there.

     

     

    in your example...

     

     

    log local0. "\[class match -- string2 equals pool-list\]: [class match -name string2 equals pool-list]"

     

     

    what would be the result if string2 did NOT exist in the class pool-list ?
  • what would be the result if string2 did NOT exist in the class pool-list ?0 will be returned.

     

     

    class match [options] item operator class

     

    Returns 0 or 1 depending on whether item matches an element in class.class wiki

     

    http://devcentral.f5.com/wiki/iRules.class.ashx
  • e.g.

    [root@ve1023:Active] config  tail -f /var/log/ltm
    Feb 12 18:06:23 local/ve1023 err mcpd[3746]: 01020066:3: The requested rule (myrule) already exists in partition Common.
    Feb 12 18:06:23 local/tmm info tmm[4822]: Rule myrule : [class get pool-list]: {string1 value1} {string2 value2} {string3 value3}
    Feb 12 18:06:23 local/tmm info tmm[4822]: Rule myrule : [class match -- string9 equals pool-list]: 0
    Feb 12 18:06:23 local/tmm info tmm[4822]: Rule myrule : [class match -name string9 equals pool-list]:
    Feb 12 18:06:23 local/tmm info tmm[4822]: Rule myrule : [class match -value string9 equals pool-list]: