VMware {code} Community
gierone
Contributor
Contributor

Function RebootGuest() stop when VmWare tools service isn't started

Hello,

I'm using VI Perl Toolkit to reboot my virtual machines and more particulary the function rebootGuest(). If the vmware tools service isn't started or doesn't work for any reason, the fonction can't reboot the vm and stop the script. How Can I ensure that the script doesn't stop in progress if a vm doesn't have the service started ?

Thank you.

Reply
0 Kudos
3 Replies
stumpr
Virtuoso
Virtuoso

You can check that the tools property is defined. You can also wrap your call in an eval { } block and catch any raised errors from running the soapcall.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
gierone
Contributor
Contributor

Ok, thank you for your help, I think I will check before if the vmware tools is defined. Do you know the method I have to use ? Else I will search by myself.

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso

Yes, you'd use the defined function. You would test to see if a VirtualMachine's GuestInfo property is defined.


if ( defined $vm_view->guest ) {
     # Do something productive here
}
else {
     # Complain about missing tools here
}

You may want to write a safe check function if you don't want your scripts to generate a run time error when accessing VMware SDK properties. A lot of the properties are not guaranteed to be set. Eval can be a bit easier to manage since you sometimes end up with a long list of if statements. I sometimes just use the ternary operator for value properties

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos