Getting started with vSphere and python scripting (pyVmomi)

From Iwan
Jump to: navigation, search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

During one of my engagements as a Professional Services Consultant I needed to upgrade a vSphere 5.1 environment to vSphere 6.

Not really exciting when you have enough hosts available to play with. But one of the things that I stumbled into is that I wanted to have a list of all the VM's that are hosted within the vSphere environment.

One of the ways to do this is to browse trough the web-client and select the Data Center (or vCenter Server) object and look / export / copy-paste the VM's from the related objects VM tab.

As being a CLI guy for a few years I expected that the vCenter Server or the ESX hosts had this functionality build in... well I was wrong. So after using Google over and over again I discovered that I needed to do this either trough Python or trough Power-shell.

In this post I am going to explain you the Python way. This is really going to a "beginners" guide as I needed to start from the beginning as well.

Below you will find the steps that I had to take (as an absolute vSphere + python beginner) to gather a list of VM's with python.

  1. Install OSX on a separate VM (using Fusion)
  2. Verify the default python version that came with Yosemite
  3. Install pip
  4. Use pip to install pyvmomi
  5. Verify version pyvmomi
  6. Create a new user in vCenter to make python calls to vCenter Server
  7. Execute one of the sample Python scripts in the sample directory (getallvms.py)
  8. Alter the getallvms.py script to only show virtual machine names
  9. Execute getallvms.py again
  10. Try another script that provides information about VM's

Install OSX on a separate VM 〈using Fusion〉

When you are playing around with scripts it is better to not do this form your "production" environment but form a "development" environment because you can break things or ending up installing unnecessary add-ons.

As I am using a Mac I decided to install a new copy of OS X trough VMware Fusion. The procedure for this can he found here. I installed Yosemite.

Note

To "fence" your environment it is also possible to use "virtualenvs" in python in stead of installing a whole new VM .

Verify the default python version that came with Yosemite

The OS X installation came with a pre-installed version of Python. To verify this version we need to issue the following command:

Iwans-Mac:~ iwanhoogendoorn$ python --version 
Python 2.7.10

In my case version 2.7.10 was pre-installed.

Install pip

Now we need to install pip. Pip is a package management system used to install and manage software packages written in Python. We need this to install pyvmomi.

Iwans-Mac:~ iwanhoogendoorn$ sudo easy_install pip

Use pip to install pyvmomi

We are using pip to install pyvmomi.

Iwans-Mac:~ iwanhoogendoorn$ sudo pip install pyvmomi

Verify version pyvmomi

Because its pyvmomi and Python are very picky with version compatibility it is good to know what version pyvmomi was installed.

Iwans-Mac:~ iwanhoogendoorn$ /usr/local/bin/pip show pyvmomi
---
Metadata-Version: 1.1
Name: pyvmomi
root ##b##Version: 6.0.0.2016.4##!b##
Summary: VMware vSphere Python SDK
Home-page: https://github.com/vmware/pyvmomi
Author: VMware, Inc.
Author-email: jhu@vmware.com
License: License :: OSI Approved :: Apache Software License
Location: /Library/Python/2.7/site-packages
Requires: requests, six
Classifiers:
  Development Status :: 5 - Production/Stable
  License :: OSI Approved :: Apache Software License
  Intended Audience :: Information Technology
  Intended Audience :: System Administrators
  Intended Audience :: Developers
  Environment :: No Input/Output (Daemon)
  Programming Language :: Python :: 2
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3
  Programming Language :: Python :: 3.2
  Programming Language :: Python :: 3.3
  Programming Language :: Python :: 3.4
  Topic :: Software Development :: Libraries :: Python Modules
  Topic :: System :: Distributed Computing
  Operating System :: Microsoft :: Windows
  Operating System :: POSIX
  Operating System :: Unix
  Operating System :: MacOS

Get pyvmomi repo from github

The pyvmomi repo consists of sample scripts that can be used to test out stuff. We need to download / clone this repo to our own computer.

Iwans-Mac:~ iwanhoogendoorn$ git clone https://github.com/vmware/pyvmomi.git

Iwans-Mac:Downloads iwanhoogendoorn$ ls
root ##b##pyvmomi##!b##

Iwans-Mac:Downloads iwanhoogendoorn$ cd pyvmomi

Iwans-Mac:pyvmomi iwanhoogendoorn$ ls -l
total 96
-rw-r--r--   1 iwanhoogendoorn  staff  11510 Jun  8 23:51 LICENSE.txt
-rw-r--r--   1 iwanhoogendoorn  staff    117 Jun  8 23:51 MANIFEST.in
-rw-r--r--   1 iwanhoogendoorn  staff    238 Jun  8 23:51 NOTICE.txt
-rw-r--r--   1 iwanhoogendoorn  staff   4513 Jun  8 23:51 README.rst
drwxr-xr-x   5 iwanhoogendoorn  staff    170 Jun  8 23:51 docs
drwxr-xr-x   5 iwanhoogendoorn  staff    170 Jun  8 23:51 pyVim
drwxr-xr-x  18 iwanhoogendoorn  staff    612 Jun  8 23:51 pyVmomi
-rw-r--r--   1 iwanhoogendoorn  staff     27 Jun  8 23:51 requirements.txt
drwxr-xr-x   4 iwanhoogendoorn  staff    136 Jun  8 23:51 sample
-rw-r--r--   1 iwanhoogendoorn  staff     75 Jun  8 23:51 setup.cfg
-rw-r--r--   1 iwanhoogendoorn  staff   2451 Jun  8 23:51 setup.py
-rw-r--r--   1 iwanhoogendoorn  staff     24 Jun  8 23:51 test-requirements.txt
drwxr-xr-x  11 iwanhoogendoorn  staff    374 Jun  8 23:51 tests
-rw-r--r--   1 iwanhoogendoorn  staff    108 Jun  8 23:51 tox.ini

Create a new user in vCenter to make python calls to vCenter Server

When we are executing scripts agains vCenter Server it is the best practice to have a special account for this purpose. Therefore we need to create a new account in vCenter and assign this account to the correct role (preferably Administrators). I have use the following:

UN = pyvmomi-user
PW = VMware 1!

Execute one of the sample Python scripts in the sample directory 〈getallvms py〉

Our first script that we are testing our is the getallvms.py script that is located in the sample folder.

Iwans-Mac:pyvmomi iwanhoogendoorn$ cd sample

Iwans-Mac:sample iwanhoogendoorn$ ls -l
total 24
-rwxr-xr-x  1 iwanhoogendoorn  staff  3853 Jun  8 23:51 getallvms.py
-rwxr-xr-x  1 iwanhoogendoorn  staff  5335 Jun  8 23:51 poweronvm.py

Iwans-Mac:sample iwanhoogendoorn$ python getallvms.py -s 10.11.11.215 -u pyvmomi-user@sso-iwan.local -p VMware1!
root ##b##Name       :  vEOS-S14##!b##
root ##b##Path       :  [NFS-VIRTUALIZATION] vEOS-S14/vEOS-S14.vmx
root ##b##Guest      :  Other 2.6.x Linux (32-bit)
root ##b##State      :  poweredOn

Name       :  vEOS-S12
Path       :  [NFS-VIRTUALIZATION] vEOS-S12/vEOS-S12.vmx
Guest      :  Other 2.6.x Linux (32-bit)
State      :  poweredOn

Name       :  dedi
Path       :  [datastore1] NL-RTD01-DEDI01/NL-RTD01-DEDI01.vmx
Guest      :  Ubuntu Linux (64-bit)
State      :  poweredOn
IP         :  10.11.11.111

Name       :  dc1-pod12-esx-m-02
Path       :  [NFS-VIRTUALIZATION] dc1-pod12-esx-m-02/dc1-pod12-esx-m-02.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod12-esx-m-01
Path       :  [NFS-VIRTUALIZATION] dc1-pod12-esx-m-01/dc1-pod12-esx-m-01.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod12-esx-m-03
Path       :  [NFS-VIRTUALIZATION] dc1-pod12-esx-m-03/dc1-pod12-esx-m-03.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod12-esx-b-02
Path       :  [NFS-VIRTUALIZATION] dc1-pod12-esx-b-02/dc1-pod12-esx-b-02.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod13-control-01
Path       :  [NFS-VIRTUALIZATION] dc1-pod13-control/dc1-pod13-control.vmx
Guest      :  Microsoft Windows Server 2012 (64-bit)
State      :  poweredOn
IP         :  2002:c00d:dc0a::c00d:dc0a

Name       :  dc1-pod12-control-01
Path       :  [NFS-VIRTUALIZATION] dc1-pod12-control-01/dc1-pod12-control-01.vmx
Guest      :  Microsoft Windows Server 2012 (64-bit)
State      :  poweredOn
IP         :  2002:c00c:dc0a::c00c:dc0a

Name       :  dc1-pod12-esx-a-02
Path       :  [NFS-VIRTUALIZATION] dc1-pod12-esx-a-02/dc1-pod12-esx-a-02.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod11-esx-m-04
Path       :  [NFS-VIRTUALIZATION] dc1-pod11-esx-m-04/dc1-pod11-esx-m-04.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod11-esx-m-03
Path       :  [NFS-VIRTUALIZATION] dc1-pod11-esx-m-03/dc1-pod11-esx-m-03.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod12-esx-b-01
Path       :  [NFS-VIRTUALIZATION] dc1-pod12-esx-b-01/dc1-pod12-esx-b-01.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod11-esx-m-02
Path       :  [NFS-VIRTUALIZATION] dc1-pod11-esx-m-02/dc1-pod11-esx-m-02.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod11-esx-b-02
Path       :  [NFS-VIRTUALIZATION] dc1-pod11-esx-b-02/dc1-pod11-esx-b-02.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod11-esx-a-01
Path       :  [NFS-VIRTUALIZATION] dc1-pod11-esx-a-01/dc1-pod11-esx-a-01.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod12-esx-a-01
Path       :  [NFS-VIRTUALIZATION] dc1-pod12-esx-a-01/dc1-pod12-esx-a-01.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod11-esx-a-03
Path       :  [NFS-VIRTUALIZATION] dc1-pod11-esx-a-03/dc1-pod11-esx-a-03.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  vEOS-L142
Path       :  [NFS-VIRTUALIZATION] vEOS-L142/vEOS-L142.vmx
Guest      :  Other 2.6.x Linux (32-bit)
State      :  poweredOn

Name       :  dc1-pod11-esx-b-03
Path       :  [NFS-VIRTUALIZATION] dc1-pod11-esx-b-03/dc1-pod11-esx-b-03.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  vEOS-S13
Path       :  [NFS-VIRTUALIZATION] vEOS-S13/vEOS-S13.vmx
Guest      :  Other 2.6.x Linux (32-bit)
State      :  poweredOn

Name       :  CSR-1000V-R1
Path       :  [NFS-VIRTUALIZATION] CSR-1000V-R1/CSR-1000V-R1.vmx
Guest      :  Other 2.6.x Linux (64-bit)
State      :  poweredOn

Name       :  vEOS-L141
Path       :  [NFS-VIRTUALIZATION] vEOS-L141/vEOS-L141.vmx
Guest      :  Other 2.6.x Linux (32-bit)
State      :  poweredOn

Name       :  vEOS-L132
Path       :  [NFS-VIRTUALIZATION] vEOS-L132/vEOS-L132.vmx
Guest      :  Other 2.6.x Linux (32-bit)
State      :  poweredOn

Name       :  vEOS-L131
Path       :  [NFS-VIRTUALIZATION] vEOS-L131/vEOS-L131.vmx
Guest      :  Other 2.6.x Linux (32-bit)
State      :  poweredOn

Name       :  dc1-pod11-esx-m-01
Path       :  [NFS-VIRTUALIZATION] dc1-pod11-esx-m-01/dc1-pod11-esx-m-01.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  vEOS-L121
Path       :  [NFS-VIRTUALIZATION] vEOS-L121/vEOS-L121.vmx
Guest      :  Other 2.6.x Linux (32-bit)
State      :  poweredOn

Name       :  vEOS-L112
Path       :  [NFS-VIRTUALIZATION] vEOS-L112/vEOS-L112.vmx
Guest      :  Other 2.6.x Linux (32-bit)
State      :  poweredOn

Name       :  vEOS-S11
Path       :  [NFS-VIRTUALIZATION] vEOS-S11/vEOS-S11.vmx
Guest      :  Other 2.6.x Linux (32-bit)
State      :  poweredOn

Name       :  dc1-pod11-esx-b-01
Path       :  [NFS-VIRTUALIZATION] dc1-pod11-esx-b-01/dc1-pod11-esx-b-01.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  vEOS-L111
Path       :  [NFS-VIRTUALIZATION] vEOS-L111/vEOS-L111.vmx
Guest      :  Other 2.6.x Linux (32-bit)
State      :  poweredOn

Name       :  dc1-pod11-control-01
Path       :  [NFS-VIRTUALIZATION] dc1-pod11-control-01/dc1-pod11-control-01.vmx
Guest      :  Microsoft Windows Server 2012 (64-bit)
State      :  poweredOn
IP         :  2002:c00b:dc0a::c00b:dc0a

Name       :  vEOS-L122
Path       :  [NFS-VIRTUALIZATION] vEOS-L122/vEOS-L122.vmx
Guest      :  Other 2.6.x Linux (32-bit)
State      :  poweredOn

Name       :  win-01
Path       :  [datastore1-esx-01] win-server/win-server.vmx
Guest      :  Microsoft Windows Server 2012 (64-bit)
State      :  poweredOn
IP         :  10.11.11.50

Name       :  dc1-pod11-esx-a-02
Path       :  [NFS-VIRTUALIZATION] dc1-pod11-esx-a-02/dc1-pod11-esx-a-02.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  dc1-pod12-esx-b-03
Path       :  [NFS-VIRTUALIZATION] dc1-pod12-esx-b-03/dc1-pod12-esx-b-03.vmx
Guest      :  VMware ESXi 6.0
State      :  poweredOff

Name       :  vcsa-01
Path       :  [datastore1-esx-01] vcsa/vcsa.vmx
Guest      :  SUSE Linux Enterprise 11 (64-bit)
Annotation :  VMware vCenter Server Appliance
State      :  poweredOn
IP         :  10.11.11.215

As you can see we have gathered a list of all the VM's and we are using a ready-to-use script that was in the sample directory. The information that we see is Name, Path , Guest and State!

Alter the getallvms py script to only show virtual machine names

But what if we only want to VM names? Then we can alter the script a little. First we copy the script so we have a second script that we can alter and leave our original script unharmed.

Iwans-Mac:sample iwanhoogendoorn$ cp getallvms.py getallvms-only.py 

Iwans-Mac:sample iwanhoogendoorn$ ls
root ##b##getallvms-only.py##!b##       getallvms.py            poweronvm.py

Then alter the script:

Iwans-Mac:sample iwanhoogendoorn$ nano getallvms-only.py
getallvms-only.py - Original code snippet
summary = vm.summary
   print("Name       : ", summary.config.name)
   print("Path       : ", summary.config.vmPathName)
   print("Guest      : ", summary.config.guestFullName)
   annotation = summary.config.annotation
   if annotation != None and annotation != "":
      print("Annotation : ", annotation)
   print("State      : ", summary.runtime.powerState)
   if summary.guest != None:
      ip = summary.guest.ipAddress
      if ip != None and ip != "":
         print("IP         : ", ip)
   if summary.runtime.question != None:
      print("Question  : ", summary.runtime.question.text)
   print("")
getallvms-only.py - Replaced with this code snippet
summary = vm.summary
   print("Name       : ", summary.config.name)
#   print("Path       : ", summary.config.vmPathName)
#   print("Guest      : ", summary.config.guestFullName)
#   annotation = summary.config.annotation
#   if annotation != None and annotation != "":
#      print("Annotation : ", annotation)
#   print("State      : ", summary.runtime.powerState)
#   if summary.guest != None:
#      ip = summary.guest.ipAddress
#     if ip != None and ip != "":
#         print("IP         : ", ip)
#   if summary.runtime.question != None:
#      print("Question  : ", summary.runtime.question.text)
   print("")

Execute getallvms py again

Iwans-Mac:sample iwanhoogendoorn$ python getallvms-only.py -s 10.11.11.215 -u pyvmomi-user@sso-iwan.local -p VMware1!
root ##b##Name       :  vEOS-S14##!b##

Name       :  vEOS-S12

Name       :  dedi

Name       :  dc1-pod12-esx-m-02

Name       :  dc1-pod12-esx-m-01

Name       :  dc1-pod12-esx-m-03

Name       :  dc1-pod12-esx-b-02

Name       :  dc1-pod13-control-01

Name       :  dc1-pod12-control-01

Name       :  dc1-pod12-esx-a-02

Name       :  dc1-pod11-esx-m-04

Name       :  dc1-pod11-esx-m-03

Name       :  dc1-pod12-esx-b-01

Name       :  dc1-pod11-esx-m-02

Name       :  dc1-pod11-esx-b-02

Name       :  dc1-pod11-esx-a-01

Name       :  dc1-pod12-esx-a-01

Name       :  dc1-pod11-esx-a-03

Name       :  vEOS-L142

Name       :  dc1-pod11-esx-b-03

Name       :  vEOS-S13

Name       :  CSR-1000V-R1

Name       :  vEOS-L141

Name       :  vEOS-L132

Name       :  vEOS-L131

Name       :  dc1-pod11-esx-m-01

Name       :  vEOS-L121

Name       :  vEOS-L112

Name       :  vEOS-S11

Name       :  dc1-pod11-esx-b-01

Name       :  vEOS-L111

Name       :  dc1-pod11-control-01

Name       :  vEOS-L122

Name       :  win-01

Name       :  dc1-pod11-esx-a-02

Name       :  dc1-pod12-esx-b-03

Name       :  vcsa-01

We have now "hacked" into the script, but there are also some other scripts available on the internet that we can try.

Try another script that provides information about VMs 〈py-vminfo py〉

After searching for some scripts that can provide me information about specific VM's I came across this script (py-vminfo.py).

When executing the script I got an error:

Iwans-Mac:python-vmstats-master iwanhoogendoorn$ python py-vminfo.py -s 10.11.11.215 -u pyvmomi-user@sso-iwan.local -p VMware1! -m CSR-1000V-R1
root ##b##Could not connect to the specified host using specified username and password##!b##

I was pretty sure that I was using the correct username and password... After asking around and contacting the creator of the script we both discovered that this had to do with the way the script was trying to connect to the vCenter Server.

I have crosschecked the "getallvms-only.py" script that WAS WORKING for me and the "py-vminfo.py" script that WAS NOT WORKING and I discovered some change in the "SmartConnect" part.

Newer versions of vSphere have required certificate verification and a warning was always thrown up... It looks like perhaps this warning turned into a hard STOP unless you provided some sort of SSL override to say "It's OK I know this cert is self sign - for example - but carry on" This is now taken care of the new SSL code part that I added in the script.

More information regarding this can be found here.

I altered the script a bit with some new parts.

py-vminfo.py - Original code snippet:
try:
            si = SmartConnect(host=args.host,
                              user=args.user,
                              pwd=password,
                              port=int(args.port),
py-vminfo.py - Replaced with this code snippet:
#
import ssl -->added
#
        try:
            context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) --> added
            context.verify_mode = ssl.CERT_NONE  --> added
            si = SmartConnect(host=args.host,
                              user=args.user,
                              pwd=password,
                              port=int(args.port),
                              sslContext=context)  --> added

After I added in the new parts I tested the script again,

Iwans-Mac:sample iwanhoogendoorn$ python py-vminfo-2.py -s vcsa-01.home.local -u pyvmomi-user@sso-iwan.local -p VMware1! -m CSR-1000V-R1

NOTE: Any VM statistics are averages of the last 15 minutes

Server Name                    : CSR-1000V-R1
Description                    : 
Guest                          : Other 2.6.x Linux (64-bit)
Snapshot Status                : No Snapshots
VM .vmx Path                   : [NFS-VIRTUALIZATION] CSR-1000V-R1/CSR-1000V-R1.vmx
Virtual Disks                  : Hard disk 1 | 8.0GB | Thin: True | [NFS-VIRTUALIZATION] CSR-1000V-R1/CSR-1000V-R1.vmdk
Virtual NIC(s)                 : Network adapter 1 | vSwitch0 - VLAN20 | 00:50:56:b5:6b:07
                                 Network adapter 2 | CSR-1000-R1-Eth2 | 00:50:56:b5:9f:b2
                                 Network adapter 3 | CSR-1000-R1-Eth3 | 00:50:56:b5:bd:64
                                 Network adapter 4 | CSR-1000-R1-Eth4 | 00:50:56:b5:55:f5
                                 Network adapter 5 | CSR-1000-R1-Eth5 | 00:50:56:b5:b4:f3
                                 Network adapter 6 | VM Network | 00:50:56:b5:0b:7c
                                 Network adapter 7 | VM Network | 00:50:56:b5:9b:7e
                                 Network adapter 8 | VM Network | 00:50:56:b5:3c:5e
                                 Network adapter 9 | VM Network | 00:50:56:b5:de:b2
                                 Network adapter 10 | VLAN11 | 00:50:56:b5:43:9c
[VM] Limits                    : CPU: None, Memory: None
[VM] Reservations              : CPU: None, Memory: None
[VM] Number of vCPUs           : 1
[VM] CPU Ready                 : Average 0.0 %, Maximum 0.1 %
[VM] CPU (%)                   : 4 %
[VM] Memory                    : 4096 MB (4.0 GB)
[VM] Memory Shared             : 0 %, 4 MB
[VM] Memory Balloon            : 0 %, 0 MB
[VM] Memory Swapped            : 0 %, 0 MB
[VM] Memory Active             : 7 %, 276 MB
[VM] Datastore Average IO      : Read: 0 IOPS, Write: 0 IOPS
[VM] Datastore Average Latency : Read: 0 ms, Write: 2 ms
[VM] Overall Network Usage     : Transmitted 0.000 Mbps, Received 0.000 Mbps
[Host] Name                    : esx-03.home.local
[Host] CPU Detail              : Processor Sockets: 2, Cores per Socket 12
[Host] CPU Type                : Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz
[Host] CPU Usage               : Used: 4037 Mhz, Total: 52680 Mhz
[Host] Memory Usage            : Used: 52 GB, Total: 256 GB

As a bonus another script to test with 〈vminfo_quick py〉

After searching for more scripts to retrieve information about VM's a also came across this script(vminfo_quick.py).

I got an error after I executed the script.

Iwans-Mac:sample iwanhoogendoorn$ python vminfo_quick.py -s 10.11.11.215 -u pyvmomi-user@sso-iwan.local -p VMware1!
Traceback (most recent call last):
  File "vminfo_quick.py", line 19, in <module>
    from tools import cli
ImportError: No module named tools

Apparently the script is referring to a module "tools". In the initial git clone that I used it did not contain a "tools" directory where "cli" is in as well. So I needed to clone / download this "tools" folder as well and place it in the sample directory.

I used "Github downloader" to download complete github folders.

Iwans-Mac:Downloads iwanhoogendoorn$ chmod 777 github-downloader.sh 

Iwans-Mac:Downloads iwanhoogendoorn$ ./github-downloader.sh https://github.com/vmware/pyvmomi-community-samples/tree/master/samples/tools
root ##b##Exporting https://github.com/vmware/pyvmomi-community-samples/trunk/samples/tools
Error validating server certificate for 'https://github.com:443':
 - The certificate is not issued by a trusted authority. Use the
   fingerprint to validate the certificate manually!
Certificate information:
 - Hostname: github.com
 - Valid: from Thu, 10 Mar 2016 00:00:00 GMT until Thu, 17 May 2018 12:00:00 GMT
 - Issuer: www.digicert.com, DigiCert Inc, US
 - Fingerprint: d7:9f:07:61:10:b3:92:93:e3:49:ac:89:84:5b:03:80:c1:9e:2f:8b
(R)eject, accept (t)emporarily or accept (p)ermanently? t
A    tools
A    tools/README.md
A    tools/__init__.py
A    tools/alarm.py
A    tools/cli.py
A    tools/cluster.py
A    tools/datacenter.py
A    tools/interactive_wrapper.py
A    tools/pchelper.py
A    tools/serviceutil.py
A    tools/tasks.py
A    tools/vm.py
root ##b##Exported revision 239.

I moved the tools folder into the sample folder and run the script again ...

Iwans-Mac:sample iwanhoogendoorn$ python vminfo_quick.py -s 10.11.11.215 -u pyvmomi-user@sso-iwan.local -p VMware1!
root ##b##Unable to connect to host with supplied info.

I received another error, and I suspected that this had something to do with the SSL self signed certificate handeling so I started altering the script.


vminfo_quick.py - Original code snippet:
service_instance = connect.SmartConnect(host=args.host,
                                            user=args.user,
                                            pwd=args.password,
                                            port=int(args.port))
vminfo_quick.py - Replaced with this code snippet:
#
import ssl --> added
#
    context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) --> added
    context.verify_mode = ssl.CERT_NONE --> added
    service_instance = connect.SmartConnect(host=args.host,
                                            user=args.user,
                                            pwd=args.password,
                                            port=int(args.port),
                                            sslContext=context) --> added

I tested the script again.

Iwans-Mac:sample iwanhoogendoorn$ python vminfo_quick.py -s 10.11.11.215 -u pyvmomi-user@sso-iwan.local -p VMware1!
----
root ##b##Name:                    vEOS-S12
root ##b##BIOS UUID:               423550f0-eedf-9c20-93b1-be087fdc6e93
root ##b##CPUs:                    1
root ##b##MemoryMB:                2048
root ##b##Guest PowerState:        notRunning
root ##b##Guest Full Name:         Other 2.6.x Linux (32-bit)
root ##b##Guest Container Type:    other26xLinuxGuest
root ##b##Container Version:       vmx-11
----
Name:                    dc1-pod12-esx-m-03
BIOS UUID:               42353833-4bd4-6217-47c0-ff1222dbd652
CPUs:                    4
MemoryMB:                16384
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod12-esx-m-02
BIOS UUID:               42355f0a-d036-b3a4-948e-7747d8ab439a
CPUs:                    4
MemoryMB:                16384
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod12-esx-m-01
BIOS UUID:               4235c8ec-09d2-dc6e-43ea-3a0d4e2b0628
CPUs:                    4
MemoryMB:                16384
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    vEOS-S11
BIOS UUID:               4235ae48-650f-dd52-19b3-14883d2206cf
CPUs:                    1
MemoryMB:                2048
Guest PowerState:        notRunning
Guest Full Name:         Other 2.6.x Linux (32-bit)
Guest Container Type:    other26xLinuxGuest
Container Version:       vmx-11
----
Name:                    vEOS-S13
BIOS UUID:               4235e6e3-b135-b0d9-8074-81493a2bd2fe
CPUs:                    1
MemoryMB:                2048
Guest PowerState:        notRunning
Guest Full Name:         Other 2.6.x Linux (32-bit)
Guest Container Type:    other26xLinuxGuest
Container Version:       vmx-11
----
Name:                    dc1-pod12-esx-b-03
BIOS UUID:               4235c697-82fb-fdbc-984e-9d174cc54a3f
CPUs:                    4
MemoryMB:                16384
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod12-esx-a-02
BIOS UUID:               4235dc67-3d20-4ac5-307e-9eca0d7e187c
CPUs:                    2
MemoryMB:                8192
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod13-control-01
BIOS UUID:               4235b786-5675-ffa9-4101-a912f967f879
CPUs:                    2
MemoryMB:                2048
Guest PowerState:        running
Guest Full Name:         Microsoft Windows Server 2012 (64-bit)
Guest Container Type:    windows8Server64Guest
Container Version:       vmx-11
----
Name:                    dc1-pod12-esx-b-01
BIOS UUID:               4235800b-7cb9-ef23-1afd-2cfbed4f42ba
CPUs:                    2
MemoryMB:                8192
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod11-esx-m-04
BIOS UUID:               4235b78e-e0c4-285f-3775-2ef82138aa49
CPUs:                    4
MemoryMB:                16384
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod11-esx-m-02
BIOS UUID:               4235c58e-3b1e-73a3-6fb5-5f1021b401d6
CPUs:                    4
MemoryMB:                16384
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod11-esx-b-03
BIOS UUID:               423528f7-43ff-e219-9f33-98cabf1f908e
CPUs:                    2
MemoryMB:                8192
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod11-esx-m-03
BIOS UUID:               4235e1ea-80db-e693-b75f-a5aaa6a73d9a
CPUs:                    4
MemoryMB:                16384
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    vEOS-S14
BIOS UUID:               42356933-b536-c3fa-0af7-0d7823c8139f
CPUs:                    1
MemoryMB:                2048
Guest PowerState:        notRunning
Guest Full Name:         Other 2.6.x Linux (32-bit)
Guest Container Type:    other26xLinuxGuest
Container Version:       vmx-11
----
Name:                    dc1-pod11-esx-a-03
BIOS UUID:               4235a69d-242e-0f34-e130-c48fcdb38ed3
CPUs:                    2
MemoryMB:                8192
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod11-esx-b-02
BIOS UUID:               42353056-8f5d-e70d-a981-09f3f28602ab
CPUs:                    2
MemoryMB:                8192
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod12-esx-b-02
BIOS UUID:               4235d9f9-2426-cd40-1204-9819aa716fd7
CPUs:                    2
MemoryMB:                8192
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod11-esx-a-01
BIOS UUID:               4235b038-f95b-d4cd-0b93-a1975d993490
CPUs:                    2
MemoryMB:                8192
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod11-esx-a-02
BIOS UUID:               42358577-ad92-938b-5c3c-232eeef39d98
CPUs:                    2
MemoryMB:                8192
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    CSR-1000V-R1
BIOS UUID:               4235422e-73c9-ece8-28ab-eba4591a059c
CPUs:                    1
MemoryMB:                4096
Guest PowerState:        running
Guest Full Name:         Other 2.6.x Linux (64-bit)
Guest Container Type:    other26xLinux64Guest
Container Version:       vmx-10
----
Name:                    vEOS-L132
BIOS UUID:               42350af5-1cbf-c21e-b505-ff6fcc029d8b
CPUs:                    1
MemoryMB:                2048
Guest PowerState:        notRunning
Guest Full Name:         Other 2.6.x Linux (32-bit)
Guest Container Type:    other26xLinuxGuest
Container Version:       vmx-11
----
Name:                    vEOS-L142
BIOS UUID:               42355808-ecff-dc04-aaa1-fff3a4eb0b82
CPUs:                    1
MemoryMB:                2048
Guest PowerState:        notRunning
Guest Full Name:         Other 2.6.x Linux (32-bit)
Guest Container Type:    other26xLinuxGuest
Container Version:       vmx-11
----
Name:                    vEOS-L141
BIOS UUID:               4235cc90-773d-0b24-8441-9f6211f4419b
CPUs:                    1
MemoryMB:                2048
Guest PowerState:        notRunning
Guest Full Name:         Other 2.6.x Linux (32-bit)
Guest Container Type:    other26xLinuxGuest
Container Version:       vmx-11
----
Name:                    vEOS-L131
BIOS UUID:               4235750e-80b5-2ae0-1ce5-e28139cc093b
CPUs:                    1
MemoryMB:                2048
Guest PowerState:        notRunning
Guest Full Name:         Other 2.6.x Linux (32-bit)
Guest Container Type:    other26xLinuxGuest
Container Version:       vmx-11
----
Name:                    dc1-pod12-esx-a-01
BIOS UUID:               4235b5d8-1cbf-3199-6b9e-8a1f9e59eb54
CPUs:                    2
MemoryMB:                8192
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    dc1-pod11-esx-b-01
BIOS UUID:               42353446-5b82-c44b-4111-f589540a0fc2
CPUs:                    2
MemoryMB:                8192
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    vEOS-L122
BIOS UUID:               4235cb47-a3a9-a097-718a-865beea06fca
CPUs:                    1
MemoryMB:                2048
Guest PowerState:        notRunning
Guest Full Name:         Other 2.6.x Linux (32-bit)
Guest Container Type:    other26xLinuxGuest
Container Version:       vmx-11
----
Name:                    dc1-pod12-control-01
BIOS UUID:               42351bd7-ec64-35c5-4b70-cdb69c914b12
CPUs:                    2
MemoryMB:                2048
Guest PowerState:        running
Guest Full Name:         Microsoft Windows Server 2012 (64-bit)
Guest Container Type:    windows8Server64Guest
Container Version:       vmx-11
----
Name:                    dedi
BIOS UUID:               4207659f-ad6f-7720-bb2d-5a82795981e6
CPUs:                    8
MemoryMB:                16384
Guest PowerState:        running
Guest Full Name:         Ubuntu Linux (64-bit)
Guest Container Type:    ubuntu64Guest
Container Version:       vmx-11
----
Name:                    vEOS-L121
BIOS UUID:               4235cd21-525f-d609-e768-c1f7f7ee649f
CPUs:                    1
MemoryMB:                2048
Guest PowerState:        notRunning
Guest Full Name:         Other 2.6.x Linux (32-bit)
Guest Container Type:    other26xLinuxGuest
Container Version:       vmx-11
----
Name:                    dc1-pod11-esx-m-01
BIOS UUID:               4235fe19-fe92-028c-b25f-0a7e1fb7a8c0
CPUs:                    4
MemoryMB:                16384
Guest PowerState:        notRunning
Guest Full Name:         VMware ESXi 6.0
Guest Container Type:    vmkernel6Guest
Container Version:       vmx-11
----
Name:                    vEOS-L112
BIOS UUID:               42356240-4cfe-84a6-2704-78769eee0f60
CPUs:                    1
MemoryMB:                2048
Guest PowerState:        notRunning
Guest Full Name:         Other 2.6.x Linux (32-bit)
Guest Container Type:    other26xLinuxGuest
Container Version:       vmx-11
----
Name:                    dc1-pod11-control-01
BIOS UUID:               423585f2-73a0-c872-8522-4be2c1dfae47
CPUs:                    2
MemoryMB:                2048
Guest PowerState:        running
Guest Full Name:         Microsoft Windows Server 2012 (64-bit)
Guest Container Type:    windows8Server64Guest
Container Version:       vmx-11
----
Name:                    vEOS-L111
BIOS UUID:               4235137a-a2a8-8409-feb8-2b0101dd18f7
CPUs:                    1
MemoryMB:                2048
Guest PowerState:        notRunning
Guest Full Name:         Other 2.6.x Linux (32-bit)
Guest Container Type:    other26xLinuxGuest
Container Version:       vmx-11
----
Name:                    win-01
BIOS UUID:               42356ad0-c9bf-7116-0258-466c0f148ba4
CPUs:                    4
MemoryMB:                8192
Guest PowerState:        running
Guest Full Name:         Microsoft Windows Server 2012 (64-bit)
Guest Container Type:    windows8Server64Guest
Container Version:       vmx-11
----
Name:                    vcsa-01
BIOS UUID:               564d54fd-ce15-384b-74e9-f1593639618e
CPUs:                    4
MemoryMB:                16384
Guest PowerState:        running
Guest Full Name:         SUSE Linux Enterprise 11 (64-bit)
Guest Container Type:    sles11_64Guest
Container Version:       vmx-08

root ##b##Found 37 VirtualMachines.
root ##b##Completion time: 0.075805 seconds.