Forum Discussion
Ian_McKenna_113
Nimbostratus
Jun 20, 2006How to get all Pools for a Node
Hi,
I am trying to display all the pools for a node.
I have set "use iControlTypeCast", but still I have problems displaying the get_member method;
Has any body an idea?
than...
Jun 20, 2006
The Pool::get_member() method returns a 2D array which is likely what is causing you an issue. You pass in an array of pools, and it returns a 2-d array with the first dimension relating to each input pool and the 2nd dimension with the members in that pool. I've streamlined your code a bit to make use of bulk calls. By calling the get methods only once you can reduce the round-trip time dramatically. Here's some code that will query all the node addresses and print out the pools that they belong to.
* I've commented out the get_screen_names method becuase on my dev build of BIG-IP it was giving me some troubles. Uncomment for a production build and you should be fine.
!/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;
use MIME::Base64;
BEGIN {push (@INC, "..");}
use iControlTypeCast;
----------------------------------------------------------------------------
Validate Arguments
----------------------------------------------------------------------------
my $sHost = $ARGV[0];
my $sPort = $ARGV[1];
my $sUID = $ARGV[2];
my $sPWD = $ARGV[3];
my $sNode = $ARGV[4];
my $sProtocol = "https";
if ( ("80" eq $sPort) or ("8080" eq $sPort) )
{
$sProtocol = "http";
}
if ( ($sHost eq "") or ($sPort eq "") or ($sUID eq "") or ($sPWD eq "") )
{
die ("Usage: PoolsForNodes.pl host port uid pwd [node_addr]\n");
}
----------------------------------------------------------------------------
Transport Information
----------------------------------------------------------------------------
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$sUID" => "$sPWD";
}
$Pool = SOAP::Lite
-> uri('urn:iControl:LocalLB/Pool')
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
eval { $Pool->transport->http_request->header
(
'Authorization' =>
'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };
$NodeAddress = SOAP::Lite
-> uri('urn:iControl:LocalLB/NodeAddress')
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
eval { $NodeAddress->transport->http_request->header
(
'Authorization' =>
'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };
&findPoolsForNode();
sub findPoolsForNode()
{
my ($node_addr) = (@_);
get the list of node addresses
$soapResponse = $NodeAddress->get_list();
&checkResponse($soapResponse);
@node_list = @{$soapResponse->result};
get the node address screen names
$soapResponse = $NodeAddress->get_screen_name
(
SOAP::Data->name(node_addresses => [$node_addr])
);
&checkResponse($soapResponse);
@screen_names = @{$soapResponse->result};
get the list of pools
$soapResponse = $Pool->get_list();
&checkResponse($soapResponse);
@pool_list = @{$soapResponse->result};
get the member lists for all of the pools.
$soapResponse = $Pool->get_member
(
SOAP::Data->name(pool_names => [@pool_list])
);
&checkResponse($soapResponse);
@member_listsAofA = @{$soapResponse->result};
find some matches
for $i (0 .. $node_list)
{
$node_address = $node_list[$i];
$screen_name = $screen_names[$i];
$pool_name = $pool_list[$i];
@member_lists = @{$member_listsAofA[$i]};
printf "----------------------------\n";
printf "NODE : %s\n", $node_address;
printf "Name : %s\n", $screen_name;
printf "Pools : ";
for $j (0 .. $member_lists)
{
$member = @member_lists[$j];
$address = $member->{"address"};
$port = $member->{"port"};
if ( $node_address eq $address )
{
Found match!
printf "%s, ", $pool_name;
}
}
printf "\n";
}
}
----------------------------------------------------------------------------
checkResponse
----------------------------------------------------------------------------
sub checkResponse()
{
my ($soapResponse) = (@_);
if ( $soapResponse->fault )
{
print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";
exit();
}
}
Hope this helps.
-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