vmware / pyvmomi-community-samples

A place for community contributed samples for the pyVmomi library.
Apache License 2.0
1.01k stars 922 forks source link

No need to search port for VM VNIC connection to DVS #750

Open ckjhljcy opened 3 months ago

ckjhljcy commented 3 months ago

Describe the bug

In this example: https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/add_vm_nic_to_dvs.py

When connect VM VNIC to a DVPG of DVS, we first try to get a free port. That is not necessary. Auto expand of the port in DVPG has been here for years and it is enabled by default on DVPG. That's, if there is no enough port, vCenter will automatically create a port for the VM.

Thanks to the auto expand, the client doesn't need to specify the portKey in the VNIC backing: nic_spec.device.backing.port.portKey = port.key

Reproduction steps

Create DVS and use add_vm_nic_to_dvs.py to connect VM VNIC to DVS. There will be 16 ports by default created. So you will find after run the script for 16 times, you can't add any vnic to that DVPG.

Expected behavior

The script should not search free port for the VM VNIC. Just let the vCenter auto expand the port if there is no free ones.

Additional context

No response