For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Set Wideip Pool Member Ratio

Problem this snippet solves:

This example sets the ratio of a Wideip Pool Member

Code :

#!/usr/bin/perl
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 $sMember = $ARGV[ 5 ]
my $sMember_Port = $ARGV[ 6 ]
my $sRatio = $ARGV[ 7 ]
my $sProtocol = "http";


sub usage()
{
        die ("Usage: ratio-set.pl Host | Port| uid | pwd | pool-name | member_IP | Member_Port | Ratio_value \n");
}



if ( ($sHost eq "") or ($sPort eq "") or ($sUID eq "") or ($sPWD eq "") or ($sMember_Port eq "") or ($sPool eq "") or 
($sMember eq "") or ($sRatio eq "") ) 

{
        usage();
}

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

$GlobalPoolMember = SOAP::Lite
        -> uri('urn
        -> readable(1)
        -> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");


#----------------------------------------------------------------------------
# Attempt to add auth headers to avoid dual-round trip
#----------------------------------------------------------------------------
eval { $GlobalPoolMember->transport->http_request->header
(
        'Authorization' =>
        'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')-->
); };
eval { $GlobalPoolMember->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
#----------------------------------------------------------------------------
# Set Up correct input arrays for iControl call - set_ratio
#----------------------------------------------------------------------------
        $MEMBER = 
        {
                address => $sMember,
                port => $sMember_Port,
        };

        
        $RATIOS = 
        {
                member => $MEMBER,
                ratio => $sRatio,
        };
        
        @List = 
        (
                [$RATIOS]
        );
        
#----------------------------------------------------------------------------
# Send SOAP request to BIGIP/GTM
#----------------------------------------------------------------------------



        $soapResponse = $GlobalPoolMember->set_ratio
        (
                SOAP::Data->name(pool_names => [$sPool]),
                SOAP::Data->name(ratios => [@List])
        );
        &checkResponse($soapResponse);



#----------------------------------------------------------------------------
# checkResponse makes sure the error isn't a SOAP error
#----------------------------------------------------------------------------

sub checkResponse()
{
        my ($soapResponse) = (@_);
        if ( $soapResponse->fault )
        {
                print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";
                exit();
        }
}
Published Mar 09, 2015
Version 1.0
No CommentsBe the first to comment