gpt4 book ai didi

python - PyVmomi 添加网卡与未连接的 dvs ('config.distributedVirtualSwitch' 未设置)

转载 作者:太空狗 更新时间:2023-10-29 17:34:08 26 4
gpt4 key购买 nike

我正在使用下面的代码将配置有 DistributedVirtualSwitch 的 NIC 添加到现有 VM(通过 pyVmomi):

def __AddNIC(si, vmconf_dict, network_name):
vm = __get_vm(si, vmconf_dict)
print " Network label : " + network_name

devices = []
nicspec = vim.vm.device.VirtualDeviceSpec()
nicspec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
nicspec.device = vim.vm.device.VirtualVmxnet3()
nicspec.device.wakeOnLanEnabled = True
nicspec.device.deviceInfo = vim.Description()
nicspec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
nicspec.device.connectable.startConnected = True
nicspec.device.connectable.allowGuestControl = True

network_objref = _get_mor_by_property(si, vim.dvs.DistributedVirtualPortgroup, network_name)
dswitch_port_connection = vim.dvs.PortConnection(
portgroupKey=network_objref.key,
switchUuid=network_objref.config.distributedVirtualSwitch.uuid
)
nicspec.device.backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo()
nicspec.device.backing.port = dswitch_port_connection

devices.append(nicspec)
vmconf = vim.vm.ConfigSpec(deviceChange=devices)
task = vm.ReconfigVM_Task(vmconf)
tasks.wait_for_tasks(si, [task])

我收到以下异常:

switchUuid=network_objref.config.distributedVirtualSwitch.uuid AttributeError: 'NoneType' object has no attribute 'uuid'

在检查 Vcenter Managed Objects(通过 mob )后,似乎某些 DistributedVirtualPortgroup 对象引用确实具有该 (VmwareDistributedVirtualSwitch) 属性,而其他对象引用则具有该属性未设置

VmwareDistributedVirtualSwitch Set

VmwareDistributedVirtualSwitch Unset

我尝试了多种方法来解决这个问题,例如:

  • 设置:switchUuid=None 结果:

    TypeError: Required field "switchUuid" not provided (not @optional)

  • 设置:dswitch_port_connection = None 结果:

    TypeError: Required field "port" not provided (not @optional)

注意:当我使用 VMware WebClient 配置上面的内容时,它工作得很好。

问题:我怎样才能像这样添加 NIC?

最佳答案

最终经过严格的实验,设置:

dswitch_port_connection = '<Unset>'

解决了这个问题,并导致添加带有已配置但未连接的 DVS 的 NIC。

关于python - PyVmomi 添加网卡与未连接的 dvs ('config.distributedVirtualSwitch' 未设置),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35408105/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com