Forum Discussion
F5_LB_Eng
Cirrostratus
Jul 14, 2022dynamically instead of a fixed value in persistance
Hi , Any one has Irule for dynamically attribute instead of a fixed value in persistance. Does the builtin cookie persistence allows something like this: Cookie_name: SESSIONID* So can we set th...
- Jul 14, 2022
You can go with universal persistence (have universal persistence configured for your virtual server) and use the following iRule:
when RULE_INIT { set static::dynamic_persist_timeout 600 } when HTTP_REQUEST { set http_cookie_list [HTTP::cookie names] if { [lsearch -glob $http_cookie_list "*_SESSIONID_*"] >= 0 } { set http_cookie_name [lindex $http_cookie_list [lsearch -glob $http_cookie_list "*_SESSIONID_*"]] set http_cookie_value [HTTP::cookie value [lindex $http_cookie_list [lsearch -glob $http_cookie_list "*_SESSIONID_*"]]] log local0. "cookiematch=${http_cookie_name},cookievalue=${http_cookie_value}" persist uie "${http_cookie_name}:${http_cookie_value}" } } when HTTP_RESPONSE { set http_cookie_list [HTTP::cookie names] if { [lsearch -glob $http_cookie_list "*_SESSIONID_*"] >= 0 } { set http_cookie_name [lindex $http_cookie_list [lsearch -glob $http_cookie_list "*_SESSIONID_*"]] set http_cookie_value [HTTP::cookie value [lindex $http_cookie_list [lsearch -glob $http_cookie_list "*_SESSIONID_*"]]] log local0. "cookiematch=${http_cookie_name},cookievalue=${http_cookie_value}" persist add uie "${http_cookie_name}:${http_cookie_value}" ${static::dynamic_persist_timeout} } }
I tested this one in my environment using another BIG-IPs virtual server as a server emulation:
when HTTP_REQUEST { set http_cookie_list [HTTP::cookie names] if { [lsearch -glob $http_cookie_list "*_SESSIONID_*"] >= 0 } { set http_cookie_name [lindex $http_cookie_list [lsearch -glob $http_cookie_list "*_SESSIONID_*"]] set http_cookie_value [HTTP::cookie value [lindex $http_cookie_list [lsearch -glob $http_cookie_list "*_SESSIONID_*"]]] log local0. "cookiematch=${http_cookie_name},cookievalue=${http_cookie_value}" } else { if { [info exists http_cookie_name] } { unset http_cookie_name } if { [info exists http_cookie_value] } { unset http_cookie_value } for { set i 0 } { $i < 3 } { incr i } { append http_cookie_name [lindex {A B C D E F G H I J K L M N O P Q R S T U V W Z Y Z} [expr int(rand()*26)]] } append http_cookie_name "_SESSIONID_" for { set i 0 } { $i < 6 } { incr i } { append http_cookie_name [lindex {0 1 2 3 4 5 6 7 8 9} [expr int(rand()*10)]] } append http_cookie_name "_" for { set i 0 } { $i < 8 } { incr i } { append http_cookie_name [lindex {A B C D E F G H I J K L M N O P Q R S T U V W Z Y Z 0 1 2 3 4 5 6 7 8 9} [expr int(rand()*36)]] } for { set i 0 } { $i < 16 } { incr i } { append http_cookie_value [lindex {a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9} [expr int(rand()*36)]] } log local0. "cookiegenerator=${http_cookie_name},valuegenerator=${http_cookie_value}" } HTTP::respond 200 content "responder\r\n" noserver Connection Close Set-Cookie "${http_cookie_name}=${http_cookie_value}" return }
You can monitor your persistence table on CLI of your device under test:
watch tmsh show ltm persist persist-records mode universal all-properties
Todd_Cromwell_9
Nimbostratus
Jun 21, 2012You didn't say, but perhaps you are experiencing one of these two error messages:
>>> b.LocalLB.Pool.create_v2(['p2'],['LB_METHOD_ROUND_ROBIN'],[[{'port': 80, 'address': 'roger'}]])
Traceback (most recent call last):
File "", line 1, in ?
File "/vol/3/user/cromwell/bigsuds.py", line 344, in __call__
result = self._method(*args, **kwargs)
File "/usr/lib/python2.4/site-packages/suds/client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "/usr/lib/python2.4/site-packages/suds/client.py", line 602, in invoke
result = self.send(soapenv)
File "/usr/lib/python2.4/site-packages/suds/client.py", line 657, in send
result = self.failed(binding, e)
File "/usr/lib/python2.4/site-packages/suds/client.py", line 712, in failed
r, p = binding.get_fault(reply)
File "/usr/lib/python2.4/site-packages/suds/bindings/binding.py", line 265, in get_fault
raise WebFault(p, faultroot)
bigsuds.ServerError: Server raised fault: 'Exception caught in LocalLB::urn:iControl:LocalLB/Pool::create_v2()
Exception: Common::OperationFailed
primary_error_code : 16908342 (0x01020036)
secondary_error_code : 0
error_string : 01020036:3: The requested node (/Common/roger) was not found.'
>>> b.LocalLB.Pool.create(['p2'],['LB_METHOD_ROUND_ROBIN'],[[{'port': 80, 'address': 'roger'}]])
Traceback (most recent call last):
File "", line 1, in ?
File "/vol/3/user/cromwell/bigsuds.py", line 344, in __call__
result = self._method(*args, **kwargs)
File "/usr/lib/python2.4/site-packages/suds/client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "/usr/lib/python2.4/site-packages/suds/client.py", line 602, in invoke
result = self.send(soapenv)
File "/usr/lib/python2.4/site-packages/suds/client.py", line 657, in send
result = self.failed(binding, e)
File "/usr/lib/python2.4/site-packages/suds/client.py", line 712, in failed
r, p = binding.get_fault(reply)
File "/usr/lib/python2.4/site-packages/suds/bindings/binding.py", line 265, in get_fault
raise WebFault(p, faultroot)
bigsuds.ServerError: Server raised fault: 'Exception caught in LocalLB::urn:iControl:LocalLB/Pool::create()
Exception: Common::OperationFailed
primary_error_code : 16908320 (0x01020020)
secondary_error_code : 0
error_string : 01020020:3: The text string cannot be converted to an IP address.'
Perhaps you want something like this:
>>> b.LocalLB.NodeAddressV2.create(['roger'],['1.1.1.1'],[0])
>>> b.LocalLB.Pool.create_v2(['p2'],['LB_METHOD_ROUND_ROBIN'],[[{'port': 80, 'address': 'roger'}]])
So we create a node, then use that in the pool create in the members argument.
That yields this pool and node:
[root@regent:Active:Standalone] iControl tmsh list ltm pool p2
ltm pool p2 {
members {
roger:http {
address 1.1.1.1
}
}
}
[root@regent:Active:Standalone] iControl tmsh list ltm node roger
ltm node roger {
address 1.1.1.1
}
If we get an address we can convert in the AddressPort structure you pass, we create the node automatically:
>>> b.LocalLB.Pool.create_v2(['p3'],['LB_METHOD_ROUND_ROBIN'],[[{'port': 80, 'address': '2.2.2.2'}]])
That gets us a node named "2.2.2.2" and creates the pool with that as a member.
[root@regent:Active:Standalone] iControl tmsh list ltm pool p3
ltm pool p3 {
members {
2.2.2.2:http {
address 2.2.2.2
}
}
}
[root@regent:Active:Standalone] iControl tmsh list ltm node 2.2.2.2
ltm node 2.2.2.2 {
address 2.2.2.2
}
Recent Discussions
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects