Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. I'm using the code below in order to add a NIC configured with `DistributedVirtualSwitch` to an existing VM (via [pyVmomi][1]):
  2.  
  3. def __AddNIC(si, vmconf_dict, network_name):
  4. vm = __get_vm(si, vmconf_dict)
  5. print " Network label : " + network_name
  6.  
  7. devices = []
  8. nicspec = vim.vm.device.VirtualDeviceSpec()
  9. nicspec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
  10. nicspec.device = vim.vm.device.VirtualVmxnet3()
  11. nicspec.device.wakeOnLanEnabled = True
  12. nicspec.device.deviceInfo = vim.Description()
  13. nicspec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
  14. nicspec.device.connectable.startConnected = True
  15. nicspec.device.connectable.allowGuestControl = True
  16.  
  17. network_objref = _get_mor_by_property(si, vim.dvs.DistributedVirtualPortgroup, network_name)
  18. dswitch_port_connection = vim.dvs.PortConnection(
  19. portgroupKey=network_objref.key,
  20. switchUuid=network_objref.config.distributedVirtualSwitch.uuid
  21. )
  22. nicspec.device.backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo()
  23. nicspec.device.backing.port = dswitch_port_connection
  24.  
  25. devices.append(nicspec)
  26. vmconf = vim.vm.ConfigSpec(deviceChange=devices)
  27. task = vm.ReconfigVM_Task(vmconf)
  28. tasks.wait_for_tasks(si, [task])
  29.  
  30.  
  31. I'm getting the following exception:
  32.  
  33. > switchUuid=network_objref.config.distributedVirtualSwitch.uuid
  34. AttributeError: 'NoneType' object has no attribute 'uuid'
  35.  
  36.  
  37. After examination of Vcenter Managed Objects(via [mob][1]) it appears that
  38. **some of the *:`DistributedVirtualPortgroup`* object references does have this (*`VmwareDistributedVirtualSwitch`*) property, while others have this property *`Unset`*.**
  39.  
  40. I've tried multiple ways to work around that, such as:
  41.  
  42.  
  43. - Setting:
  44. `switchUuid=None` which yielded:
  45. >`TypeError: Required field "switchUuid" not provided (not @optional)`
  46.  
  47. - Setting:
  48. `dswitch_port_connection = None` which yielded:
  49. >`TypeError: Required field "port" not provided (not @optional)`
  50.  
  51.  
  52. **Note:** When I'm using VMware WebClient to configure the above it works perfectly.
  53.  
  54.  
  55. So my question is - how can I make adding a NIC like this work?
  56.  
  57.  
  58. [1]: https://github.com/vmware/pyvmomi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement