VMware {code} Community
garybrown
Enthusiast
Enthusiast

problem with vminfo.pl

I have installed Beta 2 - installation went well.

If I run vminfo.pl against a given instance that does not have VMware Tools installed then it fails with

Can't call method "val" on an undefined value at vminfo.pl line 239.

and looking through the code I would suggest it is here

elsif($_ eq 'toolsStatus') {

my $status = $vm_view->summary->guest->toolsStatus->val;

but I don't know how or where this should be modified to allow for such cases........ still learning.....

Thanks for any suggestions.

Reply
0 Kudos
6 Replies
admin
Immortal
Immortal

I agree with you on this. The toolsStatus property is used for displaying the current status of VMware Tools in the guest operating system, if known. In your case, this value is not known as you do not have VMware tools installed.

But I agree, this should be handled more gracefully by simply not displaying a value if it's not known, instead of throwing an error. We will be logging a bug against this and the status of the same will be posted on forum when it's resolved.

For the time being, you can try fixing the code by placing a defined check as follows:

elsif($_ eq 'toolsStatus') {

if (defined ($vm_view->summary->guest->toolsStatus)) {

my $status = $vm_view->summary->guest->toolsStatus->val;

print_log($toolsStatus\{$status},"VMwareTools","VMware Tools");

}

}

or have the VMware tools installed, incase you want to see this property.

Reply
0 Kudos
garybrown
Enthusiast
Enthusiast

That solved that issue - thankyou .

I've just noticed that VirtualDisks is always reporting 0 ? Any ides on that one ?

Reply
0 Kudos
Engelsman
Enthusiast
Enthusiast

Hi,

I've got the same thing here Gary; the VirtualDisks is always reporting 0.

If someone has a solution fort that, it would ben great

Something like listing all vmdk's including size en location per VM.

Reply
0 Kudos
jnhall
Enthusiast
Enthusiast

I don't know why numVirtualDisks is returning 0. In any event, here's one way you could look at just the Virtual Disk devices. Notice the complete lack of error and sanity checking and so on; that is left as an exercise to the reader. The VM files themselves, that would be a different thing; you would have to browse the datastore. I'm assuming you'll settle just for the virtual disk devices.

use strict;

use warnings;

use VMware::VIRuntime;

use VMware::VILib;

Opts::parse();

Opts::validate();

Util::connect();

my $vms = Vim::find_entity_views(

view_type => 'VirtualMachine',

);

for (@$vms) {

print "VirtualMachine: " . $_->name . "\n";

my $virtual_hardware = $_->config;

for my $device (@{$_->config->hardware->device}) {

if (ref($device) eq 'VirtualDisk') {

print " VirtualDisk: " .

"label='" . $device->deviceInfo->label . "' " .

"size=" . $device->capacityInKB . " " .

"summary='" . $device->deviceInfo->summary . "'" .

"\n";

}

}

}

Util::disconnect();

Reply
0 Kudos
jnhall
Enthusiast
Enthusiast

I don't know why numVirtualDisks is returning 0

It turns out this is a bug, and is being fixed for a future release. So you will have to use an alternative approach like the one above.

Reply
0 Kudos
meistermn
Expert
Expert

Maybe we have use the data object VirtualMachineDiskDeviceInf

Or extend the sample

exlisthw.pl - Example script that lists the virtual hardware of a virtual machine

Great PDF Slides

Reply
0 Kudos