PyNSXv-Powerful tool for NSX Automation

Like last post of NSX series, this post is also focused on exploring a new tool which helps automatic NSX stuffs in your infrastructure. I first came across this tool when I was watching a VMworld 2016 Session titled NET7514 – PowerNSX and PyNSXv, but never got chance to play around this tool.

Now since I am exploring NSX automation these days, I decided to deploy the tool, in lab and use it. 

This post will be focused on just installation/configuration part and some examples on how to use this tool.

So what is PyNSXv?

PyNSXv is a high python based library that exposes ready to use work-flows and a CLI tool that can be used to control and automate NSXv in your infrastructure. 

It an opensource tool and is not supported by VMware and before using this in production, it is recommended to test it thoroughly in lab deployments. 

Currently PyNSXv functionality covers the following key areas:

  • Logical Switching
  • Logical Routing
  • NSX Edge Gateway
  • NSX Edge Load Balancer

PyNSXv can be used in two different ways, as a library by importing the files in the /library sub-directory into your code, or as a CLI tool by executing pynsxvon the command line after installation. To install PyNSXv you can use PIP on your system.

You should have some basic knowledge of Python and Powershell (and of-course of NSX) to begin with this tool. Below diagram just shows a very high level architectural view of this tool.

PyNSXv can be downloaded from VMware’s GitHub directory. Instructions for installation are available on PyNSXv Wiki page. Lets the fun begin.

Installing PyNSXv on Windows

Step 1: Install python v2.7 on your windows box. Python v2.7 can be downloaded from Here. Attention: Do Not install python v 3.X 

Step 2: Add python installation folder in the Windows path (So that PyNSXv can be run from any folder).

To do so navigate to Control Panel > System and Security > System > Advance System Settings > Advanced > Environment Variables.

Under System Variables edit PATH variable and add python installationscript folder path (typically it is C:Python27Scripts)

Step 3: Install PynSXv

Run command : pip install pysxv

Step 4: After you installed PyNSXv, the first thing you have to do is to create your a ini file that contains the host names and credentials of your vCenter and NSX Manager. Save this file in location : C:Python27Libsite-packagespynsxv

Typically nsx.ini file looks like below:

After placing the nsx.ini file in you path, you can run pynsxv from your shell or cmd prompt.

Now you can use pynsx,exe command to play around with various options. One example is shown below

To see list of all available options that can be used with pynsxv command, please read this document.

Alternatively PyNSXv can be installed on windows using git command as well. Make sure git is installed on your windows machine.

You can clone the PyNSXv repository by using command: git clone https://github.com/vmware/pynsxv.git

This will typically place the installation file under C:UsersUsernameDocumentsGitHub. From there navigate to pynsxv directory and run setup.py command. It will configure the necessary modules/library.

The nsx.ini file is placed in directory C:UsersUsernameDocumentsGitHubpynsxvpynsxv. Modify this file as per example shown earlier.

Linux Installation

Step 1: If you are using Centos/Redhat 6 then default python version that is shipped with the v6 distribution is 2.6. We have to install python 2.7 on CentOS/Redhat. Instructions for doing so are explained here.

This post also demonstrates how to install pip. Once Python2.7 and Pip2.7 is installed, PyNSXv can be installed using command: pip2.7 install pynsxv

This command places the modules/library files under directory /usr/local/lib/python2.7/site-packages/pynsxv. In the same directory you will find the nsx.ini file.

Alternatively on linux boxes PyNSXv can be installed via git using command git clone https://github.com/vmware/pynsxv.git.

This will create a directory pynsx in your present working directory. Again you can find nsx.ini file here and modify it as per your environment details.

Now its time to play around various options available. 

I hope you enjoyed reading this post. Feel free to share this on social media if it is worth sharing. Be sociable :)

Leave a Reply