Getting started with pyvmomi on RHEL 6

By | August 2, 2017

I had a need to use the API for Storage Profile Based Management (SPBM) and I recalled a blog by William Lam regarding pyvmomi support SPBM now.

He had a few example scripts but he doesn’t really go over how to get going. There were a lot of steps to get this right, so instead of my usual “here’s what I did wrong, then here’s what I did right”, I’m going to cut to the good stuff. I am assuming a RHEL 6 box, RHEL 7 will work (or the CentOS equivalents) should be similar.

First-off, you will need either Python 2.7.9 or Python 3.3. The RHEL 6 I had came with 2.6.5 which had issues because of a lack of a ssl flag to ignore self-signed certs. I went with Python 3.3.3

Download the above file to your server

In whatever directory the file is at, run the following:

This should install python3.3 and put it in your PATH so that you can run python3.3 from anywhere

Next step is to install pip3 (specific for python 3.x)

Save this file to your machine:

If you are behind a proxy, you may need to export your http_proxy and/or https_proxy settings

Then run using the pything you installed

Now install pyvmomi using pip3

Now you can run a sample script, like William’s script, but it needs to be updated for 3.3. You can get my version here

For any script you right, you will need to pass some sort of sslcontext to the connection function.
In 2.7, you will see sslcontext=ssl._create_unverified_context()

In 3.3, you should do this:

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
context.verify_mode = ssl.CERT_NONE


Also note that in 3.3, Cookie is replaced by http.cookies (just do a find/replace)


Leave a Reply

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