vSphere SDK for Perl Programming Guide - Documentation - VMware
vSphere SDK for Perl Programming Guide - Documentation - VMware
vSphere SDK for Perl Programming Guide - Documentation - VMware
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Non-Blocking and Blocking Methods<br />
Chapter 2 Writing <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> Scripts<br />
All server‐side operations available in the <strong>vSphere</strong> API are non‐blocking operations listed in the <strong>vSphere</strong> API<br />
Reference <strong>Guide</strong>. The <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> provides a non‐blocking method corresponding to the server‐side<br />
operation, and also provides a blocking (synchronous) method (() method).<br />
Non‐blocking methods – Asynchronous methods that return control to the client immediately after<br />
invocation and return a task object to the calling program. Non‐blocking methods allow you to monitor<br />
progress (of the *_Task object) outside the main processing logic of the script. This monitoring can be<br />
useful during long‐running operations. These methods also allow you to interleave local (client‐side)<br />
processing and server‐side processing.<br />
Blocking methods – Synchronous methods that fully process the operation be<strong>for</strong>e returning control to the<br />
client script. Does not return a reference to a task object.If you use a blocking method, you do not have to<br />
handle a task object with additional code.<br />
Examples of Operations<br />
The following table lists some of the operations available <strong>for</strong> a VirtualMachine managed object.<br />
Table 2-4. Examples <strong>for</strong> Asynchronous and Synchronous Methods<br />
<strong>vSphere</strong> API<br />
Non-blocking (asynchronous)<br />
See the <strong>vSphere</strong> API Reference <strong>Guide</strong> <strong>for</strong> lists of all operations <strong>for</strong> each managed object.<br />
Calling Methods<br />
After you have retrieved the view object that corresponds to a managed object, you can run methods on that<br />
view to make use of the managed object’s services. You run a method by specifying the method’s name<br />
parameter, <strong>for</strong> example:<br />
$vm->MigrateVM (name => 'productionVM');<br />
The type of parameter required by the method depends on the operation defined in the <strong>vSphere</strong> API. It might<br />
be a simple type, data object, or managed object reference. For in<strong>for</strong>mation about specific parameters and data<br />
types, see the <strong>vSphere</strong> API Reference <strong>Guide</strong>.<br />
Blocking operations are run as methods on a view object. For example, to suspend a virtual machine, call:<br />
$vm_view->SuspendVM();<br />
You can execute any operation that is defined <strong>for</strong> a managed object as a method on a corresponding view<br />
object. Because the <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> creates an accessor and a mutator method (getter and setter method)<br />
<strong>for</strong> each property defined in the managed object, you can reference the name of any property as a method call<br />
of the view, <strong>for</strong> example:<br />
my $network_name = $network_view->name<br />
<strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong><br />
Non-blocking (asynchronous)<br />
PowerOnVM_Task() PowerOnVM_Task() PowerOnVM()<br />
CloneVM_Task() CloneVM_Task() CloneVM()<br />
SuspendVM_Task() SuspendVM_Task() SuspendVM()<br />
<strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> Only<br />
Blocking (synchronous)<br />
The <strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> allows you to pass a view object to a method that requires a<br />
ManagedObjectReference. For example, if you have the view that represents a host ($host), you can pass the<br />
view to the powerOn() method as follows:<br />
my $host = Vim::find_entity_view (view_type => 'HostSystem', name => 'my host');<br />
my $vm = Vim::find_entity_view (view_type => 'VirtualMachine', name => 'my virtual machine');<br />
$vm->powerOn (host => $host)<br />
NOTE “Specifying Untyped Arguments in Scheduled Tasks and Callbacks” on page 39 discusses using the<br />
<strong>vSphere</strong> <strong>SDK</strong> <strong>for</strong> <strong>Perl</strong> PrimType structure in some calls.<br />
<strong>VMware</strong>, Inc. 31