Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I'm using the code below in order to add a NIC configured with `DistributedVirtualSwitch` to an existing VM (via [pyVmomi][1]):
- def __AddNIC(si, vmconf_dict, network_name):
- vm = __get_vm(si, vmconf_dict)
- print " Network label : " + network_name
- devices = []
- nicspec = vim.vm.device.VirtualDeviceSpec()
- nicspec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
- nicspec.device = vim.vm.device.VirtualVmxnet3()
- nicspec.device.wakeOnLanEnabled = True
- nicspec.device.deviceInfo = vim.Description()
- nicspec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
- nicspec.device.connectable.startConnected = True
- nicspec.device.connectable.allowGuestControl = True
- network_objref = _get_mor_by_property(si, vim.dvs.DistributedVirtualPortgroup, network_name)
- dswitch_port_connection = vim.dvs.PortConnection(
- portgroupKey=network_objref.key,
- switchUuid=network_objref.config.distributedVirtualSwitch.uuid
- )
- nicspec.device.backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo()
- nicspec.device.backing.port = dswitch_port_connection
- devices.append(nicspec)
- vmconf = vim.vm.ConfigSpec(deviceChange=devices)
- task = vm.ReconfigVM_Task(vmconf)
- tasks.wait_for_tasks(si, [task])
- I'm getting the following exception:
- > switchUuid=network_objref.config.distributedVirtualSwitch.uuid
- AttributeError: 'NoneType' object has no attribute 'uuid'
- After examination of Vcenter Managed Objects(via [mob][1]) it appears that
- **some of the *:`DistributedVirtualPortgroup`* object references does have this (*`VmwareDistributedVirtualSwitch`*) property, while others have this property *`Unset`*.**
- I've tried multiple ways to work around that, such as:
- - Setting:
- `switchUuid=None` which yielded:
- >`TypeError: Required field "switchUuid" not provided (not @optional)`
- - Setting:
- `dswitch_port_connection = None` which yielded:
- >`TypeError: Required field "port" not provided (not @optional)`
- **Note:** When I'm using VMware WebClient to configure the above it works perfectly.
- So my question is - how can I make adding a NIC like this work?
- [1]: https://github.com/vmware/pyvmomi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement