In this post I will be demonstrating how to enable and disable high availability on NSX edge gateway using Rest API.
If you are new to NSX and do not know what edge gateway high availability means then I would recommend to read this Blog by Gabe Rosas.
We can enable disable high availability on edge gateway from vSphere Web Client by navigating to Home > Networking & Security > NSX Edges > Selecting Edge > Manage > HA Configuration
Enabling HA on edge gateway will create a new vse vm in vCenter and both VM start exchanging heartbeat and exchanging other configuration etc.
Now we will see how to achieve this via NSX Rest API.
Step 1: Query HA Status
# curl -k -u “admin:passwd” -X GET https://nsxmgr.alex.local/api/4.0/edges/edge-2/highavailability/config | xmllint –format –
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="UTF-8"?> <highAvailability> <version>3</version> <enabled>false</enabled> <declareDeadTime>15</declareDeadTime> <logging> <enable>false</enable> <logLevel>info</logLevel> </logging> <security> <enabled>false</enabled> </security> </highAvailability> |
From the above output we can see HA ha snot been enabled on edge gateway yet.
Step 2: Enable HA
To enable HA on edge gateway, we need to supply few parameter in the request body of the API call. If you are using curl you can create an xml file as shown below and can supply it with API query with -d option.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="UTF-8"?> <highAvailability> <version>4</version> <enabled>True</enabled> <declareDeadTime>15</declareDeadTime> <logging> <enable>false</enable> <logLevel>info</logLevel> </logging> <security> <enabled>false</enabled> </security> </highAvailability> |
Firing below API call will enable HA the edge gateway.
# curl -k -u “admin:passwd” -H “Content-Type:application/xml” -X PUT https://nsxmgr.alex.local/api/4.0/edges/edge-2/highavailability/config -d @enable-ha.xml
You can watch the progress in vCenter.
You will see a couple of edge backing vm’s in vCenter post enabling HA
Step 3: Verify HA has been enabled
# curl -k -u “admin:passwd” -X GET https://nsxmgr.alex.local/api/4.0/edges/edge-2/highavailability/config | xmllint –format –
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="UTF-8"?> <highAvailability> <version>5</version> <enabled>true</enabled> <declareDeadTime>15</declareDeadTime> <logging> <enable>false</enable> <logLevel>info</logLevel> </logging> <security> <enabled>false</enabled> </security> </highAvailability> |
Step 4: Query Edge Appliance
# curl -k -u “admin:passwd” -X GET https://nsxmgr.alex.local/api/4.0/edges/edge-2/appliances
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 |
<?xml version="1.0" encoding="UTF-8"?> <appliances> <applianceSize>compact</applianceSize> <appliance> <highAvailabilityIndex>0</highAvailabilityIndex> <vcUuid>5010d31c-bd18-ebaa-f639-23052acede04</vcUuid> <vmId>vm-124</vmId> <haAdminState>up</haAdminState> <resourcePoolId>resgroup-72</resourcePoolId> <resourcePoolName>System vDC (4b5dcf7c-f2f1-4cf3-ade1-3fcc52f3312e)</resourcePoolName> <datastoreId>datastore-62</datastoreId> <datastoreName>iSCSI-2</datastoreName> <hostId>host-32</hostId> <hostName>esxi02.alex.local</hostName> <vmFolderId>group-v81</vmFolderId> <vmFolderName>Service VMs</vmFolderName> <vmHostname>vse-0b582f55-6bb3-487c-947d-580778fd0092-0</vmHostname> <vmName>vse-Prod-GW (0b582f55-6bb3-487c-947d-580778fd0092)-0</vmName> <deployed>true</deployed> <cpuReservation> <limit>-1</limit> <reservation>64</reservation> </cpuReservation> <memoryReservation> <limit>512</limit> <reservation>256</reservation> </memoryReservation> <edgeId>edge-2</edgeId> <configuredResourcePool> <id>resgroup-72</id> <name>System vDC (4b5dcf7c-f2f1-4cf3-ade1-3fcc52f3312e)</name> <isValid>true</isValid> </configuredResourcePool> <configuredDataStore> <id>datastore-62</id> <name>iSCSI-2</name> <isValid>true</isValid> </configuredDataStore> <configuredVmFolder> <id>group-v81</id> <name>Service VMs</name> <isValid>true</isValid> </configuredVmFolder> </appliance> <appliance> <highAvailabilityIndex>1</highAvailabilityIndex> <vcUuid>5010a7c1-daa2-56b1-adc3-4d2100f59e7e</vcUuid> <vmId>vm-125</vmId> <haAdminState>up</haAdminState> <resourcePoolId>resgroup-72</resourcePoolId> <resourcePoolName>System vDC (4b5dcf7c-f2f1-4cf3-ade1-3fcc52f3312e)</resourcePoolName> <datastoreId>datastore-62</datastoreId> <datastoreName>iSCSI-2</datastoreName> <hostId>host-29</hostId> <hostName>esxi01.alex.local</hostName> <vmFolderId>group-v81</vmFolderId> <vmFolderName>Service VMs</vmFolderName> <vmHostname>vse-0b582f55-6bb3-487c-947d-580778fd0092-1</vmHostname> <vmName>vse-Prod-GW (0b582f55-6bb3-487c-947d-580778fd0092)-1</vmName> <deployed>true</deployed> <cpuReservation> <limit>-1</limit> <reservation>64</reservation> </cpuReservation> <memoryReservation> <limit>512</limit> <reservation>256</reservation> </memoryReservation> <edgeId>edge-2</edgeId> <configuredResourcePool> <id>resgroup-72</id> <name>System vDC (4b5dcf7c-f2f1-4cf3-ade1-3fcc52f3312e)</name> <isValid>true</isValid> </configuredResourcePool> <configuredDataStore> <id>datastore-62</id> <name>iSCSI-2</name> <isValid>true</isValid> </configuredDataStore> <configuredVmFolder> <id>group-v81</id> <name>Service VMs</name> <isValid>true</isValid> </configuredVmFolder> </appliance> <deployAppliances>true</deployAppliances> </appliances> |
Step 5:Disable HA
To disable HA on edge gateway, again we need to supply an xml file with the API call. We just need to flag enabled=false in the xml file as shown below.
1 2 3 4 |
<?xml version="1.0" encoding="UTF-8"?> <highAvailability> <enabled>false</enabled> </highAvailability> |
# curl -k -u “admin:AdminPWD” -H “Content-Type:application/xml” -d @disable-ha.xml -X PUT https://nsxmgr.alex.local/api/4.0/edges/edge-2/highavailability/config
This will delete the extra edge VM that was deployed in step 2
And that’s it, we have now successfully enabled/disabled high availability on edge gateway.
Sources and Additional Reading
I hope you enjoyed reading this post. Feel free to share this on social media if it is worth sharing. Be sociable