Enabling or disabling a pool member

Problem this snippet solves:

The script you need for this task must:.

  1. Identify the Enterprise Manager through which you will access the necessary BIG-IP devices.
  2. Authenticate your client to the Enterprise Manager.
  3. Retrieve a list of the BIG-IP devices managed by Enterprise Manager.
  4. For each managed BIG-IP device, retrieve a list of pools and pool members.
  5. For each managed BIG-IP device, specify the operation you want to perform (enable/disable).

How to use this snippet:

To enable/disable a pool member:

  1. Create a script similar to the code sample shown below. Use either the enable or disable parameter to produce the required outcome.
  2. From a command prompt, run your script.
  3. When the code finishes running, the specified pool member is enabled or disabled in each pool and on each device on which it resides.

Code :

#!/usr/bin/perl
use SOAP::Lite;
use UNIVERSAL 'isa';

$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;

# Description: Enables/Disables a pool member in all pools of all BIG-IP devices managed by EM.
# Usage: test-icontrolproxy-pool-member-state.pl host uid pwd pool_member enable|disable

#----------------------------------------------------------------------------
# Validate Arguments
#----------------------------------------------------------------------------
my $sHost = $ARGV[0];        # EM Host
my $sUID = $ARGV[1];        # EM User (administrator role)
my $sPWD = $ARGV[2];        # EM Password
my $sPoolMember = $ARGV[3];    # BIG-IP Pool Member
my $sState = $ARGV[4];        # BIG-IP Pool Member State: enable/disable

my $proxy_uri = sprintf("https://%s:443/iControl/iControlPortal.cgi", $sHost);
my $soap = SOAP::Lite->proxy($proxy_uri);

sub SOAP::Transport::HTTP::Client::get_basic_credentials {
    return $sUID => $sPWD;
}

sub checkResponse {
    my ($resp) = (@_);
    die "$resp->faultcode $resp->faultstring\n" if $resp->fault;
      
    if (@{$resp->result}) {
        print "\tItem: $_\n" foreach (@{$resp->result});
    }
    else {
        printf "\tResult: %s\n", $resp->result;
    }
}

sub getPoolList()
{
    $soapResponse = $soap->uri("urn:iControl:LocalLB/Pool")->get_list();
    &checkResponse($soapResponse);
    my @pool_list = @{$soapResponse->result};
    
    return @pool_list;
}

sub getMemberLists()
{
    my (@pool_list) = (@_);
    
    # Get the list of pool members for all the pools.
    $soapResponse = $soap->uri("urn:iControl:LocalLB/Pool")->get_member
    (
        SOAP::Data->name(pool_names => [@pool_list])
    );
    &checkResponse($soapResponse);
    @member_lists = @{$soapResponse->result};
    
    return @member_lists;
}

sub findPoolsFromMember()
{
    my ($node_addr_port) = (@_);
    my ($node_addr, $node_port) = split(/:/, $node_addr_port, 2);
    my @pool_match_list;
    
    my @pool_list = &getPoolList();
    my @member_lists = &getMemberLists(@pool_list);

    for $i (0 .. $#pool_list)
    {
        $pool = @pool_list[$i];
        foreach $member (@{@member_lists[$i]})
        {
            $addr = $member->{"address"};
            $port = $member->{"port"};
            
            if ( ($node_addr eq $addr) && ($node_port eq $port) )
            {
                push @pool_match_list, $pool;
            }
        }
    }
    return @pool_match_list;
}

sub setPoolMemberState()
{
    my ($node_addr_port, $state) = (@_);
    my ($node_addr, $node_port) = split(/:/, $node_addr_port, 2);
    my @pool_list = &findPoolsFromMember($node_addr_port);
    my $member = { address => $node_addr, port => $node_port };
    my $ENABLED_STATE = "STATE_ENABLED";
    
    if ( $state eq "disable" )
    {
        $ENABLED_STATE = "STATE_DISABLED";
    }
    
    my $MemberMonitorState  = { member => $member, monitor_state => $ENABLED_STATE };
    my @MemberMonitorStateList;
    push @MemberMonitorStateList, $MemberMonitorState;
    
    my @MemberMonitorStateLists;
    for $i (0 .. $#pool_list)
    {
        push @MemberMonitorStateLists, [@MemberMonitorStateList];
    }
    
    # Make call to set_monitor_state 
    $soapResponse = $soap->uri("urn:iControl:LocalLB/PoolMember")->set_monitor_state(
        SOAP::Data->name(pool_names => [@pool_list]),
        SOAP::Data->name(monitor_states => [@MemberMonitorStateLists])
    );
    &checkResponse($soapResponse);
    
    print "Pool member $node_addr_port set to $ENABLED_STATE in pools: ";
    foreach $pool (@pool_list)
    {
        print "$pool, ";
    }
    print "\n";
}

#----------------------------------------------------------------------------
# Main application entry point.
#----------------------------------------------------------------------------

# EM: get devices.
print "\nGet devices...\n";
my $resp = $soap->uri('urn:iControl:Management/EM')->get_devices();
my $device_list = $resp->result;

# EM: generate a context ID.
print "\nGenerate context ID...\n";
$resp = $soap->uri("urn:iControl:Management/EM")->get_context_id();
my $context_id = $resp->result;

# Append context ID to SOAP URI.
$proxy_uri = sprintf("%s?context_id=%s", $proxy_uri, $context_id);
$soap = SOAP::Lite->proxy($proxy_uri);

# Iterate through the device list.
foreach (@{$device_list}) {

    # Get current device address.
    my $device = $_;

    # EM: set device context (to proxy to).
    print "\nSet device context...\n";
    $resp = $soap->uri("urn:iControl:Management/EM")->set_device_context(SOAP::Data->name("ip_address" => $device));
    &checkResponse($resp);
    
    # Set pool member state.
    &setPoolMemberState($sPoolMember, $sState);
}
Published Mar 07, 2015
Version 1.0
  • RickB's avatar
    RickB
    Icon for Nimbostratus rankNimbostratus

    I had the same problem.

    Requires adding additional (missing) Perl RPM packages.

    • Still have not identified all of them
    • Require software/packages needs to be posted here as prerequisites