VMware {code} Community
srimini
Contributor
Contributor

how to monitor tasks using VI SDK that is how to know when a task has exactly completed

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

0 Kudos
5 Replies
Steve_Jin
Expert
Expert

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

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:

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
0 Kudos
srimini
Contributor
Contributor

Hi,

the shutdowguest method doesnt return anything...how can i get a task refernce for that? please help me

Thanks in advance

Regards,

Padmini

0 Kudos
ykalchev
VMware Employee
VMware Employee

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

Yasen Kalchev, vSM Dev Team
0 Kudos
ultra01
Contributor
Contributor

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();

0 Kudos
RockyConcept
Contributor
Contributor

Is there any solution for this problem. I am also facing the same problem.

0 Kudos