Vmware Scripting API User's Manual
Total Page:16
File Type:pdf, Size:1020Kb
VERSION 2.3 VMware Scripting API User’s Manual Please note that you can always find the most up-to-date technical documentation on our Web site at http://www.vmware.com/support/. VMware, Inc. The VMware Web site also provides the latest product updates Copyright © 1998-2006 VMware, Inc. All rights reserved. Protected by one or more of U.S. Patent Nos. 3145 Porter Drive 6,397,242, 6,496,847, 6,704,925, 6,711,672, 6,725,289, 6,735,601, 6,785,886, 6,789,156 6,795,966, 6, 880, 022, Palo Alto, CA 94304 6,961,941, 6,961,806 and 6,944,699; patents pending. VMware, the VMware “boxes” logo and design, Virtual www.vmware.com SMP and VMotion are registered trademarks or trademarks 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. Revision 20060925 Item: SDK-ENG-Q306-114 Table of Contents Introduction ___________________________________________________7 Introducing the VMware Scripting APIs _______________________________8 Supported Products ____________________________________________8 Intended Audience ____________________________________________9 Getting Support from VMware ___________________________________9 What’s New in This Release ________________________________________10 Using the VMware Scripting APIs ___________________________________13 Installing the VMware Scripting API _________________________________14 GSX Server __________________________________________________14 ESX Server __________________________________________________14 Installing the VMware Scripting API on a Windows Machine ____________14 Installing VmPerl Scripting API on a Linux Machine ___________________15 Using VmCOM ________________________________________________ 17 Using Symbolic Links __________________________________________18 Snapshots and Redo Logs ______________________________________18 Disk Device Names ___________________________________________19 VmCOM Objects _____________________________________________19 VmConnectParams ______________________________________________20 VmServerCtl ___________________________________________________21 Property ____________________________________________________21 Methods ____________________________________________________21 VmCollection __________________________________________________23 VmCtl ________________________________________________________24 Properties ___________________________________________________24 Methods ____________________________________________________26 VmQuestion ___________________________________________________32 Symbolic Constant Enumerations __________________________________33 VmExecutionState ____________________________________________33 VmPowerOpMode ____________________________________________33 VmProdInfoType _____________________________________________34 VmProduct __________________________________________________35 VmPlatform _________________________________________________35 3 Using VmCOM to Pass User-Defined Information Between a Running Guest Operating System and a Script _____________________________________36 GuestInfo Variables ___________________________________________36 Sending Information Set in a VmCOM Script to the Guest Operating System _ 37 Sending Information Set in the Guest Operating System to a VmCOM Script _ 37 Using Sample VmCOM Programs ________________________________ 39 Copyright Information ___________________________________________40 MiniMUI Visual Basic Sample Program _______________________________41 JScript and VBScript Sample Programs _______________________________42 JScript Sample Program 1 ______________________________________42 VBScript Sample Program 2 _____________________________________44 VBScript Sample Program 3 _____________________________________47 Using VmPerl ________________________________________________ 53 Using Symbolic Links __________________________________________54 Snapshots and Redo Logs ______________________________________55 Disk Device Names ___________________________________________55 VMware::VmPerl::ConnectParams ___________________________________56 VMware::VmPerl::Server ___________________________________________58 VMware::VmPerl::VM _____________________________________________60 Additional Information on get_tools_last_active _____________________67 VMware::VmPerl::Question ________________________________________69 Symbolic Constants _____________________________________________70 VM_EXECUTION_STATE_<XXX> Values ____________________________70 VM_POWEROP_MODE_<XXX> Values _____________________________70 Infotype Values ______________________________________________71 VM_PRODINFO_PRODUCT_<XXX> Values _________________________72 VM_PRODINFO_PLATFORM_<XXX> Values _________________________72 Using VmPerl to Pass User-Defined Information Between a Running Guest Operating System and a Script _____________________________________73 GuestInfo Variables ___________________________________________73 Sending Information Set in a VmPerl Script to the Guest Operating System 74 Sending Information Set in the Guest Operating System to a VmPerl Script 74 4 www.vmware.com Using Sample VmPerl Scripts ___________________________________ 77 Copyright Information ___________________________________________79 Listing the Virtual Machines on the Server ____________________________80 Starting All Virtual Machines on a Server _____________________________82 Checking a Virtual Machine’s Power Status ____________________________85 Monitoring a Virtual Machine’s Heartbeat _____________________________87 Answering Questions Posed by a Virtual Machine ______________________90 Suspending a Virtual Machine _____________________________________94 Setting a Virtual Machine’s IP Address Configuration Variable _____________96 Getting a Virtual Machine’s IP Address _______________________________99 Adding a Redo Log to a Virtual Disk (ESX Server 2.x only) ________________101 Committing a Redo Log to a Virtual Disk without Freezing the Virtual Machine (ESX Server 2.x only) ____________________________________________103 Error Codes and Event Logging ________________________________ 107 Error Codes ___________________________________________________108 Error Handling for the VmCOM Library ___________________________108 Error Handling for the VmPerl Library _____________________________108 Common VmCOM and VmPerl Errors ____________________________109 Event Logging ________________________________________________111 Using the Event Viewer _______________________________________111 Reading the Event Log ________________________________________113 vmware-cmd Utility __________________________________________ 115 vmware-cmd Utility Options _____________________________________116 vmware-cmd Operations on a Server _______________________________117 vmware-cmd Operations on a Virtual Machine _______________________118 Using Symbolic Links _________________________________________118 Snapshots and Redo Logs _____________________________________118 Disk Device Names __________________________________________118 Operations _________________________________________________119 <powerop_mode> Values _______________________________________125 vmware-cmd Utility Examples ____________________________________126 Retrieving the State of a Virtual Machine __________________________126 Performing a Power Operation _________________________________126 Setting a Configuration Variable ________________________________127 Connecting a Device _________________________________________127 5 VMware ESX Server Resource Variables __________________________ 129 VMware ESX Server System Resource Variables _______________________130 Virtual Machine Resource Variables for ESX Server _____________________135 Using ESX Server Virtual Machine Resource Variables Efficiently __________140 Using the Server Object _______________________________________140 Reusing a Single Server Object _________________________________140 Index ______________________________________________________ 141 6 www.vmware.com CHAPTER 1 Introduction This release of VMware™ Scripting APIs version 2.3 comprises two components: VmCOM and VmPerl. VmCOM is a Component Object Model (COM) interface for languages such as Microsoft® Visual Basic®, Microsoft® Visual Basic® Scripting Edition (also known as VBScript), Microsoft® Visual C++® and JScript®. You may install the VmCOM Scripting API on machines with the Microsoft® Windows® operating system. VmPerl is an application programming interface (API) that utilizes the Perl scripting language. You may install the VmPerl Scripting API on machines with the Microsoft Windows or Linux operating system. 7 VMware Scripting API User’s Manual Introducing the VMware Scripting APIs You may install the Scripting APIs on the GSX Server host and on remote workstations, connecting to GSX Server or ESX Server. VmCOM VmPerl GSX Server on a Windows host Windows remote workstation ESX Server VmPerl GSX Server on a Linux host Linux remote workstation Although the interfaces for VmCOM and VmPerl are different, both components are functionally equivalent. Depending on your operating system, you can either use VmCOM or VmPerl to accomplish the same tasks. VMware has designed VmCOM and VmPerl to provide task automation and simple, single-purpose user interfaces. The Scripting APIs are not intended for building advanced interactive user interfaces. For example, you can use the VMware Scripting APIs to perform power operations (start, stop, suspend or reset) on VMware