VMware {code} Community
meecect
Contributor
Contributor

Getting the ESX Host from a VM view?

Hi,

I am getting a view of all Virtual Machines with:

my $VM_views = Vim::find_entity_views(view_type => 'VirtualMachine', begin_entity => $Farm_details );

How can I use the resulting views to get the physical Host each VM is currently on?

thanks,

Cliff

Reply
0 Kudos
1 Reply
admin
Immortal
Immortal

You can loop throug $VM_views and for each vm check the property $_->runtime->host

This will let you get the managed object reference to the host responsible for running this virtual machine.

foreach (@$VM_views) {

my $vm_view = $_;

my $host_view = Vim::get_view(mo_ref =>$vm_view->runtime->host);

Util::trace(0,$host_view->summary->rebootRequired);

Util::trace(0,"\n");

}

The above illustrates fetching the host managed object reference, getting it's view and accessing any property of host system.

Reply
0 Kudos