Skip to content

Commit 978bcb3

Browse files
Update Remove-NonResponsiveHosts (#7)
Add NSX version conditional check to Remove-NonResponsiveHosts <!-- markdownlint-disable first-line-h1 no-inline-html --> <!-- Hidden Markdown: Do Not Update this Area. In order to have the best experience with our community, we recommend that you read the code of conduct and contributing guidelines before submitting a pull request. By submitting this pull request, you confirm that you have read, understood, and agreed to the project's code of conduct and contributing guidelines. Please use conventional commits to format the title of the pull request and the commit messages. For more information, please refer to https://www.conventionalcommits.org. -->. ### Summary <!-- Hidden Markdown: Do Not Update this Area. Add NSX version conditional check to Remove-NonResponsiveHosts to skip detachTNP in NSX versions older than 4.1.2 -->. ### Type <!-- Hidden Markdown: Do Not Update this Area. Please check the one(s) that applies to this pull request using "x". --> - [x] Bugfix - [ ] Enhancement or Feature - [ ] Code Style or Formatting - [ ] Documentation - [ ] Refactoring - [ ] Chore - [ ] Other Please describe:. ### Breaking Changes? <!-- Hidden Markdown: Do Not Update this Area. Please check the one that applies to this pull request using "x". If this pull request contains a breaking change, please describe the impact and mitigation path. --> - [ ] Yes, there are breaking changes. - [x] No, there are no breaking changes.. ### Test and Documentation <!-- Hidden Markdown: Do Not Update this Area. Please check the one(s) that applies to this pull request using "x". For bug fixes and enhancements/features, please ensure that tests and documentation have been completed and provide details. --> - [x] Tests have been completed. - [ ] Documentation has been added or updated. <!-- Hidden Markdown: Do Not Update this Area. Please describe the tests that have been completed and/or the documentation that has been added/updated. Tested against VCF 4.5.2 -->. ### Issue References <!-- Hidden Markdown: Do Not Update this Area. Is this related to any GitHub issue(s)? If so, please provide the issue number(s) that are closed or resolved by this pull request. For bug fixes and enhancements/features, please ensure that a GitHub issue has been created and provide the issue number(s) here. Please use the 'Closes' keyword followed by the a hash and issue number. This will link the pull request to the issue(s) and automatically close them when the pull request is merged. Example: Closes #000 Closes #1 -->. ### Additional Information <!-- Hidden Markdown: Do Not Update this Area. Please provide any additional information that may be helpful. -->
2 parents 51979af + 83cc33b commit 978bcb3

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)