Interact with VMware NSX using manual and programmatic methods

In this post we will explore different methods to login to VMware NSX Manager. If you are reading this you are probably new to NSX. There are two flavors of NSX – NSX-V or NSX for vSphere, and NSX-T or NSX Transformer with NSX-T being the new version. This post does not cover NSX-V. NSX-V is deprecated now and starting version 4.0 NSX-T is now simply called NSX.

Image courtesy VMware NSX Documentation

1. From vSphere using console

NSX manager is installed as a virtual machine and like any other VM you can access console of NSX manager node directly from vCenter. This method is only required when we do not have management connectivity to NSX manager node.

Locate the VM under hosts in vCenter and click on Launch Web Console or Launch Remote Console depending upon how you want to access it. Launch remote console requires VMware Remote console tool. It will open CLI of manager node.

2. Using manager UI

Using NSX manager UI is the most popular way to access NSX manager node. You can login to NSX manager from your web browser using HTTPS.

NSX-T manager Login page

After entering username and password it presents with a default dashboard view.

NSX-T manager UI default interactive dashboard view

3. SSH to manager node

You can also SSH directly to NSX-T manager node. You can use either your administrator account or root account. Root login is not allowed in UI.

If you login using administrator account it presents nsxcli. Commands to view system will generally begin with get, you can use ? for options available for any command.

Root account gives you access to linux shell and must be use cautiously.

To switch from administrator account to root account you can use the following command ‘st en’ in administrator mode. Password here will be you administrator account password.

4. Using REST API

We can use REST api to access NSX-T manager node. You can either use a REST api client like Postman or cURL.

The NSX Manager provides two APIs: Policy and Manager.
Policy API URIs begin with /policy/api. Manager API URIs begin with /api.

Here is an example from Postman. In this example we are getting all transport-zones configured. Note Authorization type is Basic Auth. Successful call with show HTTP status code 200 and result will be in Body tab.

We can do the same from CLI using cURL method. You can use various parameters with cURL depending upon requirement.

curl -v -k GET “https://sa-nsxmgr-01.vclass.local/api/v1/transport-zones” -u admin -H ‘content-type: application/xml’

In the example above password is not passed in the command for security reasons but you can also pass it directly in command.

curl -v -k -X POST “https://https://sa-nsxmgr-01.vclass.local/api/v1/api/v1/transport-zones” -u ‘USERNAME:PASSWORD’ -H ‘content-type: application/xml’

5. Using Python

Here is a basic example to get list of transport zones. I have used requests library to to GET response from NSX manager. Username and password should be entered using Base64 encoding in the following format ‘Username:Password’.

import requests
url = "https://sa-nsxmgr-01.vclass.local/api/v1/transport-zones"

headers = {
    'Authorization': "Basic VVNFUjpQQVNTV09SRA==",
    }
response = requests.request("GET", url, headers=headers, verify=False)
print(response.text)

You can use Python SDK to automate configuration.

6. Using PowerCLI

You can also use PowerCLI to interact with NSX manager.

Authenticate to NSX manager using ‘Connect-NsxtServer’ cmdlet.

Here is an example to get transport zones using PowerCLI.

These are the methods you can use to interact with NSX manager nodes. You can also use automation tools like Ansible. I will cover automation tools in future posts. I hope you found this blog post useful.