The view subroutines — get_view()
, get_views()
, find_entity_view()
, and find_entity_views()
— can accept a properties
argument that consists of a list of property paths for retrieval from the server.
Go to the vSphere Web Services SDK Reference for a list of properties for each server-side managed object. Property paths can be full paths, and can include nested properties. Properties do not have to be top-level managed object properties.
The following example illustrates filtering by property.
- Populate a virtual machine view with power-state information only.
my $vm_view = Vim::find_entity_view( view_type => 'VirtualMachine', filter => { 'name' => 'foo' }, properties => [ 'runtime.powerState' ] );
- Use the view object's
get_property()
method.Note that
$vm_view
is an array reference, not a scalar.my $state = $vm_view->get_property('runtime.powerState');
- If you are interested in subproperties of the retrieved properties, you can retrieve them.
my $vm_view = Vim::find_entity_view( view_type => 'VirtualMachine', filter => { 'name' => 'foo' }, properties => [ 'config.hardware' ]); my $memsize = $vm_view->get_property('config.hardware.memoryMB');
get_property()
works with fully-populated views as well. The following code fragments uses get_property
to retrieve a property from a virtual machine.
my $vm_view = Vim::find_entity_view( view_type => 'VirtualMachine', filter => { 'name' => 'foo' }); my $memsize = $vm_view->get_property('config.hardware.memoryMB');
The following code fragment, which retrieves the same property by traversing the tree, has the same result.
my $vm_view = Vim::find_entity_view( view_type => 'VirtualMachine', filter => { 'name' => 'foo' }); my $memsize = $vm_view->config->hardware->memoryMB;
When you use a filtered view and attempt to read a property that was not retrieved from the server, the result is the same as if the property were unset.