VMware Communities > Developer Community > Management APIs (VI Perl, VI SDK, CIM SDK) > Discussions

This Question is Answered

2 "helpful" answers available (6 pts)
4 Replies Last post: Jan 8, 2008 6:13 AM by asp24
Reply

List current tasks and its progress (percent) for a selected VM

Jan 7, 2008 8:57 AM

Click to view asp24's profile Enthusiast asp24 48 posts since
Oct 11, 2006

I'm looking for a way to list current tasks and its progress (percent) for a selected VM (with Perl). I can't find an example script for this. Maybe some of you can point me in the right direction..? Examples?
Reply Re: List current tasks and its progress (percent) for a selected VM Jan 7, 2008 10:02 AM
Click to view ssurana's profile Hot Shot ssurana 130 posts since
Oct 1, 2007
VMware
Hi,

To begin with you can have a look at the samples shipped along with the SDK. For example there is a sample named TaskList.java present under the package com.vmware.samples.general. You can tweak this code to also display the information you are looking for. In case you are looking for samples in perl then there are number of samples that are also shipped with the VI Perl toolkit. All you need to do is to follow the correct set of objects in the same way that are used in the TaskList.java
I hope this information helps you in starting with VI SDK.

~ Sidharth
Reply Re: List current tasks and its progress (percent) for a selected VM Jan 7, 2008 10:41 AM
in response to: ssurana
Click to view asp24's profile Enthusiast asp24 48 posts since
Oct 11, 2006
Sadly I SUCK at reading/understanding Java.. Any more pointers? Example in Perl maybe? (relevant lines)
Reply Re: List current tasks and its progress (percent) for a selected VM Jan 8, 2008 1:38 AM
in response to: asp24
Click to view ssurana's profile Hot Shot ssurana 130 posts since
Oct 1, 2007
VMware
Hi,

Here you go with the perl sample code that you can use. It lists down all the task in the Recent Task List and displays their progress and Status.

#!/usr/bin/perl -w
#

  1. Copyright (c) 2007 VMware, Inc. All rights reserved.

use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/../";

use VMware::VIM2Runtime;
use VMware::VILib;

$Util::script_version = "1.0";

Opts::parse();
Opts::validate();

Util::connect();
display_progress();
Util::disconnect();

sub display_progress {
Util::trace(0, "\nConnection Sucessful\n");
my $status = 'running';
my $si_moref = ManagedObjectReference->new(type => 'ServiceInstance',
value => 'ServiceInstance');
my $si_view = Vim::get_view(mo_ref => $si_moref);
my $sc_view;
my $task;
my $mytaskref;
my $tm_view;
$sc_view = $si_view->RetrieveServiceContent();
$tm_view = Vim::get_view (mo_ref =>$sc_view->taskManager);
if (defined $tm_view->recentTask) {
foreach (@{$tm_view->recentTask}) {
$task = Vim::get_view(mo_ref => $_);
print "\nTask Name: ". $task->info->descriptionId ." Status: ". $task->info->state->val . " Progress: " .$task->info->progress ."% Complete";
}
} else {
print "\nNo Recent Tasks available.\n";
}
print "\nDisconnecting \n";
}

Hope this code helps.

~ Sidharth

Reply Re: List current tasks and its progress (percent) for a selected VM Jan 8, 2008 6:13 AM
in response to: ssurana
Click to view asp24's profile Enthusiast asp24 48 posts since
Oct 11, 2006

Thank you!!!

It works! The only changes I need to do is to include the VM name behind the task name and fix a small error ( Use of uninitialized value in concatenation (.) or string at ./task.pl line 40.) when a task is queue, and have no progress yet..(I think). I also needed to change from VIM2Runtime to VIM25Runtime

Points awarded!

Actions