I ran into a problem recently when disabling NSX in my lab where I couldn’t remove a logical segment. This logical segment was previously attached to NSX Edge virtual machines. The logical segments still had a stale port, even after the Edge virtual machines were deleted.
Any attempt to delete the segment through UI/API resulted in the error “Segment has 1 VMs or VIFs attached. Disconnect all VMs and VIFs before deleting a segment.”
GUI Error
API Error
So how do I delete the stale segments in this case? The answer is through API, but before deleting the segments, you must delete the stale VIFs.
Follow the procedure given below to delete stale VIFs.
1: List Logical Ports associated with the Stale Segment
1 2 3 |
Method: GET URL: https://{{nsx_mgr}}/api/v1/logical-ports |
This API call will list all segments. You can pass the segment uuid in the above command to list a specific segment (stale one).
The response to this API call returns a json where you can find the VIF UUID.
2: Grab the logical port ID from the response json.
3: Delete Logical Port
1 2 3 |
Method: DELETE URL: https://{{nsx_mgr}}/api/v1/logical-ports/<port-id>?detach=true |
4: Delete Logical Segment
Switch back to NSX UI and refresh the page. You will see the ports are now detached from the segment that you want to delete. You can delete the segments now.
I hope you enjoyed reading this post. Feel free to share this on social media if it is worth sharing.