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
https://www.python.org/ftp/python/3.3.3/Python-3.3.3.tgz
Download the above file to your server
In whatever directory the file is at, run the following:
1 2 3 |
sudo ./configure sudo make sudo make altinstall |
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: https://bootstrap.pypa.io/get-pip.py
If you are behind a proxy, you may need to export your http_proxy and/or https_proxy settings
1 2 |
export http_proxy=http://server.something:8080 export https_proxy=https://server.something:8080 |
Then run get-pip.py using the pything you installed
1 |
python3.3 get-pip.py |
Now install pyvmomi using pip3
1 |
pip3 install --upgrade pyvmomi |
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
sslContext=context
Also note that in 3.3, Cookie is replaced by http.cookies (just do a find/replace)