Deleting NSX Controller Using API

Today while cleaning up my lab, I came across situation where I needed to delete one of the deployed controllers. Although this task is fairly simple from vCenter UI, but recently I came across a situation (in VMware HOL) where I was unable to delete a controller via UI.

As an alternative, I came across set of API calls which did the job for me. In this post I will demonstrate how to use API calls to delete stuck/bad NSX controllers.

Step 1: Fetch controller details

Example: curl -sik -u “vcadmin@corp.local” -H ‘Content-Type: application/xml’ -X GET https://nsxmgr-01a.corp.local/api/2.0/vdn/controller | tidy -xml -indent -quiet

Output

Note: You can grep for keyword <id> in above example to limit the output of API call

Step-2: Delete NSX Controller

Example: curl -sik -u “vcadmin@corp.local” -H ‘Content-Type: application/xml’ -X DELETE https://nsxmgr-01a.corp.local/api/2.0/vdn/controller/controller-1?forceRemoval=True

In vCenter server you will see a power off and delete task kicked for NSX controller VM. This task is kicked by the service account via which NSX is registered to vCenter server.

I hope you enjoyed reading this post. Feel free to share this on social media if it is worth sharing. Be sociable :)

Leave a Reply