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.

2<br />

Writing <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> Scripts 2<br />

This chapter uses a simple example script to illustrate how to write a <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> script. The chapter<br />

also explores the basics of the <strong>vSphere</strong> API object model.<br />

NOTE This chapter does not discuss <strong>Perl</strong> basics. You are expected to know <strong>Perl</strong> and to understand its<br />

programming conventions. When you develop a <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> script, follow <strong>Perl</strong> standards <strong>for</strong><br />

filenames, imports, and general processing flow. Use the appropriate filename extension <strong>for</strong> the type of script<br />

or application you are creating (.pl on Windows and .pl or no suffix on UNIX‐like systems).<br />

The chapter includes these topics:<br />

“Basic <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> Script” on page 19<br />

“Understanding Server‐Side Objects” on page 24<br />

“Understanding <strong>Perl</strong> View Objects” on page 28<br />

“Working with View Object Property Values” on page 29<br />

“Understanding Operations and Methods” on page 30<br />

“Updating View Objects” on page 32<br />

Basic <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> Script<br />

<strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> scripts retrieve objects, such as virtual machines, from the server and work with these<br />

objects. <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> scripts follow the basic pattern shown in Table 2‐1.<br />

IMPORTANT The sample script does not use filters or property filters <strong>for</strong> efficiency. See “Refining <strong>vSphere</strong> <strong>SDK</strong><br />

<strong>for</strong> <strong>Perl</strong> Scripts” on page 33 <strong>for</strong> in<strong>for</strong>mation about those topics.<br />

Table 2-1. Basic <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> Script (simpleclient.pl)<br />

Code element Discussed in<br />

#!/usr/bin/perl<br />

use strict;<br />

use warnings;<br />

use <strong>VMware</strong>::VIRuntime;<br />

“Step 1: Import the <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong><br />

Modules” on page 20.<br />

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

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

Saved successfully!

Ooh no, something went wrong!