cancel
Showing results for 
Search instead for 
Did you mean: 

Perl LocalLB/VirtualServer - Changing iRules on a VIP

brice_11994
Nimbostratus
Nimbostratus
Hey guys,

 

My end state is to have a script to list the iRules of a VIP, remove iRules from a VIP, and add iRules to a VIP. I am having all kinds of trouble referencing the elements of the array returned with the get_rule function. When I go to reference the returned data I get the following error...

 

"Bad index while coercing array into hash"

 

Here is my code

 

$soapResponse = $VirtServ->get_rule(SOAP::Data->name(virtual_servers => [$sVirt])); &checkResponse($soapResponse); @StringRuleList = @{$soapResponse->result}; foreach $StringRule (@StringRuleList) { $rule_pri = $StringRule->{"priority"}; <-- This is the line it errors on $rule_name = $StringRule->{"rule_name"}; print "$rule_name\n$rule_pri\n\n"; }

 

I have tried to use the Data:Dumper, and I can see the data is being collected, but it will not reference it according to the documentation. Here is the output from Data:Dumper.

 

$VAR1 = bless( [ bless( { 'priority' => '0', 'rule_name' => 'rule_test' }, 'LocalLB::VirtualServer::VirtualServerRule' ) ], 'LocalLB::VirtualServer::VirtualServerRule[]' );

 

What am I doing wrong?
5 REPLIES 5

Joe_Pruitt
Cirrostratus
Cirrostratus
You are treating the response like a 1-d array while it is in reality a 2-d array.

 

 

VirtualServerRule [] [] get_rule(

 

in String [] virtual_servers

 

);

 

 

 

You are just passing in a single virtual server so the 0th index of the first dimension will be the list of VirtualServerRule structures for that given virtual.

 

 

I'll whip up some code and post it later on today for you if you haven't figured it out by then.

 

 

-Joe

Joe_Pruitt
Cirrostratus
Cirrostratus
I just whipped a sample up for you and put it in the iControl codeshare.

 

 

http://devcentral.f5.com/wiki/default.aspx/iControl/PerlVirtualServerRule.html

 

Click here

 

 

 

The usage is as follows:

 

 

$ ./VirtualServerRule.pl bigip port user pass list [virtual]

 

$ ./VirtualServerRule.pl bigip port user pass add virtual rule priority

 

$ ./VirtualServerRule.pl bigip port user pass remove virtual rulename

 

 

 

Hopefully it's fairly self-explanatory in the code. Feel free to follow up here if you have any questions about the code.

 

 

Cheers!

 

 

-Joe

brice
Nimbostratus
Nimbostratus
Wow! You rock! Thanks a bunch. I will test it out tomorrow and report back.

Joe_Pruitt
Cirrostratus
Cirrostratus
Glad to help! Please do report back and don't be a stranger...

 

 

-Joe

brice
Nimbostratus
Nimbostratus
Well, what can I say. The script works great for all three scenarios. I am going to actually hardcode some values and duplicate the script with a php front end, but this is great.

 

 

I guess my lack of ~real~ development skills had me hung up on the 2d array. Now that I see the way you reference it in the code, it makes all the sense in the world. Thanks again, and I'll let you know if I find anything out of the ordinary.