So, I've got a VM that almost always asks a question when I try to revert it (or power it on, for that matter). I can see how I can detect this power state - set up a polling loop instead of calling VixJob_Wait - but I haven't been able to find any way to actually get or answer the question within the VIX API.
The details: I'm using VMware Server 2 rc1, running on an Ubuntu host. The VM in question has a serial port mapped to a pipe file. The pipe file doesn't get deleted if the VM is shut off suddenly - such as when it's being reverted. So, any time I try to programatically revert the machine, my program hangs.
If I manually log in to the web management interface (while my program is still hanging), I get the question: "msg.serial.pipe.posix.bind.open:A virtual serial port (serial0) is trying to connect to pipe "../../.WKS02.socket", which already exists. Another virtual machine may be running as a server for this pipe. What do you want to do?" - and when I manually answer this, the VM finishes reverting and my program completes as expected.
How can I automate discovering and answering this question? (Discovering is important, because while this is the most common stuck state I encounter, there are others that I know I need to be able to deal with without manual intervention.)
I don't know of a way to do this in VIX, but you can do it using VMPerl
Here's some code (no warrenties) that tries to do it:
use VMware::VmPerl::VM;
use VMware::VmPerl::ConnectParams;
use VMware::VmPerl::Question;
...
sub unstick
{
my $cfg = shift;
my $vm = &VMware::VmPerl::VM::new();
my $cp = get_connectparams_local();
if (! $vm || ! $vm->connect($cp, $cfg, 0)) {
my ($err, $errstr) = $vm->get_last_error();
print STDERR "$0: Could not connect to VM $cfg\n";
print STDERR " (VMControl error $err: $errstr)\n";
exit(-$err);
}
my $state = $vm->get_execution_state();
while ($state == 4) {
my $q = $vm->get_pending_question();
my $choice = 0;
my $text= $q->get_text();
$text=~ s/[\r\n]+/; /g;
print "$cfg: VM was showing question: $text (",$q->get_id(),")\n";
print " answering: $choice (choices are: ",join(', ',$q->get_choices()),")\n";
$vm->answer_question($q, $choice);
sleep(2); # give a couple seconds for answering to take affect, just in case
$state = $vm->get_execution_state();
}
undef $vm; # clean up object's resources
}