We launched our VI Toolkit for Windows 1.0 a little over a week ago and it’s been a bit of a time sink. Now that I’m looking to direct some attention toward some of the other things I deal with around here, this blog should start looking a bit more lively.
As I mentioned a long time ago in my first post, VIX provides some capabilities that you can’t get through any of our other APIs, specifically the ability to perform some very useful guest operations. In this post I’m going to examine how we can use some of these guest calls to run programs inside of VMs.
In this week’s edition: starting and stopping services with VIX.
This week I’ve got a sample of how you can use VIX to start and restart services inside of VMs. The key APIs here are APIs that let you log into a VM guest and run a program inside the VM guest. Here’s the code I use so you can play along at home. To run this code you’ll need 3 things:
- A compatible VMware product to run it against.
- A VM with VMware tools installed.
- VIX with Perl support. If you want to run this code against ESX like I do, you’ll need VIX 1.5, which you can get from the VMware Server 2.0 Beta or VMware Workstation 6.5 Beta.
The specific example I’ll cover here is that of starting the print service inside a Windows VM running on an ESXi server. Here’s a screenshot of my environment:
Using the script above, here’s the command I can use to start the print spooler.
Notice that this script requires two logins: first we must log into the host, then we must login to the VM itself to run the program. If you’re running this against a local VMware Workstation or Server, you don’t need to authenticate to the VM host, but you will still need a login to the VM guest. After executing this script, here’s what I see on the command line:
There are some pretty ugly warnings there, but it gets the job done. In addition, we see the output of the command I executed so we know it was successful After hitting F5 in the guest console, here’s the "after" screenshot from the VI Client.
As you can see, the service is started. Of course the script lets you run arbitrary commands, it’s not really specific to service management, there are a lot of things you can do with it. A few examples would be:
- Editing configuration files.
- Setting IP addresses on VMs that may not be networked.
- Lots, lots more.
Some assembly required.
This example is in Perl for two reasons, 1) It’s possible to run it on either Windows or Linux and 2) I have no idea how to write VB Script. If you’re on Linux, installing the VIX Perl module is fairly straightforward, but if you’re on Windows it can be very tricky since it requires a compilation environment that can be difficult to set up properly. To try to help for Windows users I’ve create an ActiveState PPM module that might work for you if you’re using ActiveState Perl. If anyone tries it, let me know your experiences — good or bad.