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
1 2 3 |
# CONTENT-TYPE: application/xml # METHOD: GET # API CALL: https://NSX-MGR-IP/api/2.0/vdn/controller/ |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
<?xml version="1.0" encoding="utf-8"?> <controllers> <controller> <objectTypeName>Controller</objectTypeName> <revision>0</revision> <name>nsx-ctlr01</name> <clientHandle></clientHandle> <isUniversal>false</isUniversal> <universalRevision>0</universalRevision> <id>controller-1</id> <ipAddress>192.168.109.250</ipAddress> <status>RUNNING</status> <upgradeStatus>NOT_STARTED</upgradeStatus> <version>6.3.7073587</version> <upgradeAvailable>true</upgradeAvailable> <virtualMachineInfo> <objectId>vm-48</objectId> <objectTypeName>VirtualMachine</objectTypeName> <vsmUuid>42007DBE-3706-0598-4AEE-CCD932F94B3A</vsmUuid> <nodeId>1b060741-08e6-42a1-9dee-b39ea845337d</nodeId> <revision>15</revision> <type> <typeName>VirtualMachine</typeName> </type> <name> NSX_Controller_78bdb508-aaea-41e3-aed9-1b10e296b323</name> <scope> <id>domain-c7</id> <objectTypeName>ClusterComputeResource</objectTypeName> <name>Compute Cluster-Site-A</name> </scope> <clientHandle></clientHandle> <extendedAttributes /> <isUniversal>false</isUniversal> <universalRevision>0</universalRevision> </virtualMachineInfo> <hostInfo> <objectId>host-15</objectId> <objectTypeName>HostSystem</objectTypeName> <vsmUuid>42007DBE-3706-0598-4AEE-CCD932F94B3A</vsmUuid> <nodeId>1b060741-08e6-42a1-9dee-b39ea845337d</nodeId> <revision>61</revision> <type> <typeName>HostSystem</typeName> </type> <name>esxi-01a.corp.local</name> <scope> <id>domain-c7</id> <objectTypeName>ClusterComputeResource</objectTypeName> <name>Compute Cluster-Site-A</name> </scope> <clientHandle></clientHandle> <extendedAttributes /> <isUniversal>false</isUniversal> <universalRevision>0</universalRevision> </hostInfo> <resourcePoolInfo> <objectId>resgroup-8</objectId> <objectTypeName>ResourcePool</objectTypeName> <vsmUuid>42007DBE-3706-0598-4AEE-CCD932F94B3A</vsmUuid> <nodeId>1b060741-08e6-42a1-9dee-b39ea845337d</nodeId> <revision>33</revision> <type> <typeName>ResourcePool</typeName> </type> <name>Resources</name> <scope> <id>domain-c7</id> <objectTypeName>ClusterComputeResource</objectTypeName> <name>Compute Cluster-Site-A</name> </scope> <clientHandle></clientHandle> <extendedAttributes /> <isUniversal>false</isUniversal> <universalRevision>0</universalRevision> </resourcePoolInfo> <clusterInfo> <objectId>domain-c7</objectId> <objectTypeName>ClusterComputeResource</objectTypeName> <vsmUuid>42007DBE-3706-0598-4AEE-CCD932F94B3A</vsmUuid> <nodeId>1b060741-08e6-42a1-9dee-b39ea845337d</nodeId> <revision>37</revision> <type> <typeName>ClusterComputeResource</typeName> </type> <name>Compute Cluster-Site-A</name> <scope> <id>datacenter-2</id> <objectTypeName>Datacenter</objectTypeName> <name>Prod-DC01</name> </scope> <clientHandle></clientHandle> <extendedAttributes /> <isUniversal>false</isUniversal> <universalRevision>0</universalRevision> </clusterInfo> <managedBy>42007DBE-3706-0598-4AEE-CCD932F94B3A</managedBy> <isDiskReadOnly>false</isDiskReadOnly> <datastoreInfo> <objectId>datastore-41</objectId> <objectTypeName>Datastore</objectTypeName> <vsmUuid>42007DBE-3706-0598-4AEE-CCD932F94B3A</vsmUuid> <nodeId>1b060741-08e6-42a1-9dee-b39ea845337d</nodeId> <revision>1</revision> <type> <typeName>Datastore</typeName> </type> <name>iSCSI-3</name> <clientHandle></clientHandle> <extendedAttributes /> <isUniversal>false</isUniversal> <universalRevision>0</universalRevision> </datastoreInfo> <controllerClusterStatus /> <diskLatencyAlertDetected>FALSE</diskLatencyAlertDetected> <vmStatus>POWERED_ON</vmStatus> </controller> </controllers> |
Note: You can grep for keyword <id> in above example to limit the output of API call
Step-2: Delete NSX Controller
1 2 3 4 5 6 7 8 |
# Delete NSX Controller # CONTENT-TYPE: application/xml # METHOD: DELETE # API CALL: https://NSX-MGR-IP/api/2.0/vdn/controller/controller-xxx?forceRemoval=True #EXAMPLE RESPONSE 200: OK |
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