Quantcast
Viewing all articles
Browse latest Browse all 197835

Re: Can’t Get Multiple SVMotions Instances using PowerCLI Hash Tables Working

Move-VM cmdlet gave me a lot of trouble, it basically returns an object with no relationship with the VM and its task object. I experimented your method, but I realized it is very hard to match the start time of the task. Instead, I am using the method below:

 

By comparing the difference between tasks before and after, we can retrieve the newly created task object. It does not work 100%, but it is made the most robust as I can. If there are other people initiating svMotion at the same time, the method will consider the task with start time closer to our Move-VM task. There is a reason why I go down this path, the tasks in concern also include clone and svMotion with maximum number of operations set by user e.g. max 4 at a time. I want a generic method that is able to handle every case. So the preference is to retrieve all task objects rather than using Wait-Task, which is synchronous.

 

function GetNewTask($preTasks, $postTasks, $taskStartTime) {
    $collectedTasks = @()
    for($i = 0; $i -lt $postTasks.Length; $i++) {
        $thisTask = $preTasks | Where {$_.Id -eq $postTasks[$i].Id}
        if($thisTask -eq $null) {
            $collectedTasks += $postTasks[$i]
        }
    }
    $task = $null
    if($collectedTasks.Count -gt 1) {
        $task = $collectedTasks | Sort [system.math]::abs($_.StartTime - $taskStartTime) | Select -First 1
    } elseif($collectedTasks.Count -eq 1) {
        $task = $collectedTasks[0]
    } else {
        Write-Host "New Task not found through differential comparison."
    }
    return ,$task
}

 

$preTasks = Get-Task | Where {$_.Name -eq "RelocateVM_Task"}
$cstask = Move-VM -VM $vm.Name -Datastore $svmotionDatastore -Destination $vm.VMHost -DiskStorageFormat Thin -RunAsync
Start-Sleep -Seconds 5
$postTasks = Get-Task | Where {$_.Name -eq "RelocateVM_Task"}
$task = GetNewTask $preTasks $postTasks $cstask.StartTime

 

Then, I am also using your published code to get historic tasks to wait for all tasks to complete, or wait for the concurrent tasks to fall below the maximum allowed set by user. And there is another layer of vCO involved, it is better to check tasks status every N seconds, the efficiency is higher by eliminating the need to pull task status constantly.

 

Thank you for your hints. Image may be NSFW.
Clik here to view.


Viewing all articles
Browse latest Browse all 197835

Trending Articles