短編小説: 詳しくは a,b,c を参照。一般的な推奨事項は、a) またはcontrollerKeys
特定の vmware ハードウェア モデルのハードコードされたリストのいずれかを使用することです。これは、c) よりも高速であり (大きなサイズの応答)、実装する手間が少ないためです。
a) 既存のデバイススペックからコントローラーキーを見つける
私たちのコードベースは、VM に既に存在するデバイス タイプのみを追加する傾向があるため、次のスニペットで十分です。
の既存のコントローラーからキーを取得します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) ハードウェア バージョンの有効なコントローラー キーのリスト
特定の vmware ハードウェア バージョンで利用可能なすべてが含まれている/etc/vmware/hostd/env/vmconfigoption-esx-hw8.xml
(esxi、ハードウェア バージョン 8 vms のデフォルト) を参照してください。controllerKeys
ハードcontrollerKeys
ウェア バージョンではかなり一貫していますが、将来のバージョンで変更される可能性はほとんどありません。
<deviceInfo>
<_type>vim.Description</_type>
<label>VirtualIDEController 0</label>
<summary>VirtualIDEController 0</summary>
</deviceInfo>
<key>200</key>
c) SOAP 経由で vmconfigoptions を一覧表示する
次のSOAP要求は、vsphere クライアント経由で新しい仮想マシンが作成されるたびに実行されます。その応答には、ほとんどのデバイスのハードウェア プロファイル (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>