I am trying to add 3 disks to an existing VM using the storaepod, I am using the below statement to add the disk using storage DRS recommendation
myVcTask = managedObject.applyStorageDrsRecommendation_Task(myKey);
I am trying to add multiple disks the vim3waittask is not passing one request at a time, it sends all the request at same time and it fails. Do we have any other option to wait for a task to complete and then trigger the other pending tasks.
You can check how it is used in the existing workflows, for example in the workflow Mass migrate virtual machines with storage vMotion (available under Library > vCenter > Virtual Machine management > Move and Migrate).
The basic idea is to create one task at a time and wait for it to complete, before going to the next task. For example, if your loop code looks something like this
for (var i in myarray) {
myVcTask = managedObject.applyStorageDrsRecommendation_Task(myKey);
... // other code inside loop
}
you can change it to something like this
for (var i in myarray) {
myVcTask = managedObject.applyStorageDrsRecommendation_Task(myKey);
actionResult = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(myVcTask, progress, pollRate);
... // other code inside loop
}
where progress parameter is a boolean value which configures whether the log progress while waiting for the task to complete, and pollRate is a number value which configures the polling rate for the task status in seconds.
I'm not sure I fully understand the problem here. How exactly do you start the 3 tasks? vim3WaitTaskEnd will wait for a task to complete, but if you start multiple tasks in parallel it won't magically execute them one after the other; it is responsibility of your code to not run the next task until the waiting for the previous one with vim3WaitTaskEnd completes.
I am using a for loop to create multiple disks using sdrs, it creates 3 tasks at same time. Can you please provide any sample code to limits one task at a time.
You can check how it is used in the existing workflows, for example in the workflow Mass migrate virtual machines with storage vMotion (available under Library > vCenter > Virtual Machine management > Move and Migrate).
The basic idea is to create one task at a time and wait for it to complete, before going to the next task. For example, if your loop code looks something like this
for (var i in myarray) {
myVcTask = managedObject.applyStorageDrsRecommendation_Task(myKey);
... // other code inside loop
}
you can change it to something like this
for (var i in myarray) {
myVcTask = managedObject.applyStorageDrsRecommendation_Task(myKey);
actionResult = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(myVcTask, progress, pollRate);
... // other code inside loop
}
where progress parameter is a boolean value which configures whether the log progress while waiting for the task to complete, and pollRate is a number value which configures the polling rate for the task status in seconds.
Thanks llian I was able to fix the code based on your suggestion and it worked fine. I was able to execute one task at a time. Again thanks for your time and help.