foreach (@$Datacenter_views)
{
my %seen;
my $DC = $_->name;
print "$DC, ";
# get all clusters under this datacenter
my $DC_view = Vim::find_entity_view(view_type => 'Datacenter', filter => { name => $DC });
my $Cluster_views = Vim::find_entity_views(view_type => 'ClusterComputeResource', begin_entity => $DC_view);
foreach my $cluster (@$Cluster_views)
{
my $Cluster_name = $cluster->name;
# printf "%s\n",$Cluster_name;
# get all hosts in this cluster
my $Cluster_view = Vim::find_entity_view(view_type => 'ClusterComputeResource', filter => { name => $cluster->name });
my $Hosts_view = Vim::find_entity_views(view_type => 'HostSystem', begin_entity => $Cluster_view);
# print all hosts in the cluster
foreach my $hosts (@$Hosts_view)
{
my $host_name = $hosts->name;
printf"%s, %s\n", $Cluster_name, $hosts->name;
$seen{$host_name} =1;
}
}
# get all hosts under this datacenter
my $hosts_views = Vim::find_entity_views(view_type => 'HostSystem', begin_entity => $DC_view);
foreach my $hosts (@$hosts_views)
{
# This is the problem unless ( %seen)
{
printf "%s\n",$hosts->name;
}
}
exit();
}
####
my $Cluster_views = Vim::find_entity_views(view_type => 'ClusterCo
+mputeResource', begin_entity => $DC_view);
####
my $Cluster_view = Vim::find_entity_view(view_type => 'ClusterComputeResource', filter => { name => $cluster->name });
my $Hosts_view = Vim::find_entity_views(view_type => 'HostSystem', begin_entity => $Cluster_view);
####
my $hosts_views = Vim::find_entity_views(view_type => 'HostSystem', begin_entity => $DC_view);
####
Data Centre, Cluster, Host (only if the host is in a cluster)
Data centre, Host (only if the host not in a data centre)
####
foreach my $hosts (@$hosts_views)
{
# This is the problem unless (! %seen)
{
printf "%s\n",$hosts->name;
}
}
}