使用pyVmomi在VM上配置SRIOV

时间:2014-08-27 14:31:44

标签: python vmware esxi ovf

使用Python 2.7.6

我正在寻找从OVF部署VM然后在其上配置SRIOV网络设备的功能(类似于使用vsphere web ui - >添加网络适配器 - >将网络适配器类型更改为SRIOV) 这需要两件我无法找到的事情:

1)查询ESXi主机本身并了解哪些NIC支持SRIOV以及它们公开了多少虚拟功能(可能会查询vcenter)

2)使用此类型的SRIOV网络适配器配置vm本身(从OVF部署之后)

我查看了git示例和vsphere sdk文档但无法找到如何执行此操作,而且似乎关于pyVmomi的文档很少

由于

1 个答案:

答案 0 :(得分:2)

好的,回答我自己的问题(为后代)

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)