You can configure a virtual machine during creation (Folder.CreateVM_Task) or cloning (
VirtualMachine.CloneVM_Task). You can also reconfigure a virtual machine using
VirtualMachine.ReconfigVM_Task. However, do not use the
VirtualMachine.ReconfigVM_Task call to create or add a disk.
In vSphere 5.5 and later, the ReconfigVM_Task method will throw an error when it attempts to change certain virtual machine properties while the virtual machine is powered on. In previous releases, the Server would modify the properties in the configuration specification and the changes would take effect after the virtual machine resets, reboots, or performs a fast suspend and resume.
The API reference lists all properties and includes information about required permissions for these configuration methods. The following sections describe some commonly specified attributes.
You can specify the display name for the virtual machine by setting the VirtualMachineConfigSpec.name property. Any % (percent) character used in this
name parameter must be escaped, unless it is used to start an escape sequence. Clients can also escape any other characters in this name parameter.
Use the annotation field to provide a description of the virtual machine. To remove an existing description, specify the empty string as the value of
annotation.
The location of the virtual machine is determined implicitly during creation because you call a Folder.CreateVM_Task method and specify resource pool and optional target host the virtual machine should belong to. See
Resource Management Objects for a discussion of resource pools and virtual machine location.
You can control a virtual machine’s boot behavior by setting the VirtualMachineConfigSpec.bootOptions property. The
VirtualMachineBootOptions data object in that property allows you to specify the following properties:
The VirtualMachineConfigSpec data object allows you to specify CPU and memory configuration.
To allocate resources, use the cpuAllocation and
memoryAllocation properties of
VirtualMachineConfigSpec. Both properties contain
ResourceAllocationInfo objects with the following properties:
Resource Allocation discusses resource allocation in the context of resource pool hierarchies. The
Resource Management Guide includes a detailed discussion of resource allocation in the vSphere environment.
Set CpuHotAddEnabled and
CpuHotRemoveEnabled to specify whether virtual processors can be added to or removed from a virtual machine while the virtual machine is running. Set
MemoryHotAddEnabled to specify whether memory can be added while the virtual machine is running.
You can set the number of virtual processors for the virtual machine with the VirtualMachineConfigSpec.numCPUs property. Legal values for this property change depending on the
guestosid value you specify.
If your virtual machine is on an ESX/ESXi system, and if you have a license that supports Symmetric Multiprocessors (SMP), you can configure the virtual machine to have multiple virtual CPUs by setting cpuAffinity and
memoryAffinity. You define a set of integers that represents the processors (for CPU) and NUMA nodes (for memory). If you are reconfiguring the affinity setting and leave the array empty, any existing affinity is removed. See the
Resource Management Guide for a discussion of NUMA nodes and affinity.
You can use the VirtualMachineConfigSpec.cpuFeatureMask[].info property to represent the CPU features requirements for a virtual machine or guest operating system. See the
HostCpuIdInfo data object discussion in the
API Reference for a detailed discussion.
You can add a virtual network interface to a virtual machine using a subclass of VirtualEthernetCard, you can set the
addressType to
Manual,
Generated, or
Assigned. If you choose
Assigned, you can specify a MAC address explicitly.
See Adding Devices to Virtual Machines.
The ESXi Configuration Guide discusses virtual machine MAC addresses in detail.
You can set up NPIV with the VirtualMachineConfigSpec properties that start with
npiv.
If a virtual machine’s VirtualMachineCapability.swapPlacementSupported property is
true for a virtual machine, you can specify a value for the
VirtualMachineConfigSpec.swapPlacement property. The value must be one of the values of the
VirtualMachineConfigInfoSwapPlacementType enumeration, as a string.