Advertisement
Guest User

Untitled

a guest
Jan 4th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ######################################################################################################################################
  3. #
  4. #                                               Start of config section
  5. #
  6. ######################################################################################################################################
  7.  
  8. #Setup Credentials
  9. $UserName = ''
  10. $Password = ''
  11.  
  12. #Which BigIP you're going to connect to
  13. $BigipIP = ""
  14.  
  15. ######################################################################################################################################
  16. #
  17. #                                               Start of config section
  18. #
  19. ######################################################################################################################################
  20.  
  21. if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null ){
  22.     Add-PSSnapIn iControlSnapIn
  23. }
  24.  
  25. #Setup the F5 interface
  26. $success = Initialize-F5.iControl -HostName $BigipIP -Username $UserName -Password $Password;
  27. $f5 = Get-F5.iControl
  28.  
  29. #Get the partitions
  30. $f5partitions = $f5.ManagementPartition
  31.  
  32. Function Toogle-Pool-Member {
  33.  
  34.     Param(  [string]$Pool = "",
  35.             [string]$Partition = "",
  36.             [array]$Members = @(),
  37.             [string]$State = "",
  38.             [switch]$All = $false
  39.         )
  40.    
  41.     #Is the State set to something
  42.     if(!($State.tolower() -eq "enable" -or $State.tolower() -eq "disable")){
  43.         Return "Please set state to Enable or Disable"
  44.     }
  45.    
  46.     #Does the member exist
  47.     if($Members.Count -eq 0 -and $All -eq $false){
  48.         Return "Specify member or set the all flag."   
  49.     } elseif($Members.Count -gt 0 -and $All){
  50.         Return "All flag can't be specified if you defined a member."
  51.     }
  52.    
  53.     #Was a partition specified
  54.     if($Partition -eq ""){
  55.         Return "Please specify a partition"
  56.     }
  57.    
  58.     #Was a Pool name specified
  59.     if($Pool -eq ""){
  60.         Return "Please specify a pool" 
  61.     }
  62.    
  63.     #Set the active partition
  64.     $f5partitions.set_active_partition($Partition)
  65.    
  66.     #Add the partition to the pool
  67.     $Pool = "/" + $Partition + "/" + $Pool
  68.    
  69.     #Check if the pool exists and get a memberlist if it does
  70.     $PoolMembers = $F5.LocalLBPool.get_member_v2($Pool)[0]
  71.    
  72.     if(!$PoolMembers){
  73.         Return "Pool did not exist."
  74.     }
  75.    
  76.    
  77.     if(!$All){
  78.        
  79.         #The All flag has not been called. Enabling/disabling per member
  80.        
  81.         $AddressPortList = New-Object -TypeName iControl.CommonAddressPort[] $Members.Length
  82.        
  83.         #Create a CommonAddressPort list with all members specified in the parameters
  84.        
  85.         for($i=0; $i-lt $Members.Length; $i++){
  86.            
  87.             $Address = $Members[$i].Split(":")[0]
  88.             $Port = $Members[$i].Split(":")[1]
  89.            
  90.             $AddressPortList[$i] = New-Object -TypeName iControl.CommonAddressPort;    
  91.             $AddressPortList[$i].address = $Address
  92.             $AddressPortList[$i].port = $Port
  93.         }
  94.        
  95.         #Check the state specified
  96.        
  97.         if($State.tolower() -eq "enable"){
  98.             $State = "STATE_ENABLED"
  99.         } else {
  100.             $State = "STATE_DISABLED"
  101.         }
  102.        
  103.         #Create a list to tie the state to every member specified
  104.         $MemberStateList = New-Object -TypeName iControl.CommonEnabledState[] $Members.Length
  105.        
  106.         for($i=0; $i-lt $Members.Length; $i++){
  107.             $MemberStateList[$i] = New-Object -TypeName iControl.CommonEnabledState;       
  108.             $MemberStateList[$i] = $State
  109.         }
  110.        
  111.         #Disable/enable the pool members
  112.         $F5.LocalLBPool.set_member_session_enabled_state(
  113.             (,$Pool),
  114.             (,$AddressPortList),
  115.             (,$MemberStateList)
  116.         )
  117.    
  118.     } else {
  119.        
  120.        
  121.         $MemberStateList = New-Object -TypeName iControl.CommonEnabledState[] $PoolMembers.Length
  122.        
  123.         #Check the state specified
  124.         if($State.tolower() -eq "enable"){
  125.             $State = "STATE_ENABLED"
  126.         } else {
  127.             $State = "STATE_DISABLED"
  128.         }
  129.        
  130.         #Create a list to tie the state to every member specified
  131.         for($i=0; $i-lt $PoolMembers.Length; $i++){
  132.             $MemberStateList[$i] = New-Object -TypeName iControl.CommonEnabledState;       
  133.             $MemberStateList[$i] = $State
  134.         }
  135.        
  136.         #Disable/enable all pools
  137.        
  138.         $F5.LocalLBPool.set_member_session_enabled_state(
  139.             (,$Pool),
  140.             (,$PoolMembers),
  141.             (,$MemberStateList)
  142.         )
  143.     }
  144.        
  145. }
  146.  
  147. #Examples
  148. #Note that all pool names, partitions etc are case sensitive.
  149. #
  150. #Enable Myserver in the pool Test-Pool under partition Common
  151. #Toogle-Pool-Member -Pool Test-Pool -Partition Common -Members @("Myserver:80") -State Enable
  152.  
  153. #Disable all members in the pool Test-Pool under partition Common
  154. #Toogle-Pool-Member -Pool Test-Pool -Partition Common -All -State Disable
  155.  
  156. #Disable Myserver-01 and Myserver-02 in pool testpool under partition MyPartition
  157. #Toogle-Pool-Member -Pool testpool -Partition MyPartition -Members @("MyServer-01:80", "Myserver-02:80") -State Enable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement