Skip to content

Commit 83cc33b

Browse files
committed
Update VMware.CloudFoundation.InstanceRecovery.psm1
Add NSX version conditional check to Remove-NonResponsiveHosts
1 parent 0f3d2ac commit 83cc33b

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

VMware.CloudFoundation.InstanceRecovery.psm1

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,27 +2926,29 @@ Function Remove-NonResponsiveHosts {
29262926
$clusterComputeCollectionId = ($computeCollections.results | Where-Object { $_.cm_local_id -eq $clusterMoRef }).external_id
29272927
$clusterVlcmManaged = (($computeCollections.results | Where-Object { $_.cm_local_id -eq $clusterMoRef }).origin_properties | Where-Object { $_.key -eq "lifecycleManaged" }).value
29282928
$uri = "https://$nsxManagerFqdn/api/v1/fabric/compute-collections/$($clusterComputeCollectionId)?action=remove_nsx"
2929-
$detachTNP = Invoke-WebRequest -Method POST -URI $uri -ContentType application/json -headers $headers
29302929

2931-
#Wait for Hosts to be Orphaned
2932-
Foreach ($hostID in $hostIDs) {
2933-
LogMessage -type WAIT -message "[$nsxManagerFqdn] Waiting for Host $(($allHostTransportNodes | Where-Object {$_.id -eq $hostID}).display_name) to be `'Orphaned`'"
2934-
Do {
2935-
$uri = "https://$nsxManagerFqdn/api/v1/transport-nodes/$($hostID)/state"
2936-
$tnState = (Invoke-WebRequest -Method GET -URI $uri -ContentType application/json -headers $headers).content | ConvertFrom-Json
2937-
} Until ($tnState.state -eq "orphaned")
2938-
}
2930+
If ($nsxManagerVersion -ge "412") {
2931+
$detachTNP = Invoke-WebRequest -Method POST -URI $uri -ContentType application/json -headers $headers
29392932

2940-
#Attempt to Force Delete the Transport Nodes
2941-
Foreach ($hostID in $hostIDs) {
2942-
If ($nsxManagerVersion -le "313") {
2943-
$uri = "https://$nsxManagerFqdn/api/v1/fabric/nodes/$($hostID)?unprepare_host=false"
2944-
} else {
2945-
$uri = "https://$nsxManagerFqdn/api/v1/transport-nodes/$($hostID)?force=true&unprepare_host=false"
2933+
#Wait for Hosts to be Orphaned
2934+
Foreach ($hostID in $hostIDs) {
2935+
LogMessage -type WAIT -message "[$nsxManagerFqdn] Waiting for Host $(($allHostTransportNodes | Where-Object {$_.id -eq $hostID}).display_name) to be `'Orphaned`'"
2936+
Do {
2937+
$uri = "https://$nsxManagerFqdn/api/v1/transport-nodes/$($hostID)/state"
2938+
$tnState = (Invoke-WebRequest -Method GET -URI $uri -ContentType application/json -headers $headers).content | ConvertFrom-Json
2939+
} Until ($tnState.state -eq "orphaned")
29462940
}
2947-
LogMessage -type INFO -message "[$nsxManagerFqdn] Removing Transport Node associated with $(($allHostTransportNodes | Where-Object {$_.id -eq $hostID}).display_name)"
2948-
$deleteTN = Invoke-WebRequest -Method DELETE -URI $uri -ContentType application/json -headers $headers
29492941
}
2942+
#Attempt to Force Delete the Transport Nodes
2943+
Foreach ($hostID in $hostIDs) {
2944+
If ($nsxManagerVersion -le "313") {
2945+
$uri = "https://$nsxManagerFqdn/api/v1/fabric/nodes/$($hostID)?unprepare_host=false"
2946+
} else {
2947+
$uri = "https://$nsxManagerFqdn/api/v1/transport-nodes/$($hostID)?force=true&unprepare_host=false"
2948+
}
2949+
LogMessage -type INFO -message "[$nsxManagerFqdn] Removing Transport Node associated with $(($allHostTransportNodes | Where-Object {$_.id -eq $hostID}).display_name)"
2950+
$deleteTN = Invoke-WebRequest -Method DELETE -URI $uri -ContentType application/json -headers $headers
2951+
}
29502952

29512953
#Wait for Transport Nodes to flush
29522954
LogMessage -type WAIT -message "[$nsxManagerFqdn] Waiting for Transport Nodes to flush"

0 commit comments

Comments
 (0)