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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> <strong>Programming</strong> <strong>Guide</strong><br />

You must specify the arguments positionally, in the order defined in the bindings <strong>for</strong> other languages like<br />

Java.<br />

You must indicate the type of each argument using the PrimType constructor.<br />

For example, consider a scheduled task that periodically creates a snapshot. The CreateSnapshot() method<br />

takes four arguments, name, description, memory, and quiesce.<br />

You must define the arguments be<strong>for</strong>e you use them by creating four MethodActionArgument objects with<br />

PrimType values, as follows:<br />

my $name = MethodActionArgument->new(<br />

value => PrimType->new('Sample snapshot task', 'string')<br />

);<br />

my $description = MethodActionArgument->new(<br />

value => PrimType->new('Created from a sample script', 'string')<br />

);<br />

my $memory = MethodActionArgument->new(<br />

value => PrimType->new(0, 'boolean')<br />

);<br />

my $quiesce = MethodActionArgument->new(<br />

value => PrimType->new(0, 'boolean')<br />

);<br />

You use the MethodActionArgument objects in the order defined in the positional API, not with the usual<br />

name => $value syntax. You can then supply the four values defined above as arguments to<br />

CreateSnapshot().<br />

my $snapshot_action = MethodAction->new(<br />

name => "CreateSnapshot",<br />

argument => [<br />

$name,<br />

$description,<br />

$memory,<br />

$quiesce<br />

]<br />

);<br />

The complete example is in /samples/scheduled_task/vm_snapshot_schedule.pl (Linux) and in<br />

<strong>VMware</strong> <strong>vSphere</strong> CLI\<strong>Perl</strong>\samples\scheduled_task\vm_snapshot_schedule.pl (Windows).<br />

Using Advanced Subroutines<br />

<strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> includes one subroutine, Opts::get_config().<br />

Opts::get_config()<br />

Determines whether a configuration file was read when <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> executed Opts::parse().<br />

This subroutine has no parameters.<br />

Returns<br />

If a configuration file was successfully opened, Opts::get_config() returns the path to it. If no<br />

configuration file was found, or if it could not be opened, Opts::get_config() returns undef.<br />

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

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

Saved successfully!

Ooh no, something went wrong!