Trying to find if Hosts are under the cluster thru perl vcli
Would
| clusterSupported* | xsd:boolean | Whether or not the host supports clustering capabilities such as HA or DRS and therefore can be added to a cluster. If false, the host must be added as a standalone host. |
Work? If so how do I ref it..
thanks in advance.
As William said, going up the parent tree is one option. I have a FindDatacenterByHostname.pl script somewhere in the script samples that you could modify. You'd just climb up the parent tree until you find a ClusterComputeResource object. If you didn't find that object by the time you hit the hostFolder or VI root object, you'd know it was stand alone.
The other option would be to create a hash map. For example, just get all clusters with find_entity_view and enumerate the host property to get ManagedObjectReferences as keys. Then you can do a simple hash lookup for each host. If it isn't in that hash, then you know it is a standalone host. You wouldn't need to make multiple SDK calls and would be more efficient in a large VI inventory.
You could build on something like the following:
#!/usr/bin/perl -wuse strict;use VMware::VIRuntime;Opts::parse();Opts::validate();Util::connect();my $cluster_views = Vim::find_entity_views( view_type => "ClusterComputeResource",properties => [ 'name', 'host' ] );my %host_map = ( );foreach my $cluster ( @{ $cluster_views || [ ] } ) {my $cluster_name = $cluster->name;foreach my $entity ( @{ $cluster->host || [ ] } ) {my $moref = $entity->value;$host_map{$moref} = $cluster_name;}}my $host_views = Vim::find_entity_views( view_type => "HostSystem",properties => [ 'name' ] );print "Standalone Host Systems: \n";foreach my $host ( @$host_views ) {my $moref = $host->{mo_ref}->value;print " " . $host->name . "\n" unless exists $host_map{$moref};}
If you're trying to identify the VMware Cluster for a given HostSystem reference, you need to use it's parent property to retrieve this information. You should get back ClusterComputeResource which will provide you with the name of the Cluster. The other way of going about it is to query the VMware Clusters and iterate through to see if the particular host is in a given cluster or just provide the mapping, just depends on what you're trying to accomplish
As William said, going up the parent tree is one option. I have a FindDatacenterByHostname.pl script somewhere in the script samples that you could modify. You'd just climb up the parent tree until you find a ClusterComputeResource object. If you didn't find that object by the time you hit the hostFolder or VI root object, you'd know it was stand alone.
The other option would be to create a hash map. For example, just get all clusters with find_entity_view and enumerate the host property to get ManagedObjectReferences as keys. Then you can do a simple hash lookup for each host. If it isn't in that hash, then you know it is a standalone host. You wouldn't need to make multiple SDK calls and would be more efficient in a large VI inventory.
You could build on something like the following:
#!/usr/bin/perl -wuse strict;use VMware::VIRuntime;Opts::parse();Opts::validate();Util::connect();my $cluster_views = Vim::find_entity_views( view_type => "ClusterComputeResource",properties => [ 'name', 'host' ] );my %host_map = ( );foreach my $cluster ( @{ $cluster_views || [ ] } ) {my $cluster_name = $cluster->name;foreach my $entity ( @{ $cluster->host || [ ] } ) {my $moref = $entity->value;$host_map{$moref} = $cluster_name;}}my $host_views = Vim::find_entity_views( view_type => "HostSystem",properties => [ 'name' ] );print "Standalone Host Systems: \n";foreach my $host ( @$host_views ) {my $moref = $host->{mo_ref}->value;print " " . $host->name . "\n" unless exists $host_map{$moref};}
Thank you Perfect !!
