使用pyVmomi配置虚拟机上的SRIOV

0 投票
1 回答
1570 浏览
提问于 2025-04-18 18:43

使用的是Python 2.7.6

我想要实现的功能是从OVF文件部署一个虚拟机,然后在这个虚拟机上配置一个SRIOV网络设备(这跟在vsphere网页界面上操作类似 -> 添加网络适配器 -> 将网络适配器类型改为SRIOV)。不过,这个过程需要两个我找不到的方法:

1) 查询一个ESXi主机,了解哪些网卡支持SRIOV,以及它们能提供多少个虚拟功能(可能需要查询vcenter)。

2) 在虚拟机部署完成后,配置这个虚拟机的SRIOV网络适配器。

我查看了Git上的示例和vsphere SDK的文档,但没有找到相关的方法,而且关于pyVmomi的文档似乎也非常少。

谢谢!

1 个回答

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)

撰写回答