Forum Discussion

Chris_Chaloux_1's avatar
Chris_Chaloux_1
Icon for Nimbostratus rankNimbostratus
Dec 22, 2009

Power Shell Question - Disable Pool Member

Hello -

I'm running a power shell script that enables / disables a pool member. It is from the example scripts out her on DevCentral.

I have a question / issue. I want to force a node off line - not just disable it. In researching this, it seems as though if the SessionState is "State_Disabled" and the MonitorState is "State_Disabled" that it should infact force the node offline. When I call the function to do this, it appears that the member is only "disabled" and not forced offline. Can someone review the below function and see if I'm doing this correctly or how I can fix this?

Thanks!!

Chris

 
 function Disable-Member() 
 { 
   param($pool_name, $member); 
     $vals = $member.Split( (, ':')); 
       $member_addr = $vals[0]; 
         $member_port = $vals[1]; 
            Write-Host "Disabling Session Enabled State..."; 
              $MemberSessionState = New-Object -TypeName iControl.LocalLBPoolMemberMemberSessionState; 
              $MemberSessionState.member = New-Object -TypeName iControl.CommonIPPortDefinition;   
              $MemberSessionState.member.address = $member_addr;   
              $MemberSessionState.member.port = $member_port;   
              $MemberSessionState.session_state = "STATE_DISABLED";   
              $MemberSessionStateAofA = New-Object -TypeName "iControl.LocalLBPoolMemberMemberSessionState[][]" 1,1 
              $MemberSessionStateAofA[0][0] = $MemberSessionState;   
              (Get-F5.iControl).LocalLBPoolMember.set_session_enabled_state( (, $pool_name), $MemberSessionStateAofA);  
               Write-Host "Waiting for current connections to drop to zero..." 
              $MemberDef = New-Object -TypeName iControl.CommonIPPortDefinition;   
              $MemberDef.address = $member_addr;   
              $MemberDef.port = $member_port;    
              $MemberDefAofA = New-Object -TypeName "iControl.CommonIPPortDefinition[][]" 1,1   
              $MemberDefAofA[0][0] = $MemberDef; 
                 $cur_connections = 1; 
                    while ( $cur_connections -gt 0 ) 
                      {    $MemberStatisticsA = (Get-F5.iControl).LocalLBPoolMember.get_statistics( (, $pool_name), $MemberDefAofA); 
                           $MemberStatisticEntry = $MemberStatisticsA[0].statistics[0]; 
                           $Statistics = $MemberStatisticEntry.statistics;     
                           foreach ($Statistic in $Statistics)     
                           {      $type = $Statistic.type; 
                                  $value = $Statistic.value; 
                                             if ( $type -eq "STATISTIC_SERVER_SIDE_CURRENT_CONNECTIONS" ) 
                                                   {         just use the low value.  Odds are there aren't over 2^32 current connections. 
                                                             If your site is this big, you'll have to convert this to a 64 bit number.         
                                                     $cur_connections = $value.low; 
                                                     Write-Host "Current Connections: $cur_connections"       
                                                   }     
                                                   }    Start-Sleep -s 1   
                                                   }   
                                                   Write-Host "Disabling Monitor State..."; 
                                                     $MemberMonitorState = New-Object -TypeName iControl.LocalLBPoolMemberMemberMonitorState;   
                                                     $MemberMonitorState.member = New-Object -TypeName iControl.CommonIPPortDefinition;   
                                                     $MemberMonitorState.member.address = $member_addr;   
                                                     $MemberMonitorState.member.port = $member_port;   
                                                     $MemberMonitorState.monitor_state = "STATE_DISABLED";   
                                                     $MemberMonitorStateAofA = New-Object -TypeName "iControl.LocalLBPoolMemberMemberMonitorState[][]" 1,1   
                                                     $MemberMonitorStateAofA[0][0] = $MemberMonitorState;    
                                                     (Get-F5.iControl).LocalLBPoolMember.set_monitor_state( (, $pool_name), $MemberMonitorStateAofA); 
                                                      Get-PoolMemberStatus $pool_name $member 
                                                    } 
 

3 Replies

  • Hi Chris,

     

    Have you looked at the following article

     

     

    http://devcentral.f5.com/Default.aspx?tabid=53&view=topic&postid=84952

     

     

    Bhattman
  • Thanks, Bhattman.

    I had looked at it previously. Just to see if it will work for me out of the box I ran it. Some functions work great while the most important one I need to have work returns the following exception:

       
     Cannot convert argument "1", with value: "System.Object[]", for "set_monitor_state" to type "iControl.LocalLBPoolMemberMemberMonitorState[][]": "Cannot convert the "S 
     ystem.Object[]" value of type "System.Object[]" to type "iControl.LocalLBPoolMemberMemberMonitorState[]"." 
     At D:\webeng\scripts\F5\alter_node_status2.ps1:261 char:64 
     +           (Get-F5.iControl).LocalLBPoolMember.set_monitor_state <<<< ( 
         + CategoryInfo          : NotSpecified: ( [], MethodException 
         + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument 
       

    What am I missing!?!
  • I cut and pasted your code directly from the post above and ran in in my PoolMemberControl.ps1 script and it worked.

     

     

    PS C:\> .\PoolMemberControl.ps1 bigip user pass mypool 10.10.10.148: 
     80 disable 
     Disabling Session Enabled State... 
     Waiting for current connections to drop to zero... 
     Current Connections: 0 
     Disabling Monitor State... 
     Pool mypool, Member 10.10.10.148:80 status: 
       Availability : AVAILABILITY_STATUS_RED 
       Enabled      : ENABLED_STATUS_DISABLED 
       Description  : Forced down

     

     

    Which version of PowerShell are you using? I'm working with v2.0 right now.

     

     

    Try tossing in this line before the call to set_monitor_state():

     

     

    MemberMonitorStateAofA.GetType();

     

     

    It should print out something like this:

     

     

    IsPublic IsSerial Name                                     BaseType 
     -------- -------- ----                                     -------- 
     True     True     LocalLBPoolMemberMemberMonitorState[][]  System.Array

     

     

    -Joe