Created
April 13, 2015 15:09
-
-
Save hartsock/b7c3a9b5159b137b7b2d to your computer and use it in GitHub Desktop.
This is a quick and dirty sample that shows how to go from a VM's name to a mac address by using the inventory path (more robust than a simple name)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_vm_to_mac(self): | |
si = connect.SmartConnect(host='vcsa', | |
user='my_user', | |
pwd='my_password') | |
content = si.RetrieveContent() | |
# where the name of the VM is 'box' | |
vm = content.searchIndex.FindByInventoryPath("Datacenter0/vm/box") | |
self.assertEqual(vm.name, 'box') | |
nics = [dev for dev in vm.config.hardware.device | |
if isinstance(dev, vim.vm.device.VirtualEthernetCard)] | |
self.assertEqual(nics[0].macAddress, '00:50:56:82:28:7d') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note the line...
... is nice because it doesn't care about data types, only MAC addresses.