VMware {code} Community
rlaborius
Contributor
Contributor

Getting parent Resourcepools for VM ?!

Hi

I made a script to get the ResourcePool of a given VM.

Now the Resourcepool has a RootResourcepool.

Is it possible to get the whole Tree like:

RootResourcepool\PoolA\Pool1\VM.

#!/usr/bin/perl -w

use strict;
use warnings;
use VMware::VILib;
use VMware::VIRuntime;
use Data::Dumper;
use 5.010;
my $vmname,$vm_view,$pool_view,$host_view,$poolname,);
my %opts = (
        vmname => {
        type => "=s",
        help => "Name of the Virutal Machine",
        required => 1,
        },
);
# validate options, and connect to the server
Opts::add_options(%opts);
# validate options, and connect to the server
Opts::parse();
Opts::validate();
Util::connect();
$vmname = Opts::get_option('vmname');
#verify VM is valid
$vm_view = Vim::find_entity_view(view_type => 'VirtualMachine', filter => {"config.name" => $vmname});
unless (defined $vm_view){
        die "No VM named \"$vmname\" can be found! Check your spelling\n";
}
print "Located VM: \"$vmname\"!\n";
#retrieve the host in which the VM is hosted on
$host_view = Vim::get_view(mo_ref => $vm_view->resourcePool);
unless (defined $host_view){
        die "Unable to retrieve ESX(i) host from \"$vmname\".\n";
}
$poolname = $host_view->name;
print "VM: \"$vmname\" is located in \"$poolname\"\n";
#print Dumper $host_view;

Util::disconnect();

Thanks

Ronny

Reply
0 Kudos
0 Replies