I was told there might be an option when getting a view of a MOR that allows you to filter out the specific attributes without having to get the entire MOR, I believe it's called a property filter?
I'm trying to just extract the hostname that a VM is being managed by but I don't want the entire view of the hostSystem MOR
I based the following snippet of code from someone stating this is possible:
my $host_view = Vim::get_view (mo_ref => $vm->runtime->host, properties => ); print $host_view->name,"\n";
I was not able to get this to work and was not able to find anything in the API referencing this feature.
=========================================================================
--William
hi,
this works for me, and is much faster:
my $host_view = Vim::get_view(mo_ref=>$vm_view->summary->runtime->host, properties => \['name'\]);
if($host_view){
print $host_view->name;
}
hi,
this works for me, and is much faster:
my $host_view = Vim::get_view(mo_ref=>$vm_view->summary->runtime->host, properties => \['name'\]);
if($host_view){
print $host_view->name;
}
I was trying the property filter on the VM View to just retrieve the datastore name but ran into an error:
#retrieve datastore summary from VM
my $vm_datastore_view = $vm->datastore;
foreach (@$vm_datastore_view) {
my $ds = Vim::get_view(mo_ref => $_, properties => \['summary.name'\]);
$vms_storage{$vm->config->name} = $ds->name;
}
I also tried
my $ds = Vim::get_view(mo_ref => $_->summary, properties => \['name'\] );
$vms_storage{$vm->config->name} = $ds->name;
Am I missing something?
=========================================================================
--William
Yeah, I mentioned this briefly in another post from this weekend I responded to.
I can't see all of your post, the forum mangled your property filter. But if you ask for a property of a property: 'runtime.inMaintenanceMode' for example, the Perl toolkit will sort of condense it to just 'inMaintenanceMode'. So it'll be accessed not as $vm->runtime->inMaintenanceMode but as $vm->inMaintenanceMode. I think they did this for brevity, if you look at VICommon.pm (I think it was here) they just keep popping the path of a property until they get to the last property in the path.
As for your second example, I can't tell if you have your get_view properties array in a good format, the forum mangled it. Insert before any ''\[" or "\]" characters a backslash as you post it.
The first one, with the corrections you applied, should work. What is the error you're getting?
Can't locate object method "name" via package "Datastore" at ./vmwareHealthCheck.pl line 819.
End Disconnect
Though, I'm able to do the following:
my $ds = Vim::get_view(mo_ref => $_); $vms_storage{$vm->config->name} = $ds->summary->name;
So, hoping I can make it more efficient with just asking for the datastore name only.
=========================================================================
--William
I made a mistake and got you on the wrong track, my apologies. I should have been more thorough when I went through the VICommon.pm code.
So it's not a pop for the properties as I read incorrectly, that only happens when you don't define the properties. It's simply the path you provide in the properties array values:
my $ds = Vim::get_view(mo_ref => $_, properties => \['summary.name'\] );<Br>
$vms_storage{$vm->config->name} = $ds->{'summary.name'};
This obviously makes more sense otherwise the code would overwrite the managed object name property or face other potential clashes in property names. The code definitely sets the all property to 0 and updates the pathSet, so it should do a minimal RetrieveProperties call. Not setting the properties value in a get_view call will retrieve the entire object's property values.
I actually tested it and it works as advertised this time.
Hi William,
I always thought we had to use the tags. Anywho, I just fixed the output, you should be able to see what I tried.
Use the tags for that. They usually work best for code and well.. the majority of things that you don't want to be reformatted.
Have a peeksy at my document here that discusses on how to do these type of things in the forum:
--
Wil
_____________________________________________________
Visit the new VMware developers wiki at http://www.vi-toolkit.com