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.

PowerShell PoolMember Ratio And Priority

Problem this snippet solves:

This sample PowerShell script illustrates how to use the methods in the LocalLB::Pool interface to get and set the Ratio and Priority for a Pool Member.

Note, this example uses the new pool member methods in the LocalLB Pool interface introduced in BIG-IP v11.0

Code :

#----------------------------------------------------------------------------
# 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-2012
# 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.
#----------------------------------------------------------------------------
param (
  $BIGIP = $null,
  $User = $null,
  $Pass = $null,
  $Pool = $null,
  $Member = $null,
  $Ratio = $null,
  $Priority = $null
)

#-------------------------------------------------------------------------
# function Show-Usage
#-------------------------------------------------------------------------
function Show-Usage()
{
  Write-Host @"
Usage: PoolMemberRatioPriority.ps1 BIGIP User Pass Pool Member Ratio Priority
Examples
  .\PoolMemberRatioPriority.ps1 -BIGIP bigip -User user -Pass pass : list pools
  .\PoolMemberRatioPriority.ps1 -BIGIP bigip -User user -Pass pass -Member ipport : list pool members
  .\PoolMemberRatioPriority.ps1 -BIGIP bigip -User user -Pass pass -Member ipport -Ratio 5 : set member ratio to 5
  .\PoolMemberRatioPriority.ps1 -BIGIP bigip -User user -Pass pass -Member ipport -Priority 3 : set member priority to 3
"@
  exit;
}



#----------------------------------------------------------------------------
function Do-Initialize()
#----------------------------------------------------------------------------
{
  if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null )
  {
    Add-PSSnapIn iControlSnapIn
  }
  $success = Initialize-F5.iControl -HostName $BIGIP -Username $User -Password $Pass;
  
  return $success;
}

function Parse-AddressPort()
{
  param($Value);
  $tokens = $Value.Split(":");
  $r = New-Object iControl.CommonAddressPort;
  $r.address = $tokens[0];
  $r.port = $tokens[1];
  $r;
}

function Get-Pools()
{
  (Get-F5.iControl).LocalLBPool.get_list();
}

function Get-PoolMembers()
{
  param(
    $Pool = $null
  );
  $MemberListAofA = (Get-F5.iControl).LocalLBPool.get_member_v2( @($Pool) );
  $MemberListA = $MemberListAofA[0];
  $MemberListA;
}

function Get-PoolMemberDetails()
{
  param(
    $Pool = $null,
    $Member = $null
  );
  
  $AddrPort = Parse-AddressPort $Member;
  
  $RatioAofA = (Get-F5.iControl).LocalLBPool.get_member_ratio(
    @($Pool),
    @( @($AddrPort) )
  );
  
  $PriorityAofA = (Get-F5.iControl).LocalLBPool.get_member_priority(
    @($Pool),
    @( @($AddrPort) )
  );
  
  $ratio = $RatioAofA[0][0];
  $priority = $PriorityAofA[0][0];
  
  "Pool '$Pool' member '$Member' ratio '$ratio' priority '$priority'";
  
}

function Set-PoolMemberDetails()
{
  param(
    $Pool = $null,
    $Member = $null,
    $Ratio = $null,
    $Priority = $null
  );

  $AddrPort = Parse-AddressPort $Member;
  
  if ( $null -ne $Ratio )
  {
    (Get-F5.iControl).LocalLBPool.set_member_ratio(
      @($Pool),
      @( @($AddrPort) ),
      @($Ratio)
    );
  }
  if ( $null -ne $Priority )
  {
    (Get-F5.iControl).LocalLBPool.set_member_priority(
      @($Pool),
      @( @($AddrPort) ),
      @($Priority)
    );
  }
}

#-------------------------------------------------------------------------
# Main Application Logic
#-------------------------------------------------------------------------

if ( ($BIGIP -eq $null) -or ($User -eq $null) -or ($Pass -eq $null) )
{
  Show-Usage;
}

if ( Do-Initialize )
{
  if ( $Pool -eq $null ) 
  {
    # List Pools
    Get-Pools;
  }
  elseif ( $Member -eq $null )
  {
    # List Pool Members
    Get-PoolMembers -Pool $Pool;
  }
  elseif ( ($Ratio -eq $null) -and ($Priority -eq $null) )
  {
    # List Pool Member Details
    Get-PoolMemberDetails -Pool $Pool -Member $Member;
  }
  else
  {
    # Set Ratio and/or Priority
    Set-PoolMemberDetails -Pool $Pool -Member $Member -Ratio $Ratio -Priority $Priority;
    Get-PoolMemberDetails -Pool $Pool -Member $Member;
  }
}
else
{
  Write-Error "ERROR: iControl subsystem not initialized"
}
Published Mar 09, 2015
Version 1.0

1 Comment