Wednesday, September 3, 2014

Alteon group selection by HTTP Host header using AppShape++

On the previous post I have used Content Rules to configure group (server pool) selection based on the Host header in HTTP.

This lab is also based on the lab setup I am using.


This time I'll do the same, but with AppShape++, which is similar to F5's iRules.

I want a2.dans-net.com to be served by SRV1 and b2.dans-net.com to be served by SRV2, any other host should be served by all web servers.

I'll use VIP 10.86.3.10 as the VIP. Here is how I edit my /etc/hosts files, which is c:\windows\system32\drivers\etc\hosts :

10.136.6.10    a2.dans-net.com
10.136.6.10    b2.dans-net.com

First, I'll configured two new groups (server pools):

 /c/slb/group a2_dans
        add 1

 /c/slb/group b2_dans
        add 2

Next I'll write the AppShape++ script which will select a group based on the Host header:

attach group a2_dans
attach group b2_dans

when HTTP_REQUEST {
    switch -glob [HTTP::host] {
        "a2.dans-net.com" {
            group select a2_dans
        }
        "b2.dans*" {
            group select b2_dans
        }
        default {
            group select 10
        }
    }
}
-----END

The first two lines are attach statements. I have no idea why they are needed. All I know that any group referenced inside other parts of the script must be declared there.

Then, with the help of the switch command we select which  group to use when using this host or the other. If the Host matches nothing, then we will use group #10, which includes all the web servers.

Lets import the script into Alteon. Notice the "-----END" at the end, which marks the end of the script.

 /c/slb/appshape/script group_by_host
        ena
        import text 
 attach group a2_dans
 attach group b2_dans
 when HTTP_REQUEST {
     switch -glob [HTTP::host] {
         "a2.dans-net.com" {
             group select a2_dans
         }
         "b2.dans*" {
             group select b2_dans
         }
         default {
             group select 10
         }
     }
 }
 -----END

Next lets configure the VIP, or virt in Alteon's terminology.


 /c/slb/virt 6_10
        ena
        vip 10.136.6.10
 /c/slb/virt 6_10/service 80 http
 /c/slb/virt 6_10/service 80 http/appshape
        add 10 group_by_host

After apply lets test:




Success!

So which is better? Using Content Rules or use AppShape++ scripts.

I think that once you learn it, AppShape++ scripts are much easier as you you always use the same TCL commands and you are not forced in awkward configurations which at the end mimic that short script.