code: def wait_for_state(vmid, state, timeout=300):
      '''
      Wait until a specific state has been reached on a node
      '''
      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 %s is now in "%s" state!', node['name'], state)
              return True
          time.sleep(1)
          if time.time() - start_time > timeout:
              log.debug('Timeout reached while waiting for %s to become %s',
                        node['name'], state)
              return False
          node = get_vm_status(vmid=vmid)
          log.debug('State for %s is: "%s" instead of "%s"',
                    node['name'], node['status'], statef wait_for_state(vmid, state, timeout=300):
      '''
      Wait until a specific state has been reached on a node
      '''
      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 %s is now in "%s" state!', node['name'], state)
              return True
          time.sleep(1)
          if time.time() - start_time > timeout:
              log.debug('Timeout reached while waiting for %s to become %s',
                        node['name'], state)
              return False
          node = get_vm_status(vmid=vmid)
          log.debug('State for %s is: "%s" instead of "%s"',
                    node['name'], node['status'], state)
docs: Wait until a specific state has been reached on a node