Contributor
Contributor

Perl Programming for vSphere CLI

Hi , can anyone help me in writing the programming to " move virtual machine to resource pool "

i wrote like this , but error in

#!/usr/bin/perl

#to move the VM into Resource pool#

use strict;
use warnings;
use VMware::VIM25Runtime;
use VMware::VIRuntime;
use VMware::VIMRuntime;
use VMware::VILib;

Opts::parse();
Opts::validate();
Util::connect();

#to get the list of Vms
my $vmView = Vim::find_entity_view(view_type => 'VirtualMachine',
                                        filter => {'config.name' => 'PB_Win2K8_64.22'});

print "VM name : " . $vmView->name . "\n";

#to get the Resource pool view
my $rpView = Vim::find_entity_view(view_type => 'ResourcePool',
                                        filter => {'name' => 'mpr_pool'});
print "Resourcepool name : " . $rpView->name . "\n";

my $mor_vm = $vmView->resourcePool;
#my $m_vm = (mo_ref=>$mor_vm);

my $mor_rp = $rpView->vm;
#my $m_rp = (mo_ref=>$mor_rp);

#to move a particular vm into Resource pool#
my $res = ResourcePoolOperations::MoveIntoResourcePool( $mor_rp, 'VirtualMachine', $mor_vm );  #here is the error of invalid arguments

Util::disconnect();

Please help me

Thank you

0 Kudos
3 Replies
Contributor
Contributor

In every subroutine given in Perl API

sub .....{

my ($self, %args) = @_;
   my $response = Util::check_fault($self->invoke('Rename_Task', %args));
   return $response

}

can any one explain , what args to be passed

In general how to correlate them

Thank you

0 Kudos
Community Manager
Community Manager

Hi mpr4ul,

Basically you're on the right track, if you take a look at the MoveIntoResourcePool() method (http://vijava.sourceforge.net/vSphereAPIDoc/ver5/ReferenceGuide/vim.ResourcePool.html#moveInto), it requires the resource pool in which you plan on moving an object into and then it accepts an argument called "list" which is a list of entities to move into the resource pool

Here's quick psuedo code:

# get resource pool

$resourcePoolView = ...

# get VM

$vmView = ...

#move VM into RP

$resourcePoolView->MoveIntoResourcePool(list => [$vmView]);

0 Kudos
Contributor
Contributor

Thank you for reply

it will work to hide the error , but operation not performed

i wrote like this

$rpView->ResourcePoolOperations::MoveIntoResourcePool(list=>[$vmView]);

but vm is not moved to given resouce pool

0 Kudos