@@ -3812,6 +3812,14 @@ Function Remove-NonResponsiveHosts {
38123812 $computeCollections = (Invoke-WebRequest - Method GET - URI $uri - ContentType application/ json - headers $headers ).content | ConvertFrom-Json
38133813 $clusterComputeCollectionId = ($computeCollections.results | Where-Object { $_.cm_local_id -eq $clusterMoRef }).external_id
38143814 $clusterVlcmManaged = (($computeCollections.results | Where-Object { $_.cm_local_id -eq $clusterMoRef }).origin_properties | Where-Object { $_.key -eq " lifecycleManaged" }).value
3815+
3816+ # Remove non-responsive hosts
3817+ Foreach ($nonResponsiveHost in $nonResponsiveHosts ) {
3818+ LogMessage - type INFO - message " [$ ( $nonResponsiveHost.name ) ] Removing from $clusterName "
3819+ Get-VMHost | Where-Object { $_.Name -eq $nonResponsiveHost.Name } | Remove-VMHost - Confirm:$false
3820+ }
3821+ Disconnect-VIServer - Server $global :DefaultVIServers - Force - Confirm:$false
3822+
38153823 $uri = " https://$nsxManagerFqdn /api/v1/fabric/compute-collections/$ ( $clusterComputeCollectionId ) ?action=remove_nsx"
38163824
38173825 If ($nsxManagerVersion -ge " 412" ) {
@@ -3828,48 +3836,23 @@ Function Remove-NonResponsiveHosts {
38283836 }
38293837 # Attempt to Force Delete the Transport Nodes
38303838 Foreach ($hostID in $hostIDs ) {
3831- $uri = " https://$nsxManagerFqdn /api/v1/transport-nodes/$ ( $hostID ) ?force=true&unprepare_host=false"
3839+ $uri = " https://$nsxManagerFqdn /api/v1/transport-nodes/$ ( $hostID ) ?force=true&unprepare_host=false"
38323840 LogMessage - type INFO - message " [$nsxManagerFqdn ] Removing Transport Node associated with $ ( ($allHostTransportNodes | Where-Object {$_.id -eq $hostID }).display_name) "
38333841 $deleteTN = Invoke-WebRequest - Method DELETE - URI $uri - ContentType application/ json - headers $headers
38343842 }
38353843
38363844 # Wait for Transport Nodes to flush
3837- LogMessage - type WAIT - message " [$nsxManagerFqdn ] Waiting for Transport Nodes to flush"
3838- $uri = " https://$nsxManagerFqdn /api/v1/transport-nodes/"
3845+ LogMessage - type WAIT - message " [$nsxManagerFqdn ] Waiting for Transport Nodes to flush. This Task May Take Some Time To Complete"
3846+ $body = ' {"primary": {"resource_type": "HostTransportNode"}}'
3847+ $uri = " https://$nsxManagerFqdn /policy/api/v1/search/aggregate?page_size=50"
38393848 Do {
3840- $transportNodeContents = (Invoke-WebRequest - Method GET - URI $uri - ContentType application/ json - headers $headers ).content | ConvertFrom-Json
3841- $allHostTransportNodes = ($transportNodeContents.results | Where-Object { ($_.resource_type -eq " TransportNode" ) -and ($_.node_deployment_info.os_type -eq " ESXI" ) })
3842- $deletedhostIDs = ($allHostTransportNodes | Where-Object { $_.display_name -in $clusterHosts }).id
3849+ $transportNodeContents = ((Invoke-WebRequest - Method POST - URI $uri - ContentType application/ json - headers $headers - body $body ).content | ConvertFrom-Json ).results
3850+ $deletedhostIDs = ($transportNodeContents.Primary | Where-Object { $_.display_name -in $clusterHosts }).id
38433851 } Until (! $deletedhostIDs )
38443852
3845- # Remove non-responsive hosts
3846- Foreach ($nonResponsiveHost in $nonResponsiveHosts ) {
3847- LogMessage - type INFO - message " [$ ( $nonResponsiveHost.name ) ] Removing from $clusterName "
3848- Get-VMHost | Where-Object { $_.Name -eq $nonResponsiveHost.Name } | Remove-VMHost - Confirm:$false
3849- }
3850- Disconnect-VIServer - Server $global :DefaultVIServers - Force - Confirm:$false
3851-
3852- # If VLCM cluster, wait until cleanup of cluster post TN delete is done
3853- If ($clusterVlcmManaged -eq " true" ) {
3854- $SecurePassword = ConvertTo-SecureString - String $nsxManagerRootPassword - AsPlainText - Force
3855- $mycreds = New-Object System.Management.Automation.PSCredential (" root" , $SecurePassword )
3856- $inmem = New-SSHMemoryKnownHost
3857- New-SSHTrustedHost - KnownHostStore $inmem - HostName $nsxManagerFQDN - FingerPrint ((Get-SSHHostKey - ComputerName $nsxManagerFQDN ).fingerprint) | Out-Null
3858- Do {
3859- $sshSession = New-SSHSession - computername $nsxManagerFQDN - Credential $mycreds - KnownHost $inmem
3860- } Until ($sshSession )
3861- $nsxCommand = " grep -a `" .*RemoveNsxFromComputeCollectionActivity.*entity= 'ComputeCollectionMsg/$clusterComputeCollectionId .*phase= `' Begin`'`" /var/log/proton/nsxapi.log"
3862- LogMessage - type WAIT - message " [$nsxManagerFqdn ] Waiting for Cluster Image Cleanup to Complete"
3863- Do {
3864- Sleep 5
3865- $relevantUpdates = (Invoke-SSHCommand - timeout 30 - sessionid $sshSession.SessionId - command $nsxCommand ).output
3866- } Until ($relevantUpdates [-1 ] -like " *RemoveNsxFromComputeCollectionActivity*phase= `' Begin`' *next phase= `' Success!`' " )
3867- Remove-SSHSession - SSHSession $sshSession | Out-Null
3868- }
3869-
38703853 # Reattach TNP
38713854 # Get Transport Node Profiles
3872- $uri = " https://$nsxManagerFqdn /policy/api/v1/infra/host-transport-node-profiles"
3855+ $uri = " https://$nsxManagerFqdn /policy/api/v1/infra/host-transport-node-profiles"
38733856
38743857 $transportNodeProfiles = ((Invoke-WebRequest - Method GET - URI $uri - ContentType application/ json - headers $headers ).content | ConvertFrom-Json ).results
38753858 $clusterTransportNodeProfile = $transportNodeProfiles | where-object { $_.display_name -like " *$clusterName *" }
0 commit comments