I'm trying to move a vm from one resource pool to another (hot migration) using MigrateVM_Task or RelocateVM_Task. Does anyone have working code?
Here is what I have:
MoveVMToResourcePool('TestVM','TestResourcePool');;
sub MoveVMToResourcePool {
my ($vm_name, $destination_rp_name) = @_;
my $service_content = Vim::get_service_content();
my $root = $service_content->rootFolder;
my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine',
begin_entity => $root);
my $vm_count = @$vm_views;
my $vm_view = Vim::find_entity_view(view_type => 'VirtualMachine',
begin_entity => $root,
filter =>\{'name' => $vm_name});
if ($vm_view) {
my $vm_source_pool = Vim::find_entity_view(view_type => 'ResourcePool',
begin_entity => $root,
filter =>\{'config.entity' => $vm_view->resourcePool->value});
print "Current Location of \'". $vm_name ."\' is \'". $vm_source_pool->name ."\'\n";
print "Verifying destination Resource Pool: $destination_rp_name\n";
my $destination_rp = Vim::find_entity_view(view_type => 'ResourcePool',
begin_entity => $root,
filter =>\{'name' => "$destination_rp_name"});
if ($destination_rp) {
print "Destination Resource pool is good\n";
print "Setting up VirtualMachineRelocateSpec\n";
my $spec = VirtualMachineRelocateSpec->new(pool => $destination_rp);
print "Moving \'". $vm_name ."\' from \'". $vm_source_pool->name ."\' to \'". $destination_rp_name . "\'\n";
#
\# need some code here to do the work...
#[/b]
if(!$task) {
die "\nERROR: Failed to move VM to a new ResourcePool\n";
} else \{ }
}