VMware {code} Community
DroppedAtBirth
Contributor
Contributor

Wait for vm clone task - vb.net

I have all my clone code working but need to find a way to wait for the clone task to finish. Currently using the Vim25Api to do my cloning but can't get VimServer.WaitForUpdates to wait ont he task but I get an error saying I am not connected... Alot of post on the forum talk about and show using WaitForTask, which is what I have used in vSphere PowerCLI before but I don't see it anywhere in the Vim25api. I do find it in the VMware.Vim api. Anyone have an example of waiting on a clone task using the Vim25api in .net? Or is there another way I should be trying to wait for the task.

Dim cloneTask As ManagedObjectReference = service.CloneVMTask(templateRef, vmFolderRef, VMName, cloneSpec)

Thanks

Rob

0 Kudos
3 Replies
lamw
Community Manager
Community Manager

When you use the CloneVM_Task(), a task reference is returned, you can keep track of these tasks and periodically poll the status. The reason you got the timeout is if you leave your connection idle for more than 30min, it'll time out and disconnect. I've written a similar script that does deployment that basically keeps an array of task objects and basically checks on the status and remember to refresh the task object to get the latest info. This should just be a simple while loop and probably something that keeps track of all the task ref such as an array or vector.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

Twitter: @lamw

If you find this information useful, please award points for "correct" or "helpful".

DroppedAtBirth
Contributor
Contributor

I'm trying to check the task immediately after its created, the connect is still open and has not been open for 30 minutes.

0 Kudos
DroppedAtBirth
Contributor
Contributor

Ended up using Vim25Api.ServiceContent.taskManager and CreateCollectorForTasks and filterd it by the TaskID I was getting back from the CloneVM_Task MOR. Just have it checking the state of the task every 30 seconds, works but the task doesn't report the progress back, its always says the progress is 0. But I can at least watch it for error, running, queued, or complete states.

0 Kudos