VMware {code} Community
creativeview
Contributor
Contributor
Jump to solution

Getting Task state from TaskInfo

Hi,

I have been trying to get the task status from ApplyStorageDrsRecommendation_Task today and not had any luck. I just get "queued" even when the task has completed. To test this out some more I have writen some code in c# to power on the vm, wait and then check the status. Can anyone correct where I'm going wrong using TaskInfo with the provided managed object ref.

         // name of the vm to power on
        string VMname = "testvm";
        // Find the MoRef for the VM
        NameValueCollection searchVMCol = new NameValueCollection();
        searchVMCol.Add("name", VMname);
        EntityViewBase tempMoRefID = vClient.FindEntityView(typeof(VirtualMachine), vClient.ServiceContent.RootFolder, searchVMCol, null);
        VirtualMachine VM = new VirtualMachine(vClient, tempMoRefID.MoRef);
       
        //power on the vm
        ManagedObjectReference PowerON_Task_MoRef = VM.PowerOnVM_Task(null);
       
        Response.Write("Power on task: " + PowerON_Task_MoRef + "<BR>");
        Thread.Sleep(4000);
        TaskInfo TaskInfoObj = new TaskInfo();
        TaskInfoObj.Task = PowerON_Task_MoRef;       
        Response.Write(TaskInfoObj.State + "<BR>");

Thanks,

David

Tags (4)
0 Kudos
1 Solution

Accepted Solutions
Steve_Jin
Expert
Expert
Jump to solution

The problem is the following code:

TaskInfo TaskInfoObj = new TaskInfo();

TaskInfo is the type of a property defined with the Task managed object. With the ManagedObjectReference of a Task, you should use PropertyCollector to get its property. The TaskInfo is not meant to be "new"ed. If you use open source VI Java API, you will have Task object, and simple call:

TaskInfo ti = task.getInfo();

To clarify the concept, check out: http://www.doublecloud.org/2011/06/managedobjectreference-vs-managedobject/

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

View solution in original post

0 Kudos
3 Replies
creativeview
Contributor
Contributor
Jump to solution

Can anyone help with this? I'm still struggling to make this work.

Thanks,

David

0 Kudos
thornyurchin
Contributor
Contributor
Jump to solution

Is it PowerCLI Views? Perhaps this will help?

http://pubs.vmware.com/vsphere-50/index.jsp?topic=/com.vmware.powercli.ug.doc_50/GUID-48727FB6-BA66-...

Anyway, state of TaskInfo will not change by itself, additional data querying from the server is needed. By creating filter and view for Task itself, or something like this.

0 Kudos
Steve_Jin
Expert
Expert
Jump to solution

The problem is the following code:

TaskInfo TaskInfoObj = new TaskInfo();

TaskInfo is the type of a property defined with the Task managed object. With the ManagedObjectReference of a Task, you should use PropertyCollector to get its property. The TaskInfo is not meant to be "new"ed. If you use open source VI Java API, you will have Task object, and simple call:

TaskInfo ti = task.getInfo();

To clarify the concept, check out: http://www.doublecloud.org/2011/06/managedobjectreference-vs-managedobject/

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