Change NSX passwords with the API

image

Today I received a message from a customer that he wanted to change his NSX passwords to more complex passwords for the various account within his NSX environment.

NSX allows you to change the passwords by using API calls. API are a common way of managing your NSX environment. I think changing the NSX accounts passwords is a good way for getting yourself familiar with using API for managing NSX. it is quite a simple task, and this is a good way to practice using a API and Postman. Let me talk you through how to accomplish this task.

First you need Postman. You can download and install it locally, you can find it at https://www.getpostman.com/.
The next step is to connect to NSX. After you have installed Postman, you should create a Postman environment for our NSX environment.  An environment in Postman is a place where you create and store variables with their values. These can then be used within API requests. Using environment variables is a real time saver. To create an environment in Postman choose File > New and select Environment.

Give the environment a name and add the following variables:

Variable

Value

baseUrl

NSX-Manager-FQDN

NSX-Manager-User

Admin

NSX-Manager-Password

password

image

In the headers tab you need to specify the Content-Type we are going to use. For NSX this is going to be application/json.

image

Now that you have fixed these preperations you can start with the task at hand. First you need to create a list of the present user accounts so that you can pick the correct userid for the actual password change. We create this list by issuing a GET command towards: https://baseUrl/api/v1/node/users

image

The above screen shot shows the output from the get request. You can see that the json output shows a block of data per user account. For the task of changing the password we need the userid from the user that we want to perform the password change for.

image

Let’s start by changing the password for the audit account. From the output of the previous command you learn that the userid for the audit account is 10002.

To change password for the audit account you first need to change the action from GET to PUT, change the URL to https://baseUrl/api/v1/node/users/10002
You need to clear the body tab and enter the following json code:

{
     “password”: N3wP@ssw0rd,
     “old_password”: 0ldP@ssw0rd
}

image

The above image shows the output form executing the above mentioned code. You should also receive a Status 200 OK message. This message indicates that the issued command was executed successful. You can now change the password for the other NSX accounts.

 


Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *