The Latest Gartner® Magic Quadrant™Hyperconverged Infrastructure Software
Moderators: anton (staff), art (staff), Max (staff), Anatoly (staff)
Code: Select all
#
# Get synchronization status of specified HA device and if there is a need run synchronization
#
"GetHASYncState -- KW version"
Import-Module StarWindX
while ($true) {
"------------- Running ---------------"
try
{
#
# connect to the server
#
$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind
$server.Connect()
#
# Try to find specified device
#
$deviceName = "*"
$partnerTargetName = "*"
$deviceFound = $false
foreach($device in $server.devices)
{
$device.Refresh()
$syncStatus = $device.GetPropertyValue("ha_synch_status")
Write-Host ""
Write-Host -NoNewline "DeviceName:" $device.GetPropertyValue("DeviceName") -foreground yellow
If ( $syncStatus -gt "" )
{
$state = $device.GetPropertyValue("state")
Write-Host " -- TargetName:" $device.GetPropertyValue("TargetName")
Write-Host -foreground yellow -NoNewline "Device state:" $state
$stateText = switch ($state)
{
0 { " (Active)" }
1 { " (NonActive)" }
2 { " (NotLicensed)" }
3 { " (Disabled)" }
default { "(Undefined)" }
}
Write-Host $stateText -foreground yellow
Write-Host -NoNewline "Sync Status:" $syncStatus "" -foreground yellow
$waitForAutoSync = $device.GetPropertyValue("ha_wait_on_autosynch")
if ( $waitForAutoSync -eq "1" )
{
Write-Host "(Waiting for autosynchronization)" -foreground yellow
}
else
{
if ( $syncStatus -eq "1" )
{
#
# Device is synchronized. Get synchronization percent and show it
#
$syncPercent = $device.GetPropertyValue("ha_synch_percent")
Write-Host "(Synchronized) -- $($syncPercent)%" -foreground yellow
}
if ( $syncStatus -eq "2" )
{
#
# Device is synchronizing. Get synchronization percent and show it
#
$syncPercent = $device.GetPropertyValue("ha_synch_percent")
Write-Host "(Synchronizing) -- $($syncPercent)%" -foreground yellow
}
if ( $syncStatus -eq "3" )
{
#
# Device not synchronized. Synchronize current node from partner
#
Write-Host "Device not synchronized."
# Synchronize current node from partner '$($partnerTargetName)'" -foreground yellow
# $params = new-object -ComObject StarWindX.Parameters
# $params.AppendParam("deviceID",$device.DeviceId)
# $params.AppendParam("partnetTargetName",$partnerTargetName)
# $server.ExecuteCommand( 0, "restoreHAPartnerNode", $params)
#
# If you want to synchronize partners from current node you can comment out code above and uncomment section below
#
# Device not synchronized. Mark current node as 'Synchronized'.
# WARNING, Command changes Device Status to "Synchronized" without Data Synchronization with HA (High Availability) Partner,
# Device will start processing Client Requests immediately and will be used as Data Synchronization Source for Partner Device.
#
#Write-Host "Device not synchronized. Mark current node as 'Synchronized'. " -foreground yellow
#$params = new-object -ComObject StarWindX.Parameters
#$params.AppendParam("deviceID",$device.DeviceId)
#$server.ExecuteCommand( 0, "restoreCurrentHANode", $params)
# Start-Sleep -m 5000
}
}
#=======
Write-Host "ha_partner_nodes_count:" $device.GetPropertyValue("ha_partner_nodes_count")
$status = $device.GetPropertyValue("ha_partner_node1_sync_status")
$statusText = switch ($device.GetPropertyValue("ha_partner_node1_sync_status") )
{
1 { " (Synchronized)" }
2 { " (Synchronizing)" }
3 { " (NOT Synchronized)" }
default { "(Undefined)" }
}
Write-Host "ha_partner_node1_sync_status: $($status)$($StatusText) --" `
$device.GetPropertyValue("ha_partner_node1_sync_percent"), "%"
Write-Host "ha_partner_node1_is_exist_sync_valid_connection:" `
$device.GetPropertyValue("ha_partner_node1_is_exist_sync_valid_connection")
Write-Host "ha_partner_node1_is_exist_heartbeat_valid_connection:" `
$device.GetPropertyValue("ha_partner_node1_is_exist_heartbeat_valid_connection")
# Write-Host "ha_partner_node2_sync_status:" $device.GetPropertyValue("ha_partner_node2_sync_status")
# Write-Host "ha_partner_node2_sync_percent:" $device.GetPropertyValue("ha_partner_node2_sync_status")
}
else
{
write-host -NoNewLine " -- no info"
}
}
# if ( $deviceFound -ne $true )
# {
# Write-Host "$($deviceName) not found" -foreground red
# }
}
catch
{
Write-Host "Exception $($_.Exception.Message)" -foreground red
}
Write-Host ""
$server.Disconnect( )
pause
}
Code: Select all
#modified KW
#NOTE, running on ANY node sets Maintenance mode for a given device on ALL nodes.
#Cluster services should be fully stopped BEFORE using maintenance mode. and all devices should be put into maintenance mode together
param(
$addr="127.0.0.1", $port=3261, $user="root", $password="starwind", `
$deviceName1="HAImage1", `
$deviceName2="HAImage2",`
[string]$enable=$true,`
[string]$force=$true
)
Import-Module StarWindX
switch( $Host.UI.PromptForChoice("VSAN Mode Selection",`
"Set StarWind Maintenance Mode", `
@("Enable"; "Enable with FORCE"; "Disable"; "Cancel" ),3) )
{
0 { $enable=$true
$force=$false
Write-Host "Enable selected WITHOUT Force" }
1 { $enable=$true
$force=$true
Write-Host "Enable selected WITH Force" }
2 { $enable=$false
Write-Host "Disable selected" }
3 { Write-Host "Cancelled -- no action taken"
exit }
}
Pause
try
{
Enable-SWXLog
$server = New-SWServer $addr $port $user $password
$server.Connect()
#device 1
$device = Get-Device $server -name $deviceName1
if( !$device )
{
Write-Warning "Device {$deviceName1} not found"
return
}
#params: enable, force
$device.SwitchMaintenanceMode([bool]::Parse($enable), [bool]::Parse($force))
Write-Host $deviceName1 "maintenance mode enablement now:" $enable
#device 2
$device = Get-Device $server -name $deviceName2
if( !$device )
{
Write-Warning "Device {$deviceName2} not found"
return
}
#params: enable, force
$device.SwitchMaintenanceMode([bool]::Parse($enable), [bool]::Parse($force))
Write-Host $deviceName2 "maintenance mode enablement now:" $enable
}
catch
{
Write-Error $_
exit 1
}
finally
{
# $server.Disconnect()
Write-Host "Maintenance mode status may be verified in the StarWind Management Console"
}
As DCs, we recommend using 2 local VMs rather than clustered ones. Learn more at https://knowledgebase.starwindsoftware. ... san-usage/.but the domain controllers are virtual guests of the cluster, so can't be reached while bringing up cluster services if the whole cluster is offline.
Can I have the logs please, to confirm that the devices are synchronized? Please collect the logs with StarWind Log Collector (https://knowledgebase.starwindsoftware. ... collector/) and transfer them via Google Disk.Devices that report as Synchronized in both PowerShell and the StarWind Management Console are showing 0% synchronized
The reporting thing has something to do with the priorities. Synchronized 0% is for the secondary, synchronized 100% is for primary.synchronized-0% reporting from PowerShell hasn't changed.