0

我浏览了文档(http://pubs.vmware.com/vsphere-55/index.jsp),找不到任何关于将虚拟机添加到 vlan 的信息。有很多关于创建和配置它们的信息,但没有如何通过 pyvmomi(或 esxcli,如果需要)向它们添加虚拟机。我很确定它可以完成,因为您可以通过 vSphere 客户端轻松完成,但我希望以自动化方式完成。

4

1 回答 1

2

The code from https://github.com/rreubenur/vmware-python-examples/blob/master/clone_vm_on_each_host/reconfigure_vnics.py ended up helping me a great deal:

nicspec = vim.vm.device.VirtualDeviceSpec()
nicspec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
nicspec.device = nic_type
nicspec.device.wakeOnLanEnabled = True
nicspec.device.deviceInfo = vim.Description()
nicspec.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
nicspec.device.backing.network = self.get_obj(content, [vim.Network], net_name)
nicspec.device.backing.deviceName = net_name

nicspec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
nicspec.device.connectable.startConnected = True
nicspec.device.connectable.allowGuestControl = True

devices.append(nicspec)

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

Allowed me to create the proper config object for connecting to a virtual network on a standard switch.

nic_type is the type of network device (e1000, pc32, etc.), net_name is the name of the network (portgroup). The rest is pretty self-explanatory.

于 2014-06-04T14:49:21.057 回答