Forum Discussion
Patrick_Chang_7
19 years agoHistoric F5 Account
iControl to disable a pool member globally in all pools in which it appears
I am trying to disable a pool member in all pools in which it appears in one shot.
I thought that under v9 disabling a node in the UI did not disable all the pool members associated with that nod...
Patrick_Chang_7
19 years agoHistoric F5 Account
I figured out my problem. Did not read the method descriptions closely enough. Here is the working version:
!/usr/bin/perl
this script expects input of the following:
F5 device ($Host) in the form of a string,
User ID ($UID) in the form of a string,
Password ($PASSWD) in the form of a string and
Member ($member_def) in the form of ":"
we also assume transport is HTTPS on port 443 to the F5 device
use SOAP::Lite;
my $Host = $ARGV[0];
my $UID = $ARGV[1];
my $PASSWD = $ARGV[2];
my $member_def = $ARGV[3];
sub usage()
{
die ("usage: globalForceDownPoolMember.pl host usedID passwd addr:port\n");
}
if (($Host eq "") or ($UID eq "") or ($PASSWD eq "") or ($member_def eq ""))
{
usage();
}
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$UID" => "$PASSWD";
}
set up Pool and PoolMember SOAP Objects
$Pool = SOAP::Lite
-> uri('urn:iControl:LocalLB/Pool')
-> readable(1)
-> proxy("https://$Host:443/iControl/iControlPortal.cgi");
set up Member
$PoolMember = SOAP::Lite
-> uri('urn:iControl:LocalLB/PoolMember')
-> readable(1)
-> proxy("https://$Host:443/iControl/iControlPortal.cgi");
set up login credentials
eval { $Pool->transport->http_request->header (
'Authorization' =>
'Basic ' . MIME::Base64::encode("$UID:$PASSWD", ''));
};
eval { $PoolMember->transport->http_request->header (
'Authorization' =>
'Basic ' . MIME::Base64::encode("$UID:$PASSWD", ''));
};
if port is missing, set to 0
($IP, $port) = split(/:/, $member_def,2);
if ($port eq "") {
$port = "0";
}
Get list of Pools
$soapResponse = $Pool->get_list();
&checkResponse($soapResponse);
@pool_list = @{$soapResponse->result};
Get list of all Pool Members
$soapResponse = $Pool->get_member( SOAP::Data->name( pool_names => [@pool_list] ) );
&checkResponse($soapResponse);
@member_lists = @{$soapResponse->result};
Loop through member list to build up arrays for the set_session_enabled_state and set_monitor_state commands
$i = 0;
foreach $pool_name (@pool_list) {
@member_list = @{@member_lists[$i]};
foreach $member (@member_list) {
$addr = $member->{"address"};
$pt = $member->{"port"};
if ($addr eq $IP and $pt == $port) {
set the state "STATE_DISABLED" or "STATE_ENABLED" to "STATE_DISABLED"
$MemberSessionState = { member => $member, session_state => "STATE_DISABLED" };
$MemberMonitorState = { member => $member, monitor_state => "STATE_DISABLED" };
fill up pool_names structure
push @PoolNames, $pool_name;
push @MemberSessionStateList, $MemberSessionState;
push @MemberSessionStateLists, [@MemberSessionStateList];
push @MemberMonitorStateList, $MemberMonitorState;
push @MemberMonitorStateLists, [@MemberMonitorStateList];
}
}
$i++;
}
if ($PoolNames < 0) {
print "$IP:$port not in any pools\n";
exit;
}
disable the member in all pools
$soapResponse = $PoolMember->set_session_enabled_state
(
SOAP::Data->name ( pool_names => ( [@PoolNames] ) ),
SOAP::Data->name ( session_states => [@MemberSessionStateLists] )
);
&checkResponse($soapResponse);
disable the monitor in all pools
$soapResponse = $PoolMember->set_monitor_state
(
SOAP::Data->name ( pool_names => ( [@PoolNames] ) ),
SOAP::Data->name ( monitor_states => ( [@MemberMonitorStateLists] ) )
);
&checkResponse($soapResponse);
print "Pool Member $IP:$port globally Forced Down\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();
}
}
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
