Powering Off or Suspending a Virtual Machine
This section discusses the operations used to power off or suspend a virtual machine.
Choosing Whether to Power Off or Suspend
You can stop virtual machine execution in two ways. Whether you choose to power off or to suspend a virtual machine depends on your purpose.
- VixVM_PowerOff() is equivalent to turning off the power switch of a physical machine. Some operations on a virtual machine, such as changing the virtual hardware configuration, require that the virtual machine be powered off.
- VixVM_Suspend() is similar to putting a laptop to sleep. The virtual machine stops running. When you resume operation, the virtual machine continues exactly from the point of suspension
The suspend operation also saves the virtual machine's state on disk, allowing you to reboot the host or move the virtual machine to a new location without shutting down the guest operating system in the virtual machine.
Both functions are asynchronous, so either function call must be completed with a callback function or a call to VixJob_Wait().
Powering Off a Virtual Machine
To power off a virtual machine
- Connect to the host on which the virtual machine is located. See Connecting to a Host.
- Get a handle to the virtual machine. See Getting a Handle to a Virtual Machine.
- Use the virtual machine handle in a call to VixVM_PowerOff().
Example 3-12.
C code below. Click here for Perl. Click here for COM.
VixError err = VIX_OK; VixHandle jobHandle = VIX_INVALID_HANDLE; // Power off the virtual machine. jobHandle = VixVM_PowerOff(vmHandle, VIX_VMPOWEROP_FROM_GUEST, // powerOffOptions NULL, // callbackProc NULL); // clientData err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE); if (VIX_OK != err) { // Handle the error... goto abort; } Vix_ReleaseHandle(jobHandle); jobHandle = VIX_INVALID_HANDLE;
Suspending a Virtual Machine
- Connect to the host on which the virtual machine is located. See Connecting to a Host.
- Get a handle to the virtual machine. See Getting a Handle to a Virtual Machine.
- Use the virtual machine handle in a call to VixVM_Suspend().
Example 3-13.
C code below. Click here for Perl. Click here for COM.
VixError err = VIX_OK; VixHandle jobHandle = VIX_INVALID_HANDLE; // Suspend the virtual machine. jobHandle = VixVM_Suspend(vmHandle, 0, // powerOffOptions NULL, // callbackProc NULL); // clientData err = VixJob_Wait(jobHandle, VIX_PROPERTY_NONE); if (VIX_OK != err) { // Handle the error... goto abort; } Vix_ReleaseHandle(jobHandle); jobHandle = VIX_INVALID_HANDLE;