Recently I have been engaged in a NSX-v PSO engagement where we need to make sure all the best practices are applied to the environment. Trust me, with every engagement, you learn something new as it is always the business requirements that drive technical solutions.
As the customer have iBGP routing configured between DLR and NSX edges, and eBGP between NSX edges and the L3 leaf switches, we need to ensure that all ECMP-enabled edges can reach the logical switches via DLR in case DLR-Edges BGP neighborship is down (if DLR control VM is down). So, one of the changes that were needed to be done was to make sure floating static routes are added to the NSX edges as backup routes.
Having about 160 discontiguous subnets attached to the UDLR and 4 edges in each datacenter in an active/standby multi-site deployment, makes it a nightmare to add all these subnets individually to each NSX edge through the GUI. REST API comes into rescue in such case.
This approach makes it feasible to add all 160 routes to each NSX edge in one REST API call.
In this post, we gonna see how we can add a floating static route to an NSX edge via REST API.
Download and install a REST client such as postman.
Configure basic authentication with your NSX manager and supply admin credentials. Make sure you are able to connect to your NSX manager as we need to get the NSX edge ID to make our changes.
To get the ID of your corresponding edge, you can use the below API call: GET https://<NSX-Mgr Name>/api/4.0/edges/
First let’s get the static routes currently configured on your NSX edge (if any) using the below API call: Get https://<NSX-Mgr Name>/api/4.0/edges/<edge-ID>/routing/config/static
From the above screenshot, you can notice that there are no static routes configured on edge-1.
As we are going to use NSX-v 6.x API PUT methods to inject the static routes, we need to make sure that encoding specified in the headers is configured with application/xml. Key: Content-Type, Value: application/xml
We will add the below 2 static routes as an example. The same logic can be followed to add N static routes.
Route1: Exit interface=vNIC 1, Logical Subnet=10.14.101.0/24, Next Hop=192.168.5.2, AD=240
Route2: Exit interface=vNIC 1, Logical Subnet=192.168.10.0/24, Next Hop=192.168.5.2, AD=240
Static Route AD 240 > iBGP AD 200 is used to make sure the static route acts as backup route only if BGP is down.
To do so, the below API request and body will be used.
PUT https://<NSX-Mgr Name>/api/4.0/edges/<edge-ID>/routing/config/static
After you execute the above API call, you should get a “204 No Content” response if all went OK.
Now, let’s verify our work and check if our static routes have been added to the NSX edge.
Hope this post is informative,
Thanks for reading,
3316total visits,11visits today