variable scopes only for one virtual sever or one request

Hello. I want to operate multiple stage environments(development, staging, production) in a partition. For those environments, I want to use same aflex policies as many as possible. I had looked for use following aflex policies. staging_env.tcl


when RULE_INIT {
    set ::global::target_service = "staging_service_80"
}

production_env.tcl


when RULE_INIT {
    set ::global::target_service = "production_service_80"
}

http_location.tcl


when HTTP_REQUEST {
    pool ::global::target_service
}

But ::global:: variables seem really global on the whole AX device. So I think the variable for the staging effects to the production. I want to use variables can be applied to one virtual service or one request. Do we have any solutions?

Can you give it a go without the ::global prefix.
Just do ::target_service and it will be “local” to the Virtual Port.

Mischa, Thank you for your response. I have just tried but result is NG. :: variable can not be read by other policies. I want to use separated policies to keep maintainability. config for a virtual service


   port 80  http
      name test
      service-group pl_test
      aflex test-env
      aflex test-access

aflex test-env


when RULE_INIT {
    set ::global::test_target_service "global"
    set ::test_target_service "noglobal"
}

aflex test-access


when HTTP_REQUEST {
    log "::global::test_target_service $::global::test_target_service"
    log "::test_target_service  $::test_target_service"
}

log(result) : logged only for the global variable


Mar 11 2014 01:05:22 Info    [AFLEX]:::global::test_target_service global

I rechecked the manual ‘aFleX Scripting Language Reference’ and some descriptions there.

Prefix :: Scope Applies only to the current aFleX policy. This variable cannot be set or read by any other aFleX policies. Once the variable is defined, it can be removed only by an unset command. Prefix ::global:: Scope Applies to all aFleX policies. This variable can be set or read by all aFleX policies on the AX device.

any ideas?

Yes, you are correct the ::VAR can not be used by other scripts. I have been wrecking my brain but there isn’t a way to do what you want to do today.
Using tables for example will give you the same result as ::global::.
The only alternative would be to include the RULE_INIT in the actual script.

Hi, I found a trick as follows. When the virtual server works on 10.0.0.1. aflex test-env


when RULE_INIT {
    set ::global::10.0.0.1 "pool_staging"
}

aflex test-access


when HTTP_REQUEST {
    eval "set pool_name \${::global::[IP::local_addr]}"
    log "pool_name $pool_name"
}

log


Mar 18 2014 05:01:10 Info    [AFLEX]:pool_name pool_staging

We might use arrays in this way. Please tell me if you have any smarter ways.

Nice workaround!