You can add devices to a virtual machine during creation using the VirtualMachineConfigSpec.deviceChange property, which is a VirtualDeviceSpec. You specify the host device that the virtual device should map to by using a backing object. A backing object represents the host device associated with a virtual device.
■ Backing information object – The backing information object allows you to supply data for virtual device configuration. You access a VirtualDeviceBackinInfo object as follows:To add a device to a virtual machine, you must first find out which devices are supported on the corresponding ESX/ESXi host, and then specify a VirtualDevice object. Perform these tasks to add a device to a virtual machine:
1 Find out which devices your ESXi system supports by calling the QueryConfigOption method, which you can access through the VirtualMachine.environmentBrowser property. The method returns a VirtualMachineConfigOption data object that specifies what the ESX/ESXi supports. For example, VirtualMachineConfigOption.hardwareOptions includes information about supported CPU and memory and an array of VirtualDeviceOption data objects.
Note You cannot use the QueryConfigOption method to create another instance of a default device. If you attempt to add a default device, such as an IDE controller, the server ignores the operation.
2 Specify the backing information object for the device. The actual process for defining the object differs for different objects. For example, for a CD-ROM passthrough device, you use a VirtualCdromPassthroughBackingInfo device. The VirtualDevice.backing property is a VirtualDeviceBackingInfo object which is extended by devices.The VirtualDevice.connectable property is a VirtualDeviceConnectInfo data object. This object provides information about restrictions on removing the device while a virtual machine is running. This property is null if the device is not removable.You define these items with the integer properties: controllerKey, key, and unitNumber. See the VirtualDevice data object in the API Reference.The deviceInfo property is a Description data object that has a name property and a summary property. You can supply a string value for each, describing the device.
6
7 Specify the VirtualDeviceConfigSpec as the deviceChange property to the VirtualMachineConfigSpec that you pass in to a Folder.CreateVM_Task or VirtualMachine.ReconfigVM_Task method.