6.0
Table Of Contents
- vSphere SDK for Perl Programming Guide
- Contents
- Getting Started with vSphere SDK for Perl
- Writing vSphere SDK for Perl Scripts
- Refining vSphere SDK for Perl Scripts
- Creating and Using Filters
- Filtering Views Selectively Using Properties
- Retrieving the ServiceInstance Object on a vSphere Host
- Saving and Using Sessions
- Using Multiple Sessions
- Learning About Object Structure Using Data::Dumper
- Specifying Untyped Arguments in Scheduled Tasks and Callbacks
- Using Advanced Subroutines
- vSphere SDK for Perl Subroutine Reference
- Web Services for Management Perl Library
- Credential Store Perl Library
vSphere SDK for Perl Programming Guide
38 VMware, Inc.
}
# logout
foreach my $vim_obj (@vim_objs) {
$vim_obj->logout();
}
Learning About Object Structure Using Data::Dumper
ThevSphereSDKforPerltransparentlyusestheData::DumperPerlmodule(astandardlibrary)tocreatethe
client‐sideviewobjects.Example 3‐4illustrateshowyoucanuseData::Dumpertoexploreviewobjectsand
correspondingvSphereobjects.
Lines12through14setseveralparametersofData::Dumper,asfollows:
Sortkeysordersthename‐valuepairsalphabeticallybyname.
Deepcopyenablesdeepcopyingofstructures.Deepcopyingensuresthattheoutputisstraightforward
andtree‐like.
Indentsetto2causesData::Dumpertotakehashkeylengthintoaccountintheoutput.Theindent
resultsinamorereadableformat.
Example 3-4. Using Data::Dumper to Output Perl Object Structures
01 use strict;
02 use warnings;
03
04 use VMware::VIRuntime;
05 use VMware::VILib;
06
07 # Parse connection options and connect to the server
08 Opts::parse();
09 Opts::validate();
10 Util::connect();
11
12 $Data::Dumper::Sortkeys = 1; #Sort the keys in the output
13 $Data::Dumper::Deepcopy = 1; #Enable deep copies of structures
14 $Data::Dumper::Indent = 2; #Output in a reasonable style (but no array indexes)
15
16
17
18 # Get the view for the target host
19 my $host_view = Vim::find_entity_view(view_type => 'HostSystem');
20
21 print "The name of this host is ", $host_view->name . "\n\n";
22
23 print Dumper ($host_view->summary->config->product) . "\n\n\n";
24
25 print Dumper ($host_view->summary->config) . "\n\n\n";
26
27 print Dumper ($host_view->summary) . "\n\n\n";
28
29 # logout
30 Vim::logout();
Whenyouruntheentireprogram,itproducesdetailedoutput.Theoutputfromline23looksasfollows:
$VAR1 = bless( {
'apiType' => 'HostAgent',
'apiVersion' => '4.0.0',
'build' => '31178',
'fullName' => 'VMware ESX Server 3.0.1 build-31178',
'localeBuild' => '000',