vSphere SDK for Perl Programming Guide - Documentation - VMware
vSphere SDK for Perl Programming Guide - Documentation - VMware
vSphere SDK for Perl Programming Guide - Documentation - VMware
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Filtering Views Selectively Using Properties<br />
Chapter 3 Refining <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> Scripts<br />
Each <strong>Perl</strong> view object has properties that correspond to properties of server‐side managed objects as follows:<br />
For each simple property (string, Boolean, numeric data type), including inherited simple properties,<br />
the <strong>SDK</strong> creates an accessor method. The accessor method name is the same as the property name.<br />
Arrays of properties become arrays of properties of the same name.<br />
Because many of the server‐side managed objects have a large number of properties, accessing only a small<br />
number of objects can potentially result in noticeable per<strong>for</strong>mance degradation. You use a properties filter to<br />
populate the view object only with properties you are interested in to avoid that problem.<br />
Using View Subroutines with a Properties Argument<br />
The view subroutines—get_view(), get_views(), find_entity_view(), and find_entity_views()<br />
—can accept a properties argument that consists of a list of property paths <strong>for</strong> retrieval from the server. Go<br />
to the <strong>vSphere</strong> Web Services <strong>SDK</strong> Reference <strong>for</strong> a list of properties <strong>for</strong> each server‐side managed object. Property<br />
paths can be full paths, and can include nested properties. Properties do not have to be top‐level managed<br />
object properties.<br />
The following example illustrates filtering by property.<br />
1 Populate a virtual machine view with power‐state in<strong>for</strong>mation only, as follows:<br />
my $vm_view = Vim::find_entity_view(<br />
view_type => 'VirtualMachine',<br />
filter => { 'name' => 'foo' },<br />
properties => [ 'runtime.powerState' ]<br />
);<br />
2 Use the view object’s get_property() method. Note that $vm_view is an array reference, not a scalar.<br />
my $state = $vm_view->get_property('runtime.powerState');<br />
3 If you are interested in subproperties of the retrieved properties, you can retrieve them like this:<br />
my $vm_view = Vim::find_entity_view(<br />
view_type => 'VirtualMachine',<br />
filter => { 'name' => 'foo' },<br />
properties => [ 'config.hardware' ]);<br />
my $memsize = $vm_view->get_property('config.hardware.memoryMB');<br />
get_property() works with fully‐populated views as well. The following code fragments uses<br />
get_property to retrieve a property from a virtual machine.<br />
my $vm_view = Vim::find_entity_view(<br />
view_type => 'VirtualMachine',<br />
filter => { 'name' => 'foo' });<br />
my $memsize = $vm_view->get_property('config.hardware.memoryMB');<br />
The following code fragment, which retrieves the same property by traversing the tree, has the same result.<br />
my $vm_view = Vim::find_entity_view(<br />
view_type => 'VirtualMachine',<br />
filter => { 'name' => 'foo' });<br />
my $memsize = $vm_view->config->hardware->memoryMB;<br />
When you use a filtered view and attempt to read a property that was not retrieved from the server, the result<br />
is the same as if the property were unset.<br />
<strong>VMware</strong>, Inc. 35