Couple of months back, I wrote an article on “How did I get started with pyVmomi on ubuntu distro?”, which was very well received. Recently I got several requests from readers on how to set pyVmomi on Windows platform and I thought to write this tutorial, which will take you through steps required to set pyVmomi on my Windows 10.
Step 1: Install latest python for windows.
Latest 3.x python version available is 3.6.5 on python official portal . Download the python installer as pointed out in below screenshot.
I see that python is installed as expected at directory i.e. C:\Users\shitolev\AppData\Local\Programs\Python\Python36, which is default directory. I also checked python version using “python -V” command and I see correct python version is installed.
Step 2: Install pyvmomi and pyvim python modules
As I already discussed in my pyVmomi on ubuntu article, we need “pip” to install these python modules. Note that “pip” itself gets installed as part of python installation. Let us go ahead for “pyvmomi” and pyvim” modules installation by running this command
“python.exe -m pip install pyvmomi pyvim” . You can run this command from any directory of your choice.
you can see that latest “pyvmomi” i.e. the one supports vSphere 6.7 and “pyvim” python modules got installed successfully. I also see that these modules are installed at python directory i.e. C:\Users\shitolev\AppData\Local\Programs\Python\Python36\Lib\site-packages
Now that we are done with setting up pyVmomi on Windows, its time to run a vSphere API sample to confirm everything is working fine.
Step 3: Running vSphere API sample.
For the sake of simplicity I chose the same sample I used in my ubuntu article
# VMware vSphere Python SDK, pyvmomi
# Simple script to get vCenter server product details
from pyVim.connect import SmartConnect
s=ssl.SSLContext(ssl.PROTOCOL_SSLv23) # For VC 6.5/6.0 s=ssl.SSLContext(ssl.PROTOCOL_TLSv1)
si= SmartConnect(host="10.192.1.2", user="Administrator@vsphere.local", pwd="VMware#123", sslContext=s)
print ("Product Name:",aboutInfo.fullName)
print("Product Unique Id:",aboutInfo.instanceUuid)
print("Product Base OS:",aboutInfo.osType)
Output shows that this small pyvmomi script got executed on vSphere 6.7 successfully. How cool is that?
Note: I would like you to take a look at line #7, where I had to use “ssl.PROTOCOL_SSLv23” protocol for VC 6.7 connection. For VC 6.0 and 6.5, I used “ssl.PROTOCOL_TLSv1”.
1. Please take a look at tutorial on how to get hold of vSphere objects and play around. Take a look at some cool samples on VC HA
4. Getting started with vCenter server REST APIs using python
Vikas Shitole is a Staff engineer 2 at VMware India R&D. He currently focusses on vCenter server in general, vSphere with Tanzu, VCF and partly VMware cloud. He is passionate about VMware customers & automation around VMware technologies. He has been a vExpert since last 9 years (2014-22) in row for his significant community contributions around VMware. He is also part of BU driven vExpert sub-programs i.e. vExpert App modernization, vExpert VMware Cloud on AWS & vExpert PRO as well. He is author of 2 VMware flings & holds multiple technology certifications. He has been speaker at International conferences such as VMworld Europe, VMworld USA & was designated VMworld 2018 blogger as well.
In addition, he is passionate cricketer, bicycle rider & aspiring Ironman 70.3. He also enjoys learning about fitness & nutrition.