Skip to content

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 Comments

  1. suresh iyer wrote:

    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

    Monday, March 1, 2010 at 7:34 pm | Permalink
  2. Deem wrote:

    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.

    Tuesday, March 2, 2010 at 12:44 pm | Permalink
  3. David wrote:

    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.

    Thursday, May 13, 2010 at 11:19 am | Permalink
  4. Deem wrote:

    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.

    Thursday, May 13, 2010 at 12:05 pm | Permalink
  5. David wrote:

    Hey Deem, thanks for the response. I posted a somewhat related question on the VI Java API forum (https://sourceforge.net/projects/vijava/forums/forum/826592/topic/3708248), and have been trying to use that.

    Basically, I added a setTaskDescription method to Steve Jin’s code, following his style.

    Sad as it may be, that didn’t work, either. I feel like I am close. There’s got to be a way to set those descriptions.

    Thursday, May 13, 2010 at 5:34 pm | Permalink
  6. Deem wrote:

    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.

    Thursday, May 13, 2010 at 8:15 pm | Permalink
  7. Deem wrote:

    David,

    See this posting.

    Sorry about me confusing assigning a task description with assigning a custom label/summary.

    Friday, May 14, 2010 at 12:57 pm | Permalink
  8. David wrote:

    Deem, not setting the key was the root of all my problems. Thanks!

    Monday, May 17, 2010 at 3:23 pm | Permalink
  9. DM wrote:

    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.

    Friday, May 27, 2011 at 2:49 pm | Permalink
  10. Deem wrote:

    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.

    Friday, May 27, 2011 at 2:58 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*

Soft & Virt is Digg proof thanks to caching by WP Super Cache