vCO Workflow Action to Wait for a vCenter Task to Complete

The following is the script for the action to wait for a vCenter task to complete.

 

if (objVCTask == null)
{
	throw "The vCenter Task is null";
}
else
{
	while (objVCTask != null)
	{
		var objVcTaskInfo;
	
		if (objVCTask.info == null)
		{
			throw "The vCenter Task info is null";
		}
		else
		{
			objVcTaskInfo = objVCTask.info;
			
			if (objVcTaskInfo.state == null)
			{
				throw "The vCenter Task state is null";
			}
			else
			{
				var objVcTaskInfoState;
					objVcTaskInfoState = objVcTaskInfo.state;
						
				var strState;
					strState = objVcTaskInfoState.value;
	
				if (strState == "success")
				{
					break;
				}
				else if (strState == "error")
				{
					if (objVcTaskInfo.error.localizedMessage == null)
					{
						throw "The vCenter Task '" + objVcTaskInfo.name + "' has encountered an unknown error";
					}
					else
					{
						throw "The vCenter Task '" + objVcTaskInfo.name + "' error: " + objVcTaskInfo.error.localizedMessage;
					}
				}
				
				System.sleep(1 * 1000);
			}
		}
	}
}

if (objVCTask != null && objVcTaskInfo != null && objVcTaskInfo.result != null)
{
	return VcPlugin.convertToVimManagedObject(objVCTask, objVcTaskInfo.result);
}
else
{
	return null;
}

Leave a Reply