vSphere SDK for Perl scripts retrieve objects, such as virtual machines, from the server and work with these objects.
vSphere SDK for Perl scripts follow the basic pattern shown in Basic vSphere SDK for Perl Script (simpleclient.pl).
Important: The sample script does not use filters or property filters for efficiency. See
Refining vSphere SDK for Perl Scripts for information about those topics.
Code element | Discussed in |
---|---|
#!/usr/bin/perl use strict; use warnings; use VMware::VIRuntime; |
Step 1: Import the vSphere SDK for Perl Modules |
my %opts = ( entity => { type => "=s", variable => "VI_ENTITY", help => "ManagedEntity type: HostSystem, etc", required => 1, }, ); Opts::add_options(%opts); Opts::parse(); Opts::validate(); |
Step 2: (Optional) Define Script-Specific Command-Line Options |
Util::connect(); |
Step 3: Connect to the Server |
# Obtain all inventory objects of the specified type my $entity_type = Opts::get_option('entity'); my $entity_views = Vim::find_entity_views( view_type => $entity_type); |
Step 4: Obtain View Objects of Server-Side Managed Objects |
# Process the findings and output to the console foreach my $entity_view (@$entity_views) { my $entity_name = $entity_view->name; Util::trace(0, "Found $entity_type: $entity_name\n"); } |
Step 5: Process Views and Report Results |
# Disconnect from the server Util::disconnect(); |
Step 6: Close the Server Connection |