Hello Joe,
Thanks again for all the pointers - I'm almost there now but I am having issues getting the member_priority array to print the correct values with the @member_state array.
I tried pushing (merging) the arrays but nothing is working. Depending on my foreach loop I either get the correct priority values for each pool to print without the cooresponding member_state value; or I get the correct member_state values without the correct corresponding priority value. Any suggestions on how i could code these arrays in order to print ALL correct values on each line output?
below is the code:
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 $sNodeAddr = $ARGV[5];
my $sProtocol = "https";
sub usage()
{
die ("Usage: PoolToggle.pl host port uid pwd ([pool]) \n");
}
if ( ($sHost eq "") or ($sPort eq "") or ($sUID eq "") or ($sPWD eq ""))
{
usage();
}
----------------------------------------------------------------------------
Transport Information
----------------------------------------------------------------------------
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$sUID" => "$sPWD";
}
$Pool = SOAP::Lite
-> uri('urn:iControl:LocalLB/Pool')
-> readable(1)
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
$PoolMember = SOAP::Lite
-> uri('urn:iControl:LocalLB/PoolMember')
-> 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", '')
); };
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
----------------------------------------------------------------------------
$soapResponse = $Pool->get_list();
&checkResponse($soapResponse);
@pool_list = @{$soapResponse->result};
&showPoolMembers(@pool_list);
----------------------------------------------------------------------------
Show list of pools and members
----------------------------------------------------------------------------
sub showPoolMembers()
{
my (@pool_list) = @_;
my @sortedPool = sort { lc($a) cmp lc($b) } @pool_list;
my @member_state_lists = &getPoolMemberStates(@sortedPool);
my @member_priority_lists = &getPoolPriority(@sortedPool);
print "Pool Members Enabled State\n";
print "==========================\n";
$i = 0;
foreach $pool (@sortedPool)
{
@priorityCheck = @{@member_priority_lists[$i]};
@memberState = @{@member_state_lists[$i]};
foreach $member_priority (@priorityCheck)
{
$priority = $member_priority->{"priority"};
foreach $member_state (@memberState)
{
$member = $member_state->{"member"};
$addr = $member->{"address"};
$port = $member->{"port"};
$session_state = $member_state->{"session_state"};
----------------------------------------------------------------------------
PRINT THE OUTPUT:
print "$pool:$addr:$port:$session_state:$priority\n";
$i++;
}}}
}
----------------------------------------------------------------------------
returns the status structures for the members of the specified pools
----------------------------------------------------------------------------
sub getPoolMemberStates()
{
my (@pool_list) = @_;
$soapResponse = $PoolMember->get_session_enabled_state
(
SOAP::Data->name(pool_names => [@pool_list])
);
&checkResponse($soapResponse);
@member_state_lists = @{$soapResponse->result};
return @member_state_lists;
}
sub getPoolPriority()
{
my (@pool_list) = @_;
$soapResponse2 = $PoolMember->get_priority
(
SOAP::Data->name(pool_names => [@pool_list])
);
&checkResponse($soapResponse2);
@member_priority_list = @{$soapResponse2->result};
return @member_priority_list;
}
&checkResponse($soapResponse);
&checkResponse($soapResponse2);
----------------------------------------------------------------------------
checkResponse makes sure the error isn't a SOAP error
----------------------------------------------------------------------------
sub checkResponse()
{
my ($soapResponse) = (@_);
if ( $soapResponse->fault )
{
print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";
exit();
}