I'm trying to get a total count of VMs, excluding some vShield Edge devices and any VMs in a certain Resource Pool (System vDC). I'm starting with this:
use strict;
use warnings;
use VMware::VIRuntime;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
Opts::parse();
Opts::validate();
Util::connect();
use Data::Dumper;
# Obtain all inventory objects of the specified type
my $e_vm = Vim::find_entity_views(view_type => 'VirtualMachine',properties => ['summary.config.name']);
my $count = 0;
foreach (@$e_vm) {
my $vmName = $_->{'summary.config.name'};
if (!($vmName =~ m/EdgeGW/i) && !($vmName =~ m/^vse/i)){
$count++;
} else {
print "Checking... VMName: ".$vmName."\n";
}
}
printf("TotalVMs:%d \n",$count);
Util::disconnect();
That works pretty well, but trying to go to the next step is where I'm having troubles. In theory, there should be a resourceConfig.entity.name string (if I'm reading the API documentation correctly). I can't seem to figure out how to obtain that string for comparison inside the foreach loop.
Any ideas?