Unable to delete a segment in NSX because of an orphaned logical port

imageFor one of our customers all NSX related questions are routed to me (pun intended). I received a customer ticket stating that they where not able to remove an unused NSX created port group although it is not in use while observing from vCenter.

After some investigating within NSX it was clear that this issues was caused by an orphaned logical port. NSX allows you to do allot of the config from the UI, but for some actions it is required to turn to the application programming interface (API). NSX provides a programmatic API to automate management activities. The API follows a resource-oriented architecture by using JSON object encoding. Clients interact with the management plane by using RESTful web service calls over HTTPS.

The API abstracts the object configuration that is stored in the NSX database.

Method Use Function
Get Retrieve details of single or multiple NSX objects Read
Post Create an NSX object such as a segment, gateway or transport node. Create
Put Modify all properties of an existing NSX object, or replace it. Update
Patch Modify some properties of an existing NSX object, or create an object. Partial update or modify
Delete Delete or remove an existing NSX object or multiple objects. Delete or remove

Lets first confirm the statement that the NSX created vCenter distributed port group is not in use from vCenter.

2023-03-20 11_01_20-admpqr_rplo01@10.240.2.14 - PMP RDP SESSION – Mozilla Firefox

When zooming in the related NSX Segment associated with this vCenter Distributed Port Group I notice that according to NSX there are two VM’s connected.

2023-03-20 11_01_59-admpqr_rplo01@10.240.2.14 - PMP RDP SESSION – Mozilla Firefox

To fix this issue we have to turn to the NSX API to allow us to remove these connected VM’s (that are not really connected, the are orphaned logical ports connected to this Logical Switch aka Segment). The tool I am using to interact with the API is called Postman. To be able to disconnect these orphaned logical ports we first need to identify the ID for this logical port, this ID is not viewable from the NSX UI.
To identify the ID for the logical port we want to disconnect we collect all logical ports in the environment. To do this we execute the following request via Postman.

GET https://NSX-T-MANAGER-FQDN/api/v1/logical-ports

When we receive the output for this query we first notice that a status 200 is returned. This response let is know that everything was executed correctly. In the output window we notice the following data. With key combination CTRL+F we are able to search through this output.

2023-03-20 10_54_01-admpqr_rplo01@10.240.2.14 - PMP RDP SESSION – Mozilla Firefox

Now that we know the ID for the logical port we want to disconnect we can execute our next API Call.

DELETE https://NSX-T-MANAGER-FQDN/api/v1/logical-ports/<LogicalPortID>?detach=true

2023-03-20 10_55_41-admpqr_rplo01@10.240.2.14 - PMP RDP SESSION – Mozilla Firefox

When this call is executed we receive again a Status 200 return.

2023-03-20 10_56_09-admpqr_rplo01@10.240.2.14 - PMP RDP SESSION – Mozilla Firefox

When both logical ports are disconnected we can proceed and delete the vCenter Distributed Port Group by deleting the corresponding NSX Segment.

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *