Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
This document supports the version of each product listed and supports all subsequent versions until the document is replaced by a new edition. To check for more recent editions of this document, see http://www.vmware.com/support/pubs.
EN-000389-00
You can find the most up-to-date technical documentation on the VMware Web site at: http://www.vmware.com/support/ The VMware Web site also provides the latest product updates. If you have comments about this documentation, submit your feedback to: docfeedback@vmware.com
Copyright 2005, 2007, 2009, 2010 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents. VMware is a registered trademark or trademark of VMware, Inc. in the United States and/or other jurisdictions. All other marks and names mentioned herein may be trademarks of their respective companies.
VMware, Inc.
Contents
AboutThisBook
5 7
VMwarevSphereGuestSDKProgrammingGuide
OverviewofthevSphereGuestAPI 7 SupportedGuestOperatingSystems 7 VirtualMachineStatistics 7 HowtoUsethevSphereGuestAPI 8 vSphereGuestAPIRuntimeComponents 8 EnablingandDisablingtheRuntimeComponents 8 vSphereGuestAPIDataTypes 9 vSphereGuestAPIFunctions 9 ContextFunctions 9 AccessorFunctions(VirtualMachine) 11 vSphereGuestAPIErrorCodes 13
Index 15
VMware, Inc.
VMware, Inc.
Revision History
Thisbookisrevisedwitheachreleaseoftheproductorwhennecessary.Arevisedversioncancontainminor ormajorchanges.Table 1summarizesthesignificantchangesineachversionofthisbook. Table 1. Revision History
Revision Date 13JUL2010 7MAY2009 29NOV2007 18JUL2005 Description Nonewinformation,butrevisedtonotesupportforVMwareESX4.1. RevisedmanualforVMwareESXversion4.0. Nonewinformation,butrevisedtonotesupportforVMwareESX3.5andVMwareESX3iversion3.5. InitialreleaseoftheVMwareGuestSDKprovidingsupportforVMwareESX3.0.
Intended Audience
Thisbookisintendedforanyonedevelopingapplicationstoruninsideguestoperatingsystemsunder VMwareESX.
Document Feedback
VMwarewelcomesyoursuggestionsforimprovingourdocumentation.Sendyourfeedbackto docfeedback@vmware.com.
VMware, Inc.
Support Offerings
TofindouthowVMwaresupportofferingscanhelpmeetyourbusinessneeds,goto http://www.vmware.com/support/services.
VMware, Inc.
TheVMwareGuestAPIprovidesfunctionsthatyoucanuseinaprogramthatrunsintheguestoperating systemenvironmentonaVMwareESXvirtualmachine.Thisguideincludesthefollowingtopics:
OverviewofthevSphereGuestAPIonpage 7 HowtoUsethevSphereGuestAPIonpage 8
SeetheGuestOperatingSystemInstallationGuideforalistofsupportedguestoperatingsystemversions.
VMware, Inc.
VMware, Inc.
4 5 6
ContextFunctionsonpage 9 AccessorFunctions(VirtualMachine)onpage 11
Context Functions
ThevSphereGuestAPIprovidesasetoffunctionsthatinitializeandmanipulatethecontextinwhichthe GuestAPIoperates.Beforeyourapplicationcanusetheaccessorfunctionstoretrieveinformationabouta virtualmachine,usethefollowingfunctionstoinitializethevSphereGuestAPIenvironment. 1 2 3 CalltheVMGuestLib_OpenHandlefunctiontoobtainahandleforaccessinginformationaboutthevirtual machine.TheguestlibraryhandleisaparametertoeveryGuestAPIfunction. CalltheVMGuestLib_UpdateInfofunctiontoupdatetheinformationavailablethroughthehandle. CalltheVMGuestLib_GetSessionIdfunctiontoretrieveasessionID.
VMware, Inc.
Example 1showsaCcodefragmentthatillustratesthefunctioncallsforinitialization.(Thecodefragmentsin thissectiondonotperformerrorhandling.Forinformationabouterrorhandling,seevSphereGuestAPI ErrorCodesonpage 13.) Example 1. Initializing the vSphere Guest API Environment
VMGuestLibHandle glHandle; VMGuestLibError glError; VMSessionId sid = 0; glError = VMGuestLib_OpenHandle(&glHandle); glError = VMGuestLib_UpdateInfo(glHandle); glError = VMGuestLib_GetSessionId(glHandle, &sid);
VMGuestLib_CloseHandle VMGuestLib_UpdateInfo
10
VMware, Inc.
Whenacallcompletessuccessfully,thefunctionreturnsthevalueVMGUESTLIB_ERROR_SUCCESS.Unsuccessful callsreturnerrorcodesthatcontainanappropriatedescriptionaspartoftheerrorcodename.Fordetails,see vSphereGuestAPIErrorCodesonpage 13. CallVMGuestLib_UpdateInfooncetorefreshallstatisticsbeforecallinganaccessorfunctionoraseriesof accessorfunctions. Table 4. Accessor Functions for Virtual Machine Data
Function VMGuestLib_GetCpuLimitMHz Description RetrievestheupperlimitofprocessoruseinMHzavailabletothevirtual machine.ForinformationaboutsettingtheCPUlimit,seeLimitsand Reservationsonpage 12. RetrievestheminimumprocessingpowerinMHzreservedforthevirtual machine.ForinformationaboutsettingaCPUreservation,seeLimitsand Reservationsonpage 12. RetrievesthenumberofCPUsharesallocatedtothevirtualmachine.For informationabouthowanESXserverusesCPUsharestomanagevirtual machinepriority,seethevSphereResourceManagementGuide. Retrievesthenumberofmillisecondsthatthevirtualmachinewasina readystate(abletotransitiontoarunstate),butwasnotscheduledtorun. Retrievesthenumberofmillisecondsduringwhichthevirtualmachine hasusedtheCPU.Thisvalueincludesthetimeusedbytheguest operatingsystemandthetimeusedbyvirtualizationcodefortasksforthis virtualmachine.Youcancombinethisvaluewiththeelapsedtime (VMGuestLib_GetElapsedMs)toestimatetheeffectivevirtualmachine CPUspeed.ThisvalueisasubsetofelapsedMs. Retrievesthenumberofmillisecondsthathavepassedinthevirtual machinesinceitlaststartedrunningontheserver.Thecountofelapsed timerestartseachtimethevirtualmachineispoweredon,resumed,or migratedusingVMotion.Thisvaluecountsmilliseconds,regardlessof whetherthevirtualmachineisusingprocessingpowerduringthattime. YoucancombinethisvaluewiththeCPUtimeusedbythevirtualmachine (VMGuestLib_GetCpuUsedMs)toestimatetheeffectivevirtualmachine CPUspeed.cpuUsedMSisasubsetofthisvalue. RetrievesthespeedoftheESXsystemsphysicalCPUinMHz. Retrievestheamountofmemorythevirtualmachineisactivelyusingits estimatedworkingsetsize. Retrievestheamountofmemorythathasbeenreclaimedfromthisvirtual machinebythevSpherememoryballoondriver(alsoreferredtoasthe vmmemctldriver). Retrievestheupperlimitofmemorythatisavailabletothevirtual machine.Forinformationaboutsettingamemorylimit,seeLimitsand Reservationsonpage 12. Retrievestheamountofmemorythatisallocatedtothevirtualmachine. Memorythatisballooned,swapped,orhasneverbeenaccessedis excluded.
VMGuestLib_GetCpuReservationMHz
VMGuestLib_GetCpuShares
VMGuestLib_GetCpuStolenMs VMGuestLib_GetCpuUsedMs
VMGuestLib_GetElapsedMs
VMGuestLib_GetMemLimitMB
VMGuestLib_GetMemMappedMB
VMware, Inc.
11
VMGuestLib_GetMemReservationMB
FormoreinformationaboutESXresourcemanagement,seethevSphereResourceManagementGuide,available ontheVMwareWebsite. Limits and Reservations YouusetheGuestAPItoretrieveinformationaboutlimitsandreservationsforCPUandmemory.Tosetlimits andreservations,youcanuseeitherthevSphereClientorthevSphereAPI.Settinglimitsandreservationson avirtualmachineensuresthatresourcesareavailabletothatmachineandtoothervirtualmachinesthatdraw resourcesfromthesameresourcepool. TousethevSphereClienttosetlimitsorreservations: 1 2 3 InthevSphereClientwindow,clickontheResourceAllocationtab. IneithertheCPUorMemorysection,clickEdit. IntheVirtualMachinePropertiesWindow,clickontheResourcestab.
12
VMware, Inc.
4 5
SelecteithertheCPUorMemorysetting. Usetheslidercontrolstosetlimitsorreservations.
VMGUESTLIB_ERROR_INVALID_HANDLE
VMGUESTLIB_ERROR_INVALID_ARG VMGUESTLIB_ERROR_UNSUPPORTED_VERSION
VMware, Inc.
13
14
VMware, Inc.
Index
Numerics
32-bit guest support 8 64-bit guest support 8
A
accessor functions 11
C
configuration file for virtual machine 8 context functions 9
D
data types 9 disabling the vSphere Guest API 8
E
enabling the vSphere Guest API 8
H
handle 9, 11 how to use the vSphere Guest API 8
L
libvmGuestLib.so 8 Linux guest operating system 7
N
non-Unicode DLL (Windows) 8
VMGuestLib_CloseHandle 10 VMGuestLib_GetCpuLimitMHz 11 VMGuestLib_GetCpuReservationMHz 11 VMGuestLib_GetCpuShares 11 VMGuestLib_GetCpuStolenMs 11 VMGuestLib_GetCpuUsedMs 11 VMGuestLib_GetElapsedMs 11 VMGuestLib_GetHostProcessorSpeed 11 VMGuestLib_GetMemActiveMB 11 VMGuestLib_GetMemBalloonedMB 11 VMGuestLib_GetMemLimitMB 11 VMGuestLib_GetMemMappedMB 11 VMGuestLib_GetMemOverheadMB 12 VMGuestLib_GetMemReservationMB 12 VMGuestLib_GetMemSharedMB 12 VMGuestLib_GetMemSharedSavedMB 12 VMGuestLib_GetMemShares 12 VMGuestLib_GetMemSwappedMB 12 VMGuestLib_GetMemUsedMB 12 VMGuestLib_GetResourcePoolPath 12 VMGuestLib_GetSessionId 10 VMGuestLib_OpenHandle 10 VMGuestLib_UpdateInfo 10 VMGuestLibError 9 VMGuestLibHandle 9 VMGuestLibSessionID 9 vSphere Guest API runtime components 8
O
overview of the vSphere Guest API 7
W
Windows guest operating system 7
R
refreshing all statistics 11 runtime components 8
S
session ID 9 supported guest operating systems 7
T
technical support resources 5 test program vmGuestlibTest.c 8
V
virtual machine statistics 7 vmGuestLib.h 9 vmGuestLib.lib 8
VMware, Inc. 15
16
VMware, Inc.