The VirtualMachine.CreateSnapshot_Task method creates a new snapshot of a virtual machine. As a side effect, the current snapshot becomes the parent of the new snapshot.

The method allows you to specify a name for the snapshot and also requires you set the memory and quiesce properties:

  • memory – If true, a dump of the internal state of the virtual machine (basically a memory dump) is included in the snapshot. Memory snapshots consume time and resources, and take a while to create. When set to false, the power state of the snapshot is set to powered off.
  • quiesce – If true and the virtual machine is powered on when the snapshot is taken, VMware Tools is used to quiesce the file system in the virtual machine. This ensures that a disk snapshot represents a consistent state of the guest file systems. If the virtual machine is powered off or VMware Tools is not available, the quiesce flag is ignored.

The example calls this method as follows:

ManagedObjectReference taskMor = service.createSnapshot_Task(
                                       vmMor, snapshotName, desc, false, false);

The method returns MOR to a Task object with which to monitor the operation. The info.result property in the Task contains the newly created VirtualMachineSnapshot upon success.