How to Retrieve Task Info

This is how to retrieve a task info in you have the task MOR:

ObjectContent[] objs =
connection.Service.RetrieveProperties(
   connection.ServiceContent.propertyCollector, new PropertyFilterSpec[]
   {
      new PropertyFilterSpec()
      {
          objectSet = new ObjectSpec[]
             { new ObjectSpec() { obj = taskMOR } },
          propSet = new PropertySpec[]
          {
             new PropertySpec()
             {
                all = false, allSpecified = true,
                type = "Task", pathSet = new String[] { "info" }
             }
          }
      }
   });
TaskInfo result = (TaskInfo)objs[0].propSet[0].val;

10 thoughts on “How to Retrieve Task Info”

  1. I dont see a method on TaskInfo to wait for it. I am doing a clone on a vm and need to wait for it to complete.

    How does one do that ?

    suresh

    1. You pull the task info properties regularly until its ’state’ property has ’success’ or ‘error’ value.
      If the value is ’success’ then this task info ‘result’ property has the reference to the newly created virtual machine.

  2. I have the TaskInfo object in hand, but now I want to set the description so that vCenter displays it in the task panel.

    LocalizableMessage lm = new LocalizableMessage(); lm.setMessage(“Hello World”); myTask.getTaskInfo().setDescription(lm);

    …but this doesn’t seem to be doing the trick. If I use setTaskState(TaskInfoState.error), the task panel indeed displays the task with the error state.

    Any ideas how to get a meaningful description up on vCenter’s details column in the task panel?

    Thanks.

    1. David,

      Very interesting question, but I’m not sure it is possible to set a custom task description like you do.

      See, the description of a task gets assigned by descriptionId property of the Task.

      List of available descriptions is an array, and it belongs to the TaskManager (description property).

      When I retrieve this property from the TaskManager, it returns three arrays:

      methodInfo
      reason
      state

      First (methodInfo) array in my case has a length of 746 elements. Each element consists if key, label and summary. The key is what is used to identify the task description that is displayed as content of the summary property.

      Sorry I wish it would be a little less complicated.

      If I were you I would try to expand the methodInfo array with your key/label/summary structure and assign your task that your key as its descriptionId.

      But I’m not sure you can change properties on the TaskManager.

      See TaskDescription documentation.

      Good luck and let me know if you get it working.

    1. David,

      Have you noticed that this method requires Task.Update privilege?

      I’m not sure about Steve’s Toolkit: I know it, but I don’t use any, all my code is raw calls to VMware API from C#.

      Let’s me try to get it working over the weekend, I’m a little busy tomorrow.

  3. I have a small doubt in the last line

    TaskInfo result = (TaskInfo)objs[0].propSet[0].val;
    objs[0].propSet[0].val is of DynamicProperty type. I wonder how can we cast it like that. I am doing it in C++. However when i store it in a DynamicProperty and then i set my TaskInfo DynamicProperty to this value. Something like
    result->setDynamicProperty(objs[0].propSet[0].val);

    The problem is my result->getState() is always NULL.

  4. Hey DM,

    The line you refer to is fine.

    If you code it in C++ then you need to do a proper casting, and C++ casting is out of scope of this article.

Comments are closed.