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 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 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.
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 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 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 ESXi hosts you must specify -host, -user, and -password options.
5
Read and Write VMDK Using vSphere API
The VMware vSphere Web Services API (version 2 and later) offers some methods to manage VMDK files. The VirtualDiskManager managed object defines more than a dozen methods similar to those in the Virtual Disk API documented here.
For more information, navigate to the latest VMware vSphere documentation center on the Web, search for VirtualDiskManager, and follow the specific link. At top of page you can click Local Methods to see a list of all methods defined by the VirtualDiskManager managed object.
VirtualDiskManager methods were not heavily used, and have not been updated to support object oriented file systems such as Virtual SAN (VSAN) or storage profile based management (SPBM).
Back Up First Class Disk (FCD)
First Class Disk (FCD) is a named virtual disk independent of a virtual machine. VDDK supports the backup of FCD in attached mode. This support is independent of transport mode.
VDDK does not support backing up a detached FCD. The workaround is to attach the FCD to a dummy virtual machine, which you then back up. The dummy can be a empty virtual machine without a guest OS.
To attach an FCD using the vSphere Web Client, click Edit virtual machine settings > New device: Select and add it as an Existing Hard Disk.
To attach an FCD using the vSphere API, you can call the AttachDisk_Task method.