The vSphere Guest SDK includes the test program vmGuestlibTest.c. If you are using a Windows environment, you must rebuild the test program. The
vmGuestLib.dll library file is a non-Unicode DLL. In Microsoft Visual Studio, build the test program
vmGuestlibTest.c as a non-Unicode executable file so that the program can access the DLL at runtime.
The vSphere Guest API runtime components are enabled by default (disable = “FALSE”). To disable the runtime components, use the configuration editor in the vSphere Client to edit the configuration file for the virtual machine. The virtual machine must be powered off before you can use the configuration editor.
The default value for the disable setting is FALSE. The default setting enables the runtime components. Reinstalling VMware Tools does not affect the disable setting. If you disable the vSphere Guest API and reinstall VMware Tools, the vSphere Guest API remains unavailable until you change the configuration setting
guestLibGetInfo.disable to
FALSE.
The vSphere Guest SDK contains the header file vmGuestLib.h. This file declares the functions and data types that you use to call the vSphere Guest API. The following sections describe the vSphere Guest API functions:
Example: Initializing the vSphere Guest API Environment shows a C code fragment that illustrates the function calls for initialization. (The code fragments in this section do not perform error handling. For information about error handling, see
vSphere Guest API Error Codes .)
You can use the session ID to detect changes that invalidate previously retrieved data. Example: Detecting Stale Data shows a code fragment that illustrates how to use the session ID to detect stale data. (The
ResetStats function in the following fragment represents application code to handle the session change.)
Open, Close, and Update Functions lists the context functions for creating and releasing handles, updating information, and obtaining session IDs.
Accessor functions retrieve information about a virtual machine. When you call an accessor function, you pass a guest library handle (type VMGuestLibHandle) to the function. If the function is successful, it returns the requested data as an output parameter. The function return value is an error code (type
VMGuestLibError) that indicates success or failure.
Example: Using an Accessor Function shows a C code fragment that illustrates an example of calling
VMGuestLib_GetCpuLimitMHz to retrieve the processor limit available to the virtual machine.
When a call completes successfully, the function returns the value VMGUESTLIB_ERROR_SUCCESS. If the call is unsuccessful, the error code name contains an appropriate description. For details, see
vSphere Guest API Error Codes .
Call VMGuestLib_UpdateInfo once to refresh all statistics before calling an accessor function or a series of accessor functions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handle is an input parameter specifying the guest library handle.
bufferSize is an input/output parameter. It is a pointer to the size of the pathBuffer in bytes. If bufferSize is not large enough to accommodate the path (including a NULL terminator), the function returns VMGUESTLIB_ERROR_BUFFER_TOO_SMALL. In this case, the function uses the bufferSize parameter to return the number of bytes required for the string.
pathBuffer is an output parameter. It is a pointer to a buffer that receives the resource pool path string. The path string is NULL-terminated.
|
For more information about ESXi resource management, see the vSphere Resource Management Guide, available on the VMware Web site.
To use the vSphere API to set limits or reservations, call the ReconfigVM_Task method. In the method call, use the
VirtualMachineConfigSpec data object to set the
cpuAllocation or
memoryAllocation property. These properties are of type
ResourceAllocationInfo, which has
limit and
reservation properties. For more information, see the VMware vSphere API Reference Documentation.
Each vSphere Guest API function returns an error code. If successful, the returned error code is VMGUESTLIB_ERROR_SUCCESS. If the function is unable to complete its task, the error code provides information for diagnosing the problem.
Use the VMGuestLib_GetErrorText function to retrieve the error text associated with a particular error code. When you call the function, pass the error code to the function;
VMGuestLib_GetErrorText returns a pointer to a string containing the error text.
Example: Error Handling shows error handling. The C code fragment declares a guest library handle and calls the function
VMGuestLib_OpenHandle. If the call is not successful, the code calls
VMGuestLib_GetErrorText and displays the error text.
Error Codes lists all error codes defined for the vSphere Guest API.