My trying to script out a treeview for my infrastructure but can't seem to get it working right. Looking for an output like this:
DC1
-Cluster1
-
ResourcePool1
-
Sub ResourcePool1
-
Sub ResourcePool2
-
Sub ResourcePool3
---ResourcePool2
-
Sub ResourcePool1
-
Sub ResourcePool2
-
Sub ResourcePool3
The problem I'm having is with with find_entity_views and the entry points.
Here is what I have:
\# List Datacenters
my $datacenter_views = Vim::find_entity_views(view_type => 'Datacenter');
foreach (@$datacenter_views)
{
my $dc = $_;
my $datacenter = $_->name;
print "Datacenter: " . $datacenter . "\n";
List Clusters
my $cluster_views = Vim::find_entity_views(view_type => 'ClusterComputeResource',begin_entity => $dc );
foreach (@$cluster_views) {
my $ccr = $_;
print "\t";
print $ccr->name;
print "\n";
my $resourcepool_views = Vim::find_entity_views(view_type => 'ResourcePool',begin_entity => $ccr );
foreach (@$resourcepool_views) {
my $rp = $_;
print "\t\t";
print $rp->name;
if ($rp->resourcePool) {
print ":Parent\n";
my $crp_views = Vim::find_entity_views(view_type => 'ResourcePool',begin_entity => $rp->parent);
foreach (@$crp_views) {
my $crp = $_;
print "\t\t\t";
print $crp->name;
print "\n";
}
}
print "\n";
}
}
looks like my ->parent is returning all resources, not just the children of the current resourcepool.
Any ideas?