vmware/pyvmomi-community-samples

add_nic_to_vm.py issue: TypeError: For "deviceName" expected type str, but got vim.dvs.DistributedVirtualPortgroup

Open

#647 opened on Jul 21, 2020

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Python (914 forks)batch import
help wanted

Repository metrics

Stars
 (972 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Traceback (most recent call last): File "./add_nic_to_vm-new.py", line 165, in main() File "./add_nic_to_vm-new.py", line 158, in main add_nic(serviceInstance, vm, args.port_group) File "./add_nic_to_vm-new.py", line 113, in add_nic nic_spec.device.backing.deviceName = network File "/usr/local/lib/python2.7/dist-packages/pyVmomi/VmomiSupport.py", line 537, in setattr CheckField(self._GetPropertyInfo(name), val) File "/usr/local/lib/python2.7/dist-packages/pyVmomi/VmomiSupport.py", line 972, in CheckField % (info.name, info.type.name, valType.name)) TypeError: For "deviceName" expected type str, but got vim.dvs.DistributedVirtualPortgroup

If we change line #113 from: nic_spec.device.backing.deviceName = network to: nic_spec.device.backing.deviceName = network.name

then it works.

Contributor guide