add check if there is something to failover

main
lub 3 years ago
parent 918522f4d0
commit baccf4dcfe

@ -4,6 +4,12 @@ $nodeList = docker node ls --format '{{json .}}'| ConvertFrom-Json | ForEach-Obj
docker node inspect $_.ID | ConvertFrom-Json
}
$onlineNodeList = $nodeList | Where-Object {$_.Spec.Availability -eq 'active'}
$offlineNodeList = $nodeList | Where-Object {$_.Spec.Availability -ne 'active'}
if (!$offlineNodeList.Count) {
Write-Output 'all hosts online, nothing to failover'
exit
}
$failoverAddressList = (Invoke-RestMethod -Uri 'https://robot-ws.your-server.de/failover' -Authentication Basic -Credential $hetznerCredentials).failover
$offlineAddressList = $failoverAddressList | Where-Object active_server_ip -notin $onlineNodeList.Status.Addr