Forum Discussion
bert_vandebroe1
Nimbostratus
Apr 19, 2006get_member_ratios example
Hi guys,
Can someone post an example of how to call get_member_ratios in perl ?
I have looked at the examples but my perl skills are waaaaaaay to rusty to make that one work ...
Apr 19, 2006
This should get you going:
!/usr/bin/perl
----------------------------------------------------------------------------
The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
Software Development Kit for iControl"; you may not use this file except in
compliance with the License. The License is included in the iControl
Software Development Kit.
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
the License for the specific language governing rights and limitations
under the License.
The Original Code is iControl Code and related documentation
distributed by F5.
The Initial Developer of the Original Code is F5 Networks,
Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2004 F5 Networks,
Inc. All Rights Reserved. iControl (TM) is a registered trademark of F5 Networks, Inc.
Alternatively, the contents of this file may be used under the terms
of the GNU General Public License (the "GPL"), in which case the
provisions of GPL are applicable instead of those above. If you wish
to allow use of your version of this file only under the terms of the
GPL and not to allow others to use your version of this file under the
License, indicate your decision by deleting the provisions above and
replace them with the notice and other provisions required by the GPL.
If you do not delete the provisions above, a recipient may use your
version of this file under either the License or the GPL.
----------------------------------------------------------------------------
use SOAP::Lite + trace => qw(method debug);
use SOAP::Lite;
----------------------------------------------------------------------------
Validate Arguments
----------------------------------------------------------------------------
my $sHost = $ARGV[0];
my $sPort = $ARGV[1];
my $sUID = $ARGV[2];
my $sPWD = $ARGV[3];
my $sPool = $ARGV[4];
my $sProtocol = "https";
sub usage()
{
die ("Usage: PoolMemberRatios.pl host port uid pwd [pool]\n");
}
if ( ($sHost eq "") or ($sPort eq "") or ($sUID eq "") or ($sPWD eq "") )
{
usage();
}
if ( ($sPort eq 80) || ($sPort eq 8080) )
{
$sProtocol = "http";
}
----------------------------------------------------------------------------
Transport Information
----------------------------------------------------------------------------
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$sUID" => "$sPWD";
}
$Pool = SOAP::Lite
-> uri('urn:iControl:ITCMLocalLB/Pool')
-> readable(1)
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
----------------------------------------------------------------------------
Attempt to add auth headers to avoid dual-round trip
----------------------------------------------------------------------------
eval { $Pool->transport->http_request->header
(
'Authorization' =>
'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };
----------------------------------------------------------------------------
support for custom enum types
----------------------------------------------------------------------------
sub SOAP::Deserializer::typecast
{
my ($self, $value, $name, $attrs, $children, $type) = @_;
my $retval = undef;
if ( "{urn:iControl}Common.EnabledState" == $type )
{
$retval = $value;
}
return $retval;
}
----------------------------------------------------------------------------
Main logic
----------------------------------------------------------------------------
if ( "" eq $sPool )
{
------------------------------------------------------------------------
No pool supplied. Query pool list and display members for given pool
------------------------------------------------------------------------
$soapResponse = $Pool->get_list();
&checkResponse($soapResponse);
@pool_list = @{$soapResponse->result};
foreach $pool (@pool_list)
{
print "Pool '$pool'\n";
}
}
elsif ( "" ne $sPool )
{
&getMemberInfo($sPool);
}
else
{
print "No conditions defined yet\n";
}
----------------------------------------------------------------------------
getMemberInfo
----------------------------------------------------------------------------
sub getMemberInfo()
{
my ($pool_name) = @_;
Get Member List
$soapResponse = $Pool->get_member_list
(
SOAP::Data->name(pool_name, => $pool_name)
);
&checkResponse($soapResponse);
@member_list = @{$soapResponse->result};
get member ratios
$soapResponse = $Pool->get_member_ratios
(
SOAP::Data->name(pool_name => $pool_name),
SOAP::Data->name(member_defs => [@member_list])
);
&checkResponse($soapResponse);
@member_ratios = @{$soapResponse->result};
for $i (0 .. $member_ratios)
{
$member_ratio = @member_ratios[$i];
$member_def = $member_ratio->{"member_def"};
$address = $member_def->{"address"};
$port = $member_def->{"port"};
$ratio = $member_ratio->{"ratio"};
print " -> $address:$port -> Ratio: $ratio \n";
}
}
----------------------------------------------------------------------------
checkResponse makes sure the error isn't a SOAP error
----------------------------------------------------------------------------
sub checkResponse()
{
my ($soapResponse) = (@_);
if ( $soapResponse->fault )
{
print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";
exit();
}
}
Enjoy!
-Joe
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