0

Practical NSX: Restful API

REST API allows us to programmatically control NSX, using REST API requests we can install, configure, monitor, and maintain NSX. The API calls typically use HTTP or HTTPS as the communication protocol, the payload itself is in JSON or XML format. VMware provides a beefy document that goes through all the various API calls and functionality available. If you are using NSX 6.3 like me, the guide can be found here.

There are various Rest API clients out there, in this blog post you will be using Postman which can be downloaded from here.

Once you have launched Postman, we will need to make a couple of configuration changes. Namely the Authorization type and adding a custom header which is needed for POST calls.

Configuring Postman

Launch Postman, click on Authorization, change the type to Basic, then enter your NSX Manager credentials.

Navigate to the headers menu

Add Content-Type as key and Application/xml as value

One last thing to mention here is that we will be using the https protocol to interact with the NSX manager. In my case I will be using https://192.168.0.44 to interact with my NSX Manager.

We are now ready to use Postman.

API Requests

Below is a list of the requests that are possible to use, however in my experience, you will find yourself using GET, POST, PUT, DELETE more frequently than the others.

GET: To read information

PUT: To update configuration.

POST: To change configuration

DELETE: To delete

Examples

Query my NSX controllers: https://192.168.0.44/api/2.0/vdn/controller

Query my SSO configuration: https://192.168.0.44/api/2.0/services/ssconfig

Query my logical switches: https://192.168.0.44/api/2.0/vdn/virtualwires

Create a logical switch:

As we all know, a logical switch needs to belong to a transport zone, I will therefore need to find it’s scope id as it’s part of the logical switch creation call.

Query my transport zones : https://192.168.0.44/api/2.0/vdn/scopes

Now that we have our transport zone scope id vdnscope-1, let’s create our logical switch.

https://192.168.0.44/api/2.0/vdn/scopes/vdnscope-1/virtualwires

Body of our call

<virtualWireCreateSpec>
<name>LS_API</name>
<description>REST API LS</description>
<tenantId></tenantId>
<controlPlaneMode>UNICAST_MODE</controlPlaneMode>
</virtualWireCreateSpec>

Checking in our NSX environment we can see that the logical has indeed been created.

Delete a logical switch

Let’s first find it’s object id: https://192.168.0.44/api/vdn/virtualwires <virtualWire>

<objectId>virtualwire-59</objectId>
<objectTypeName>VirtualWire</objectTypeName>
<vsmUuid>422A55B6-E2C7-A8A0-3E16-1D83B9C55220</vsmUuid>
<nodeId>d17fc929-b712-4b69-b597-7f7fa4861dc8</nodeId>
<revision>2</revision>
<type>
<typeName>VirtualWire</typeName>
</type>
<name>LS_API</name>

Now we can delete the logical switch: https://192.68.0.44/api/2.0/vdn/virtualwires/virtualwire-59

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

Sharing is caring!

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *