Interfacing With VMware vSphere
This section provides pointers to other vSphere programming interfaces.
The VIX API
The VIX API is a popular, easy-to-use developer interface for VMware Workstation, other hosted products, and ESX/ESXi. See the VMware developer documentation for information about the VIX API:
http://www.vmware.com/support/developer/vix-api
The VIX API Reference guide includes function reference pages for C++, Perl, and COM (component object model) for Microsoft C#, VBScript, and Visual Basic. Most reference pages include helpful code examples. Additionally, the vix-api Web guide includes examples for power on and off, suspending a virtual machine, taking a snapshot, guest operations, virtual machine discovery, and asynchronous callbacks.
Virus Scan all Hosted Disk
Suppose you want to run the antivirus software presented in Scan VMDK for Virus Signatures for all virtual machines hosted on a VMware Workstation. Here is the high-level algorithm for an VIX-based application that would scan hosted disk on all virtual machines.
To virus scan hosted virtual disk
1
2
3
4
Call VixHost_FindItems() with item-type (second argument) VIX_FIND_RUNNING_VMS.
This provides to a callback routine (fifth argument) the name of each virtual machine, one at a time. To derive the name of each virtual machine’s disk, append “.vmdk” to the virtual machine name.
5
Your callback function must be similar to the VixDiscoveryProc() callback function shown as an example on the VixHost_FindItems() page in the VIX API Reference Guide.
6
7
The vSphere Web Services API
The VMware vSphere Web Services (WS) API is a developer interface for ESX/ESXi hosts and vCenter Server. See the VMware developer documentation for information about the vSphere WS API:
http://www.vmware.com/support/developer/vc-sdk
The Developer’s Setup Guide for the VMware vSphere WS SDK has a chapter describing how to set up your programming environment for Microsoft C# or Java. Some of the information applies to C++ also.
The Programming Guide for the vSphere SDK contains some sample code written in Microsoft C# but most examples are written in Java, and based on the JAX-WS development framework.
ESX/ESXi hosts and the VMware vSphere WS API use a programming model based on Web services, in which clients generate Web services description language (WSDL) requests that pass over the network as XML messages encapsulated in simple object access protocol (SOAP). On ESX/ESXi hosts or vCenter Server, the vSphere layer answers client requests, usually passing back SOAP responses. This is a different programming model than the object-oriented function-call interface of C++ and the VIX API.
Virus Scan All Managed Disk
Suppose you want to run the antivirus software presented in Scan VMDK for Virus Signatures for all virtual machines hosted on an ESX/ESXi host. Here is the high-level algorithm for a VMware vSphere solution that can scan managed disk on all virtual machines.
To virus scan managed virtual disk
1
2
Call Vim::find_entity_views() to find the inventory of every VirtualMachine.
3
Call Vim::get_inventory_path() to get the virtual disk name in its appropriate resource.
The VMDK filename is available as diskPath in the GuestDiskInfo data object.
4
Using Perl’s system(@cmd) call, run the extended vixDiskLibSample.exe program with -virus option.
For ESX/ESXi hosts you must specify -host, -user, and -password options.
5
Read and Write VMDK with vSphere WS API
Version 2.5 and later of the VMware vSphere WS API contain some useful methods to manage VMDK files. See the managed object type VirtualDiskManager, which contains about a dozen methods similar to those in the Virtual Disk API documented here.
If you are interested, navigate to VMware Infrastructure SDK on the Web and click VI API Reference Guide for the 2.5 version or VMware vSphere WS API Reference Guide for the 4.0 version. Click All Types, search for VirtualDiskManager, and follow its link.