Because of the way vSphere SDK for Perl maps the vSphere API into Perl, you have to specify arguments to callback methods differently from the way you specify arguments to other methods.
You can use PrimType
to specify untyped arguments in scheduled tasks and callbacks.
- You must specify the arguments positionally, in the order defined in the bindings for other languages like Java.
- You must indicate the type of each argument using the
PrimType
constructor.
For example, consider a scheduled task that periodically creates a snapshot. The CreateSnapshot()
method takes four arguments, name
, description
, memory
, and quiesce
.
You must define the arguments before you use them by creating four MethodActionArgument objects with PrimType values.
my $name = MethodActionArgument->new( value => PrimType->new('Sample snapshot task', 'string') ); my $description = MethodActionArgument->new( value => PrimType->new('Created from a sample script', 'string') ); my $memory = MethodActionArgument->new( value => PrimType->new(0, 'boolean') ); my $quiesce = MethodActionArgument->new( value => PrimType->new(0, 'boolean') );
You use the MethodActionArgument
objects in the order defined in the positional API, not with the usual name => $value
syntax. You can then supply the four values defined above as arguments to CreateSnapshot()
.
my $snapshot_action = MethodAction->new( name => "CreateSnapshot", argument => [ $name, $description, $memory, $quiesce ] );
The complete example is in /samples/scheduled_task/vm_snapshot_schedule.pl (Linux) and in VMware vSphere CLI\Perl\samples\scheduled_task\vm_snapshot_schedule.pl (Windows).