@ -647,22 +647,24 @@ def wait_for_task(module, task_ref, timeout=300):
result = " "
result = " "
# If we have to wait indefinitely, make time ou t larger than 0 so we can
# If we have to wait indefinitely, make time _lef t larger than 0 so we can
# enter while loop.
# enter while loop.
if timeout == 0 :
if timeout == 0 :
timeout = 1
time_left = 1
else :
time_left = timeout
try :
try :
while time ou t > 0 :
while time _lef t > 0 :
task_status = xapi_session . xenapi . task . get_status ( task_ref ) . lower ( )
task_status = xapi_session . xenapi . task . get_status ( task_ref ) . lower ( )
if task_status == " pending " :
if task_status == " pending " :
# Task is still running.
# Task is still running.
time . sleep ( interval )
time . sleep ( interval )
# We decrease time ou t only if we don't wait indefinitely.
# We decrease time _lef t only if we don't wait indefinitely.
if timeout != 0 :
if timeout != 0 :
time ou t - = interval
time _lef t - = interval
continue
continue
elif task_status == " success " :
elif task_status == " success " :
@ -860,11 +862,7 @@ class XenServerObject(object):
" Please download XenServer SDK and copy XenAPI.py to your Python site-packages. "
" Please download XenServer SDK and copy XenAPI.py to your Python site-packages. "
" Check Notes section in module documentation for more info. " ) )
" Check Notes section in module documentation for more info. " ) )
if module :
self . module = module
self . module = module
else :
module . fail_json ( msg = " XenServerObject: Invalid module object passed! " )
self . xapi_session = XAPI . connect ( module )
self . xapi_session = XAPI . connect ( module )
try :
try :