vmware / pyvmomi

VMware vSphere API Python Bindings
Apache License 2.0
2.19k stars 766 forks source link

Question: How to correctly add new PortGroup to ESXI ? #1042

Closed sYera21 closed 10 months ago

sYera21 commented 12 months ago

Describe the bug

Currently working on a project where I require adding new port groups to the esxi. The issue that Im facing is that im trying to create a port group spec that I can pass to host.networkSystem.AddPortGroup so it can show in my esxi, but it seems to give me a LazyType when I try to create a spec and pass it to the method .This is the code so far...

Reproduction steps

    pg_spec=vim.host.PortGroup.Specification
    print(type(pg_spec))
    pg_spec.name="BackUp"
    pg_spec.vlanId=4
    pg_spec.vswitchName="vSwitch0"
    netsys=host.configManager.networkSystem
    netsys.AddPortGroup(pg_spec)

Expected behavior

The expected behavior is to get a type vim.host.PortGroup.Specification that I can pass to my esxi host to add a port group.

Additional context

Any direction if im doing it right or wrong in terms of trying to add a port group. And any guidance someone can give me to help fix this. Thank You !

prziborowski commented 12 months ago
    pg_spec=vim.host.PortGroup.Specification()

This should instantiate the object. Without () part you are just updating the class information.