VMware

This Question is Possibly Answered

1 "correct" answer available (10 pts) 2 "helpful" answers available (6 pts)
4 Replies Last post: Nov 2, 2009 7:29 PM by ultra01  

how to monitor tasks using VI SDK that is how to know when a task has exactly completed posted: Jan 18, 2009 8:58 PM

Click to view srimini's profile Novice 27 posts since
Apr 23, 2008

Hi ,

i need to know when actually a task is completed using VI API whether it is a success or failure ..........for example if i use shutdownguest method on a vm to shut down the guest the method returns immediately invoking the task...but can someone help me with the code to know whethet the system has shut down completely?

Thanks in advance

Regards,

Padmini

Click to view Steve Jin's profile Expert 388 posts since
Jun 4, 2007

You can poll the Task managed object for its info.state. If it's done successfully, it is Enum success.

http://pubs.vmware.com/vi-sdk/visdk250/ReferenceGuide/vim.TaskInfo.State.html

You are right the method is async call so you have to block your thread by yourself. If you use VI Java API, it's as simple as:

Task task = vm. shutdownGuest();

if(task.waitForme==Task.SUCCESS)

{...}

else

{...}

Steve JIN, VMware Engineering
Creator of VI Java API: http://vijava.sf.net/

Click to view ykalchev's profile Hot Shot 68 posts since
Mar 5, 2008
Hi,

According to VI SDK API reference vm.ShutdownGuest method just send shutdown command to guest operating system and returns immediately. It does not wait for the guest operating system to complete the operation.
The easiest way to check if operation is completed is to loop and wait vm.runtime.powerstate to change to poweredOff.
You can also check if guest has a pending shutdown command examining vm.guest.guestState == "shuttingdown"

Regards,
Yasen
Click to view ultra01's profile Novice 11 posts since
Apr 2, 2009
Hi. The problem with that is vm.shutdownGuest() is of type void :

VMpowerOps.java:117: incompatible types
found : void
required: com.vmware.vim25.mo.Task
Task task = vm.shutdownGuest();

Developer Social Media

Communities