短故事:詳見的a,b,或c。一般的建議是堅持a)或硬編碼的controllerKeys
列表,用於特定的vmware硬件模型,因爲它比c)(大尺寸響應)更快並且更少實施。
一)找到controllerkey現有devicespec
我們的代碼庫往往只添加設備類型已經存在於我們的虛擬機,因此下面的片段是對我們非常充分,可能還有你:
獲得從type==ctrl_type
def _find_controller(self, ctrl_type, max_devs=None):
for dev in self._machine._vm.config.hardware.device:
if isinstance(dev, ctrl_type):
if not max_devs or len(dev.device) < max_devs:
return dev
raise ControllerNotFoundException(ctrl_type)
一個已經存在的控制鍵的具體使用情況,這是增加另一個IDE類型CDROM(這僅添加到引用的規範,並承諾一次性更高版本):
def _add_cdrom(self, spec, path):
spec.device.controllerKey = self._find_controller(vim.vm.device.VirtualIDEController, max_devs=2).key
dev = VSphereMediaDevice(spec.device, self._machine)
dev._spec.device.backing = vim.vm.device.VirtualCdrom.IsoBackingInfo()
dev.mount(path)
spec.device.backing = dev._spec.device.backing
B)爲您的硬件版本
有效controllerkeys列表看看/etc/vmware/hostd/env/vmconfigoption-esx-hw8.xml
(ESXi的,默認適用於硬件版本8 vms),其中包含特定vmware硬件版本的所有可用controllerKeys
。 controllerKeys
對於硬件版本非常一致,但在未來的版本中總會有變化的可能性不大。
<deviceInfo>
<_type>vim.Description</_type>
<label>VirtualIDEController 0</label>
<summary>VirtualIDEController 0</summary>
</deviceInfo>
<key>200</key>
經由SOAP
c)列出vmconfigoptions每當經由vSphere Client中創建了一個新的虛擬機的請求following SOAP執行。其響應包含大部分設備的硬件配置文件(win8,win7,winlonghorn,...)以及controllerKeys
。但我想這可能是一種矯枉過正,如果由於沉重的反應你必須多次這樣做。
POST /sdk HTTP/1.1
User-Agent: VMware VI Client/xxx
Content-Type: text/xml; charset="utf-8"
SOAPAction: "urn:internalvim25/5.0"
Host: xxx
Cookie: vmware_soap_session="xxxx"
Content-Length: 526
...<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<operationID>xxx</operationID>
</soap:Header>
<soap:Body>
<QueryConfigOption xmlns="urn:internalvim25">
<_this xsi:type="ManagedObjectReference" type="EnvironmentBrowser" serverGuid="">ha-env-browser-vmx-08</_this>
<key>vmx-08</key>
</QueryConfigOption>
</soap:Body>
</soap:Envelope>
響應(截斷):
HTTP/1.1 200 OK
Date: xxx
Cache-Control: no-cache
Connection: Keep-Alive
Content-Type: text/xml; charset=utf-8
Transfer-Encoding: chunked
7ED8
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<QueryConfigOptionResponse xmlns="urn:internalvim25"><returnval><version>vmx-08</version><description>Hardware version 8 virtual machine</description><guestOSDescriptor><id>windows8Server64Guest
....
<defaultDevice xsi:type="VirtualIDEController"><key>200</key><deviceInfo><label>IDE 0</label><summary>IDE 0</summary></deviceInfo><busNumber>0</busNumber></defaultDevice><defaultDevice xsi:type="VirtualIDEController"><key>201</key><deviceInfo><label>IDE 1</label><summary>IDE 1</summary></deviceInfo><busNumber>1</busNumber></defaultDevice><defaultDevice xsi:type="VirtualPS2Controller"><key>300</key><deviceInfo><label>PS2 controller 0</label><summary>PS2 controller 0</summary></deviceInfo><busNumber>0</busNumber></defaultDevice><defaultDevice xsi:type="VirtualPCIController"><key>100</key><deviceInfo><label>PCI controller 0</label><summary>PCI controller 0</summary></deviceInfo><busNumber>0</busNumber></defaultDevice><defaultDevice xsi:type="VirtualSIOController"><key>400</key><deviceInfo><label>SIO controller 0</label><summary>SIO controller 0</summary></deviceInfo><busNumber>0</busNumber></defaultDevice><defaultDevice xsi:type="VirtualKeyboard"><key>600</key><deviceInfo><label>Keyboard </label><summary>Keyboard</summary></deviceInfo><controllerKey>300</controllerKey><unitNumber>0</unitNumber></defaultDevice><defaultDevice xsi:type="VirtualPointingDevice"><key>700</key><deviceInfo><label>Pointing device</label><summary>Pointing device; Device</summary></deviceInfo><backing xsi:type="VirtualPointingDeviceDeviceBackingInfo"><deviceName></deviceName><useAutoDetect>false</useAutoDetect><hostPointingDevice>autodetect</hostPointingDevice></backing><controllerKey>300</controllerKey><unitNumber>1</unitNumber></defaultDevice><defaultDevice xsi:type="VirtualMachineVideoCard"><key>500</key><deviceInfo><label>Video card </label><summary>Video card</summary></deviceInfo>
謝謝你的有用的信息和詳細的答覆。我認爲這正是我們需要的! – codekoala