Lab spring clean

I may be a little early here, but I’m currently carrying out a bit of a spring clean in the lab. Why? Well, as I mentioned in my first post I have built many different nested environments, as you can imagine with little in the way of documentation on the build, there’s absolutely nothing in the way of a decommissioning process! As a result, the lab is in a bit of a, well a mess. I thought I would make a start at the networking layer, confirming what details I do have in my IPAM (I have tried to keep some documentation) match those that exist. You’ll never guess what, they don’t match! Time to purge some NSX segments that are no longer needed.

First segment for deletion is NSX-HCX-Segment-Primary. As the below screenshot from vCenter shows there aren’t any VM’s connected to this segment.

Into NSX Manager, I browsed to the segment, selected delete and there’s where my issue started. Now I’ll admit, I didn’t pay any attention to the NSX Manager screen – if I had done I would have known that this wasn’t going to work. I’m not able to delete the segment as there is still a VIF attached.

Odd, I saw in vCenter before even logging into NSX that there were no VM’s connected. Browsing the connected ports on the segment, sure enough it showed a connection from a VM that would have been connected once upon a time, yet no longer existed.

I tried a few things to start with, changing the admin status of the segment port to down, I still couldn’t delete. I tried changing the admin state of the segment, the connectivity state, nothing I tried allowed me to delete the segment.

I turned to the documentation, after a bit of reading I found myself in the NSX-T API guide here. At this point I turned to Postman. Running the following GET API call https://{{baseUrl}}/policy/api/v1/infra/segments/NSX-HCX-Segment-Primary/ports I was able to determine the segment port ID.

In this case the port ID is "default: 54b8ff80-6b8b-4255-8c51-be8fc85e09da" the next step I took was to run the following get API call https://{{baseUrl}}/api/v1/logical-ports/54b8ff80-6b8b-4255-8c51-be8fc85e09da presenting the details about the VIF.

Now comes the deletion point, a standard delete API call fails "Unable to delete logical port with attachments of LogicalPort LogicalPort/54b8ff80-6b8b-4255-8c51-be8c85e09da." One final step, forcefully deleting the VIF using the detach key within the API call. Done by using the delete API call https://{{baseUrl}}/api/v1/logical-ports/54b8ff80-6b8b-4255-8c51-be8fc85e09da?detach=true the difference here being ?detach=true at the end of the string, success! The following link will take you right to the “Delete a Logical Port” section of the NSX-T API guide for reference.

Success! After a short time, NSX manager then updated and the segment showed zero ports connected.

I was then able to delete the segment via NSX Manager as expected.

One Comment

Leave a Comment

Your email address will not be published. Required fields are marked *