18.08.2013 Views

vSphere SDK for Perl Programming Guide - Documentation - VMware

vSphere SDK for Perl Programming Guide - Documentation - VMware

vSphere SDK for Perl Programming Guide - Documentation - VMware

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3<br />

Refining <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> Scripts 3<br />

This chapter discusses some programming techniques <strong>for</strong> your <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> scripts.<br />

The chapter includes these topics:<br />

“Creating and Using Filters” on page 33<br />

“Filtering Views Selectively Using Properties” on page 35<br />

“Retrieving the ServiceInstance Object on a <strong>vSphere</strong> Host” on page 36<br />

“Saving and Using Sessions” on page 36<br />

“Using Multiple Sessions” on page 37<br />

“Learning About Object Structure Using Data::Dumper” on page 38<br />

“Specifying Untyped Arguments in Scheduled Tasks and Callbacks” on page 39<br />

“Using Advanced Subroutines” on page 40<br />

Creating and Using Filters<br />

You can use the <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> to define and use filters that select objects based on property values.<br />

Filters can reduce a large result set to only those objects with characteristics of interest to you.<br />

Using Filters with Vim::find_entity_view() or Vim::find_entity_views()<br />

You can call Vim::find_entity_view() or Vim::find_entity_views() to retrieve objects from the<br />

ESX/ESXi host. Vim::find_entity_view() returns the first object it finds that matches the search criteria.<br />

Vim::find_entity_views() returns all objects.<br />

When you call Vim::find_entity_view() the first object found might not be the one you are looking <strong>for</strong>. For<br />

example, you might want to retrieve only those virtual machine objects whose names begin with a certain<br />

prefix. When you call Vim::find_entity_views(), the command might return more objects than you want<br />

to work with, <strong>for</strong> example all virtual machines in a datacenter. You can apply one or more filters to<br />

Vim::find_entity_view() and Vim::find_entity_views() to select a subset of objects based on property<br />

values.<br />

To apply a filter to the results of Vim::find_entity_view() or Vim::find_entity_views(), you supply an<br />

optional filter parameter. The value of the parameter is an anonymous hash reference containing one or<br />

more pairs of filter criteria. Each of the criteria is a property path and a match value. The match value can be<br />

either a string or a regular expression object. If the match value is a string, the value of the property must match<br />

the string exactly (including case). To match Boolean values, use the strings true and false.<br />

The following filter parameter matches a virtual machine power state of poweredOff:<br />

filter => { 'runtime.powerState' => 'poweredOff' }<br />

<strong>VMware</strong>, Inc. 33

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!