简体   繁体   中英

using pyVmomi to configure SRIOV on VM

Using Python 2.7.6

I am looking for the capability to deploy a VM from an OVF and then configure an SRIOV network device on it (similar to using the vsphere web ui -> Add network adapter -> change network adapter type to SRIOV) This requires two things that I could not find how to do:

1) Query an ESXi host itself and understand which NICs are supporting SRIOV and how many virtual functions do they expose (possibly query the vcenter)

2) configure the vm itself with the SRIOV network adapter of this type (after it was deployed from the OVF)

I looked at the git samples and vsphere sdk documentation and could not find how to do this, and there seems to be very little documentation at all about the pyVmomi

Thanks

ok, to answer my own question (for future generations)

devices = []
network_name = "Data"
vnic_label = "pyvmomi sriov nic1"

content = si.content
vm = get_obj(content, [vim.VirtualMachine], vm_name)
nic = vim.vm.device.VirtualDeviceSpec()

# VM device
nic.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
nic.device = vim.vm.device.VirtualSriovEthernetCard()
nic.device.addressType = 'assigned'
nic.device.key = 13016
nic.device.deviceInfo = vim.Description()
nic.device.deviceInfo.label = vnic_label
nic.device.deviceInfo.summary = network_name
nic.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
nic.device.backing.network = get_obj(content, [vim.Network], network_name)
nic.device.backing.deviceName = network_name
nic.device.backing.useAutoDetect = False
nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
nic.device.connectable.startConnected = True
nic.device.connectable.allowGuestControl = True

nic.device.sriovBacking = vim.vm.device.VirtualSriovEthernetCard.SriovBackingInfo()
nic.device.sriovBacking.physicalFunctionBacking = vim.vm.device.VirtualPCIPassthrough.DeviceBackingInfo()
nic.device.sriovBacking.physicalFunctionBacking.id = '84:00.1'
nic.device.sriovBacking.virtualFunctionBacking = vim.vm.device.VirtualPCIPassthrough.DeviceBackingInfo()
nic.device.sriovBacking.virtualFunctionBacking.id = '84:11.1'

devices.append(nic)

vmconf = vim.vm.ConfigSpec(deviceChange=devices)
task = vm.ReconfigVM_Task(vmconf)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM