Forum Discussion
Chris_Chaloux_1
Nimbostratus
Dec 22, 2009Power 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
}
- The_Bhattman
Nimbostratus
Hi Chris, - Chris_Chaloux_1
Nimbostratus
Thanks, Bhattman.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
- 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
MemberMonitorStateAofA.GetType();
IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True LocalLBPoolMemberMemberMonitorState[][] System.Array
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects