A backup application can also use information contained in a VirtualMachineConfigInfo. If at backup time you preserve all the VirtualMachineConfigInfo details that describe the virtual machine, you can transfer much of this information into a VirtualMachineConfigSpec to create a virtual machine at restore time. However, some of the information in VirtualMachineConfigInfo is not needed, and if used in the Spec, virtual machine creation can fail. For example, a VirtualMachineConfigSpec that contains information about so called “Default Devices” usually fails. The list of default devices includes:
vim.vm.device.VirtualIDEController vim.vm.device.VirtualPS2Controller vim.vm.device.VirtualPCIController vim.vm.device.VirtualSIOController vim.vm.device.VirtualKeyboard vim.vm.device.VirtualVMCIDevice vim.vm.device.VirtualPointingDevice
However, other controllers and devices must be explicitly included in the VirtualMachineConfigSpec.
Some information about devices is unneeded and can cause problems if supplied. Each controller device has its vim.vm.device.VirtualController.device field, which is an array of devices that report to the controller. The server rebuilds this list when a virtual machine is created, using the (negative) device key numbers supplied as a guide. The relationship between controller and device must be preserved using negative key numbers in the same relationship as in the hardware array of VirtualMachineConfigInfo.
The parent property for virtual disk backing information must be set to null. In the sample code for creating a virtual machine, find vim.vm.device.VirtualDisk.FlatVer2BackingInfo under SCSI disk one and SCSI disk two. The null setting is required because the pre-backup snapshot causes the parent property to be populated with a reference to the base disk.
One other configuration needs substitution. VirtualMachineConfigInfo contains the cpuFeatureMask, field, which is an array of HostCpuIdInfo. The array entries must be converted to ArrayUpdateSpec entries containing the VirtualMachineCpuIdInfoSpec along with the “operation” field, which must contain the value ArrayUpdateOperation::add. The VirtualMachineCpuIdInfoSpec also contains a HostCpuIdInfo array that you can copy from the cpuFeatureMask array in VirtualMachineConfigInfo. These items are not reflected in the sample code. Everything else can be copied intact from VirtualMachineConfigInfo data.
To summarize: when creating a virtual machine in which to restore virtual disk:
- Exclude default devices, and VirtualController.device, from the VirtualMachineConfigSpec.
- Set the parent virtual disk backing information (VirtualDisk.FlatVer2BackingInfo) to null.
- Convert HostCpuIdInfo array entries to ArrayUpdateSpec, insert ArrayUpdateOperation::add, and copy the HostCpuIdInfo array from cpuFeatureMask into VirtualMachineConfigInfo.