Scripting How-To: Map virtual machines attached to an interface using PyEZ and Python SDK for vCenter

By Elevate posted 11-09-2015 14:16


VMware vCenter VM's to Interface Mapping Tool


The following Python script was created to map all virtual machines attached to an interface using PyEZ and the Python SDK for vCenter.


The script does not work with NSX, however it will map standard vSwitches and distributed vSwitches.


It extracts VM information from vCenter and maps it to the interface using the PyEZ tables:

  • EthPortTable
  • VlanTable

We hope you find the script useful. It is located at: 


The following example shows output from the mapping tool:


ubuntu:systest$ python --port ge-2/0/35 --unit 0
Established connection to Juniper VMware vCenter
Established connection to Juniper System...

Interface        VLAN ID              VM MAC                Virtual Machine Name
ge-2/0/35.0      105                  00:50:56:a8:1a:e9            windows7.mydomain.local
ge-2/0/35.0      201                  00:50:56:a8:85:41      w2k10-1.mydomain.local
ge-2/0/35.0      201                  00:50:56:a8:d4:29      w2k10-2.mydomain.local
ge-2/0/35.0      201                  00:50:56:a8:52:54      w2k10-3.mydomain.local
ge-2/0/35.0      107                  00:50:56:a8:b1:f2       w2k10-3.mydomain.local
ge-2/0/35.0      107                  00:50:56:a8:0c:bb            MAAS.mydomain.local
ge-2/0/35.0      105                  00:50:56:a8:24:d6            JunosSpace.mydomain.local
ge-2/0/35.0      107                  00:50:56:a8:c8:91            OpenContrail1.mydomain.local
ge-2/0/35.0      105                  00:50:56:a8:a6:13            OpenContrail2.mydomain.local
ge-2/0/35.0      201                  00:50:56:11:11:11            OpenContrail3.mydomain.local
ge-2/0/35.0      201                  00:50:56:a8:f6:3c       MySQL-1.mydomain.local