Exploring VMware VCenter REST API using python – part I

By | 8th August 2017

With the release of 6.5, there is an improved focus on using vcenter REST API’s
In this example, I am trying to explore the vcenter 6.5 api specifically vcenter 6.5 VCSA using python.

Make sure you install the required packages so that it will work like request,urlopen etc.                           pip can be used to install the same, there might be more packages depending on your setup.

#sudo pip install requests
#sudo pip install urlopen

How to get the details of the API?
Connect to the VCenter using the browser.

Click on the Right-hand corner “Browse vSphere REST APIs”

VCENTER_BROWSE_API

 

How to Explore the vcenter API’s?

Once you click on browse select API for which you would like to have more details.

VCENTER EXPLORE

How to access the API?
Using GET/PUT method to access the details.

Example:
Attached is an example to query the health status of the VCSA appliance.
It will print the messages based on the health status

https://github.com/rajeevrn/myscripts/blob/master/vmware/vcenterapi.py

Output:

$ python vcenterapi.py
The Health status of the appliance is: GREEN
VCSA health status is fine

Leave a Reply

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