VMware {code} Community
piuhapofuhpaosf
Contributor
Contributor
Jump to solution

Trouble with find_entity_views

I'm trying to grab all of the templates from a datacenter. To do that, I'm trying to use find_entity_views and filter by 'config.template' => 1. Unfortunately, this is not working for me. Here's the code:

my $dc = $vim->find_entity_view(view_type=>'Datacenter',

filter=>{name=>'CALO-RTP-DEV'});

my $v = $vim->find_entity_views(view_type=>'VirtualMachine',

filter=>{'config.template'=>1},

begin_entity=>$dc->vmFolder);

print Dumper $v;

foreach my $x (@$v) {

print $x->name ."\n";

}

Unfortunately, no VMs are returned from the find_entity_views call. I've also tried this without using the begin_entity, as well as setting the begin_entity to just be the datacenter itself, and I still get nothing returned. In fact, the only way I've successfully gotten a return value from find_entity_views when using a filter is if to filter only searches the VM name (filter=>{name=>'whateverthenameis'}). That seems to be the only field it will successfully search. Also, it won't return anything when I filter using wildcard characters (filter=>{name=>'.something.'} OR filter=>{name=>qr/.something./i}). I've seen samples containing just about all of these sorts of searches, yet none of them work for me. Any ideas why that is? Any help is greatly appareciated.

0 Kudos
1 Solution

Accepted Solutions
stumpr
Virtuoso
Virtuoso
Jump to solution

You'll want to use the strings 'true' and 'false' for your pattern matching.

my $dc = $vim->find_entity_view(view_type=>'Datacenter',
filter=>{name=>'CALO-RTP-DEV'});

my $v = $vim->find_entity_views(view_type=>'VirtualMachine',
*filter=>{ 'config.template' => qr/true/i},*
begin_entity=>$dc->vmFolder);
   

print Dumper $v;

foreach my $x (@$v) {
   print $x->name ."\n";
}

Reuben Stump | http://www.virtuin.com | @ReubenStump

View solution in original post

0 Kudos
2 Replies
stumpr
Virtuoso
Virtuoso
Jump to solution

You'll want to use the strings 'true' and 'false' for your pattern matching.

my $dc = $vim->find_entity_view(view_type=>'Datacenter',
filter=>{name=>'CALO-RTP-DEV'});

my $v = $vim->find_entity_views(view_type=>'VirtualMachine',
*filter=>{ 'config.template' => qr/true/i},*
begin_entity=>$dc->vmFolder);
   

print Dumper $v;

foreach my $x (@$v) {
   print $x->name ."\n";
}

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
piuhapofuhpaosf
Contributor
Contributor
Jump to solution

Beautiful! Thanks for the help.

0 Kudos