# Internal class format

**URL:** <https://community.f5.com/t/internal-class-format/23499>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [April 1, 2010, 6:31pm UTC](https://community.f5.com/t/internal-class-format/23499 "2010-04-01T18:31:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![qqdixf5\_74186](https://avatars.discourse-cdn.com/v4/letter/q/b38774/32.png) [@qqdixf5\_74186](https://community.f5.com/u/qqdixf5_74186)\
**Post date:** [April 1, 2010, 6:31pm UTC](https://community.f5.com/t/internal-class-format/23499/1 "2010-04-01T18:31:09Z")

</div>

Is this format valid for v10.0.1.

```tcl
class namevalue {   
      {   
         "name1" { "value1" }   
         "name2" { "value1" }   
      }   
  }

```

I am getting a parsing error on b verify load.

012e0021:3: The requested attribute ({ name1) is invalid for ‘class’.

So I tried this and it passed the verify.

```tcl
class namevalue {   
         "name1" { "value1" }   
         "name2" { "value1" }   
   }

```

But, after I load and sync, the class changed to

```tcl
class namevalue {   
      { 
         "value1"   
         "name1"    
         "value2"   
         "name2" 
      }   
   }

```

I want to make it easy to lookup values based on names.

Thanks!

---

<div class="post-metadata">

**Author:** ![L4L7\_53191](https://avatars.discourse-cdn.com/v4/letter/l/f475e1/32.png) [@L4L7\_53191](https://community.f5.com/u/L4L7_53191)\
**Post date:** [April 1, 2010, 6:34pm UTC](https://community.f5.com/t/internal-class-format/23499/2 "2010-04-01T18:34:46Z")

</div>

On 10.1 this is what works for me:

```tcl
class foo { 
    {  
          "www.one.com www.foo.com" 
          "www.two.com www.bar.com" 
     } 
 }

```

-Matt

---

<div class="post-metadata">

**Author:** ![qqdixf5\_74186](https://avatars.discourse-cdn.com/v4/letter/q/b38774/32.png) [@qqdixf5\_74186](https://community.f5.com/u/qqdixf5_74186)\
**Post date:** [April 1, 2010, 6:54pm UTC](https://community.f5.com/t/internal-class-format/23499/3 "2010-04-01T18:54:19Z")

</div>

This format works in v10.0.1 as well. But does it make the entry as name/value pairs so it it easy to lookup value based on the key?

I just tested it. It doesn’t. The whole line is treat as the name of the element. I have to parse it.

It sounds like the below format should be valid for internal calls in v10.0.1, according to the class wiki page. I wonder why it couldn’t pass the verify command

```tcl
class namevalue { 
    { 
       "name1" { "value" } 
       "name2" { "value" } 
    } 
 }

```

Any help is appeciated!

---

<div class="post-metadata">

**Author:** ![Hamish](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Hamish](https://community.f5.com/u/Hamish)\
**Post date:** [April 2, 2010, 10:22am UTC](https://community.f5.com/t/internal-class-format/23499/4 "2010-04-02T10:22:52Z")

</div>

Well the format

```tcl
class keyvalue { 
    { 
       "onekey" { "onevalue" } 
       "twokey" { "twovalue" } 
    } 
 }

```

is the way that the GUI adds in the key/value pairs when you create the DG via the GUI itself. That verifies on my vLTM. I don’t see why it wouldn’t validate on yours. Are you sure the error is in the class itself and not before it?

H

---

<div class="post-metadata">

**Author:** ![qqdixf5\_74186](https://avatars.discourse-cdn.com/v4/letter/q/b38774/32.png) [@qqdixf5\_74186](https://community.f5.com/u/qqdixf5_74186)\
**Post date:** [April 2, 2010, 12:11pm UTC](https://community.f5.com/t/internal-class-format/23499/5 "2010-04-02T12:11:34Z")

</div>

I used GUI, created a string datagroup, added these two string entries:

```tcl
"name1" {"value1"} 
 "name2" {"value2"}

```

After save, open config file and they are saved as:

```tcl
class namevalues{ 
    { 
       "\"name1\" {\"value1\"}" 
       "\"name2\" {\"value2\"}" 
    } 
 }

```

Each line is treated as the name of element. so [class names namevalues] command returns:

```tcl
{"name1" {"value1"}} {"name2" {"value2"}}

```

[class match -value “name1” equals namevalues] returns nothing.

---

<div class="post-metadata">

**Author:** ![L4L7\_53191](https://avatars.discourse-cdn.com/v4/letter/l/f475e1/32.png) [@L4L7\_53191](https://community.f5.com/u/L4L7_53191)\
**Post date:** [April 2, 2010, 6:45pm UTC](https://community.f5.com/t/internal-class-format/23499/6 "2010-04-02T18:45:21Z")

</div>

This rule works with the original format I posted above. The idea of the rule is to redirect based on a lookup of the original HTTP::host header value. For example,

with a class like:

class foo {

{

“[www.one.com](http://www.one.com) [www.foo.com](http://www.foo.com)”

“[www.two.com](http://www.two.com) [www.bar.com](http://www.bar.com)”

}

}

The following code:

```tcl
when HTTP_REQUEST {   
      set Host [findclass [HTTP::host] dc-post " "] 
 log local0. "Host var is $Host"  
      if { $Host ne "" } {  
           HTTP::redirect http://$Host[HTTP::uri]  
           }  
   }

```

…will lookup the k/v pair where [www.one.com](http://www.one.com) or [www.two.com](http://www.two.com) are the keys, and redirect to the value ([www.foo.com](http://www.foo.com) or [www.bar.com](http://www.bar.com)).

It may be of value to have a look at this post: [DevCentral](https://devcentral.f5.com/Default.aspx?tabid=53&view=topic&postid=1144951&forumid=5&tpage=1)

-Matt

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [April 8, 2010, 10:44am UTC](https://community.f5.com/t/internal-class-format/23499/7 "2010-04-08T10:44:31Z")

</div>

I think qqdixf5 is using 10.0.x which might handle class -name and class -value differently than 10.1.x. I think in order to use class -name/-value in 10.0.x, you’d need to use the := format in an external datagroup.

Aaron
