使用 pyVmomi 配置 VM 上的 SRIOV

2024-09-30 22:28:51 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Python2.7.6

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

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

从该网络适配器的SRV配置它自己(IOF)

我查看了git示例和vsphere sdk文档,但找不到如何做到这一点,而且关于pyVmomi的文档似乎很少

谢谢


Tags: 函数文档功能webui类型部署事情
1条回答
网友
1楼 · 发布于 2024-09-30 22:28:51

好吧,回答我自己的问题(为了子孙后代)

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)

相关问题 更多 >