I’ve been playing with VMware lately, both Workstation and VMware Infrastructure (VI). The company has really stepped up with the new SDKs and the level of programmable interfaces, making some excellent implementation decisions that enable us to drive virtual machines for primarily unit-testing purposes. The doc is a little light today, so this should help.
What do we use this for?
We (at my day job) developed a tool (in C#) that runs MSI installers to make sure the product installs on various knownly good or bad environments, sort of unit testing installers. We also have an ESX environment that we share.
VMWare Programming APIs
There’re two types of APIs.
-
VMWare Virtual Infrastructure SDK : a set of tools and APIs to manage a VMWare Infrastructure environment. A toolkit has also been released that contains managed wrappers on top of the SOAP interface provided by a VMWare deployment. It’s focused on VMWare ESX or VirtualCenter management and is beyond the scope of this post.
-
VMWare VIX API. The VIX API allows you to write programs and scripts that automate virtual machine operations, as well as the guests within virtual machines. It runs on both Windows and Linux and supports management of VMware Server, Workstation, and Virtual Infrastructure (both ESX and vCenter). Bindings are provided for C, Perl, and COM (Visual Basic, VBscript, C#). In this post I’ll focus on the C# implementation.
What do you need?
- Either VMWare Workstation 6.5, a VI environment (I use ESX), or both.
- VMWare ViX. This is the SDK, obtained from here. The new 1.6.2 version is required for VI support.
Connecting to a VMWare Workstation or ESX Server
Connecting to a local VMWare Workstation or an ESX server is virtually identical. The ESX server requires an URL to the SOAP SDK (eg. https://esxserver/sdk) and a username and password.
Locating a Virtual Machine
A virtual machine on a VMWare Workstation is a file with a standard path (eg. C:\Virtual Machines\myvirtualmachine.vmx). Unsurprisingly it is the same thing on an ESX server, but with a relative storage path. The latter can be found in the VMWare Infrastructure Client: right click on a virtual machine, choose Edit Settings, click the Options tab and note the Virtual Machine Configuration File (eg. [storage] virtualmachine/virtualmachine.vmx).
Power-on, power-off, copy and execute
These are straightforward operations supported by the SDK via the IVM interface returned set by the above-mentioned OpenFile method. Here’re some examples.
It is now possible to execute commands synchronously and asynchronously, without having to involve WMI or another similar method.
I think the whole job-based API could use a nice .NET wrapper :)
Update (2015)
Check out VMWareTasks.