def wait_for_state(vmid, state, timeout=300):
 start_time = time.time()
 node = get_vm_status(vmid=vmid)
 if (not node):
  log.error('wait_for_state: No VM retrieved based on given criteria.')
  raise SaltCloudExecutionFailure
 while True:
  if (node['status'] == state):
   log.debug('Host {0} is now in "{1}" state!'.format(node['name'], state))
   return True
  time.sleep(1)
  if ((time.time() - start_time) > timeout):
   log.debug('Timeout reached while waiting for {0} to become {1}'.format(node['name'], state))
   return False
  node = get_vm_status(vmid=vmid)
  log.debug('State for {0} is: "{1}" instead of "{2}"'.format(node['name'], node['status'], state))

def wait_for_state ( vmid , state , timeout = 300 ) : start_time = time . time ( ) node = get_vm_status ( vmid = vmid ) if ( not node ) : log . error ( 'wait_for_state: No VM retrieved based on given criteria.' ) raise SaltCloudExecutionFailure while True : if ( node [ 'status' ] == state ) : log . debug ( 'Host {0} is now in "{1}" state!' . format ( node [ 'name' ] , state ) ) return True time . sleep ( 1 ) if ( ( time . time ( ) - start_time ) > timeout ) : log . debug ( 'Timeout reached while waiting for {0} to become {1}' . format ( node [ 'name' ] , state ) ) return False node = get_vm_status ( vmid = vmid ) log . debug ( 'State for {0} is: "{1}" instead of "{2}"' . format ( node [ 'name' ] , node [ 'status' ] , state ) )
wait until a specific state has been reached on a node .