Forum Discussion
brice_11994
Nimbostratus
Aug 12, 2008Perl LocalLB/VirtualServer - Changing iRules on a VIP
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
- 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 - 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
Wow! You rock! Thanks a bunch. I will test it out tomorrow and report back. - Glad to help! Please do report back and don't be a stranger...
-Joe - brice
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.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
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