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?
thanks in advance
Ian
sub execute
{
my $sHost = shift @_;
my $sPort = shift @_;
my $sUID = shift @_;
my $sPWD = shift @_;
my $sNode = shift @_;
my $sProtocol = "https";
if ( ("80" eq $sPort) or ("8080" eq $sPort) )
{
$sProtocol = "http";
}
my $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", '')
); };
my $PoolList = SOAP::Lite
-> uri('urn:iControl:LocalLB/Pool')
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
eval { $PoolList->transport->http_request->header
(
'Authorization' =>
'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };
---------------- idev -------
my $node_address;
my $soapResponse = $NodeAddress->get_list();
&checkResponse($soapResponse);
my @node_list = @{$soapResponse->result};
my @node_name;
my$i = 0;
if ($sNode eq "")
{
foreach $node_address (@node_list)
{
printf "----------------------------------\n";
printf("NODE %15s \n", $node_address);
&getData($node_address, $NodeAddress, $PoolList);
$i++;
}
}
else
{
foreach $node_address (@node_list)
{
if ($sNode eq $node_address)
{
printf("NODE %15s \n", $node_address);
&getData($node_address, $NodeAddress, $PoolList);
}
$i++;
}
}
SUCCESS;
}
sub getData
{
my $node_address = shift @_;
my $NodeAddress = shift @_;
my $PoolList = shift @_;
my @value_name;
my $value;
my $single_value;
my @pool_list;
my $pool_value;
my $port_value;
my $address_value;
my $soapResponse_1;
my $soapResponse = $NodeAddress->get_screen_name(
SOAP::Data->name( node_addresses => [$node_address] ));
&checkResponse($soapResponse);
@value_name = @{$soapResponse->result};
printf("Name - %20s \n", @value_name);
$soapResponse = $PoolList->get_list();
&checkResponse($soapResponse);
@pool_list = @{$soapResponse->result};
foreach $pool_value (@pool_list)
{
printf("Pool %25s \n", $pool_value);
$soapResponse_1 = $PoolList->get_member(
SOAP::Data->name( pool_names => [$pool_value] ));
&checkResponse($soapResponse_1);
@value_name = @{$soapResponse_1->result};
foreach $value (@value_name)
{
$address_value = $value -> "address"};
$port_value = $value -> {"port"};
printf("Addess %25s \n", $address_value);
printf("Port %25s \n", $port_value);
}
}
}
- 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.
!/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(); } }
- Robin_Mordasie1Historic F5 AccountI ran this script and noticed that the section where you look for matches is not correct.
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