code: def wait_for_stack_ready(orchestration_client, stack_name):
      
      SUCCESSFUL_MATCH_OUTPUT = "(CREATE|UPDATE)_COMPLETE"
      FAIL_MATCH_OUTPUT = "(CREATE|UPDATE)_FAILED"
  
      while True:
          stack = orchestration_client.stacks.get(stack_name)
  
          if not stack:
              return False
  
          status = stack.stack_status
  
          if re.match(SUCCESSFUL_MATCH_OUTPUT, status):
              return True
          if re.match(FAIL_MATCH_OUTPUT, status):
              print("Stack failed with status: {}".format(
                  stack.stack_status_reason, file=sys.stderr))
              return False
  
          time.sleep(10)
docs: Check the status of an orchestration stack
  
      Get the status of an orchestration stack and check whether it is complete
      or failed.
  
      :param orchestration_client: Instance of Orchestration client
      :type  orchestration_client: heatclient.v1.client.Client
  
      :param stack_name: Name or UUID of stack to retrieve
      :type  stack_name: string