VMware {code} Community
lamw
Community Manager
Community Manager

Unable retrieve # of disks for VM, always returns 0

I'm starting from ComputerResource to host view to vm and extracing information about all the VM(s) and everything has returned properly except for the number of virtual disks a VM has. It always comes back as 0 and it's always defined. I'm kind of puzzle on exactly what's going on, I've looked at scripts written by VMware like vminfo.pl and they're extracing the same value but it's populated.

foreach my $host (@$hosts) {
        my $vm_views = Vim::get_views (mo_ref_array => $host->vm);
        foreach my $vm (@$vm_views) {
                 print $vm->config->name,"\n"; #prints fine
                 print $vm->summary->config->numVirtualDisks,"\n"; # prints 0
        }
}

Am I missing something?

=========================================================================

--William

VMware ESX/ESXi scripts and resources at:

Reply
0 Kudos
2 Replies
admin
Immortal
Immortal

As I understand, you have stated, vminfo.pl is listing the results for numVirtualDisks. I am not sure, why you are not able to get values for numVirtualDisks using your code when you can get it using vminfo.pl, as there is nothing different. Are you running vminfo.pl on the same setup, on which you are executing your code.

You can try using the following approach to find information of the disks and maintain a counter to keep track of the no. of virtual disks as an alternative.

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 . "' " . ."\n";

}

You will also find the following thread helpful.

http://communities.vmware.com/message/767147;jsessionid=0DABE6DC1A0EC6417A60C4F024FAF890

Reply
0 Kudos
lamw
Community Manager
Community Manager

That is true, I could just "count".

I'm not using the vminfo.pl code directly, but looking at the API and looking at vminfo.pl, I was able to match up the value to numVirtualDisks. I'm using and older sample code called "clusterList.pl" which starts from ClusterComputeResource.

http://communities.vmware.com/message/744314#744314

I'm able to get the vm view and like I said, I've been able to get all attributes but this single one is the one that is acting up. It's weird because if I did something wrong, I would have expected it to return null or thrown an error but it just comes back as 0. I have an array of VM(s) ranging from Linux/Win and the majority are poweredOn and have the latest VMware tools running, which I don't think would affect the results.

UPDATE: I also noticed when I pass in a single ESX/ESXi host, the retrieval of the # of disks per VM is outputted correctly, it's when I drill down from the ClusterComputerResource->Cluster->Host->VM that it prints 0.

=========================================================================

--William

VMware ESX/ESXi scripts and resources at:

Reply
0 Kudos